| 1 |
<?php |
| 2 |
|
| 3 |
namespace ResponsiveMenu\Controllers; |
| 4 |
use ResponsiveMenu\View\View as View; |
| 5 |
use ResponsiveMenu\Services\OptionService as OptionService; |
| 6 |
use ResponsiveMenu\ViewModels\Menu as MenuViewModel; |
| 7 |
use ResponsiveMenu\ViewModels\Button as ButtonViewModel; |
| 8 |
use ResponsiveMenu\Factories\FrontDisplayFactory as DisplayFactory; |
| 9 |
|
| 10 |
class Front { |
| 11 |
|
| 12 |
public function __construct(OptionService $service, View $view) { |
| 13 |
$this->service = $service; |
| 14 |
$this->view = $view; |
| 15 |
} |
| 16 |
|
| 17 |
public function index() { |
| 18 |
# Get Latest Options |
| 19 |
$options = $this->service->all(); |
| 20 |
|
| 21 |
# This needs refactoring - Martin Fowler HELP! |
| 22 |
$display_factory = new DisplayFactory(); |
| 23 |
$display_factory->build($options); |
| 24 |
|
| 25 |
# Build Our Menu Display |
| 26 |
$menu = new MenuViewModel($options); |
| 27 |
$html = new ButtonViewModel($options); |
| 28 |
|
| 29 |
# Only render if we don't have shortcodes turned on |
| 30 |
if($options['shortcode'] == 'off'): |
| 31 |
$this->view->render('button', ['options' => $options, 'button' => $html->getHtml()]); |
| 32 |
$this->view->render('menu', ['options' => $options, 'menu' => $menu->getHtml()]); |
| 33 |
else: |
| 34 |
add_shortcode('responsive_menu', function($atts) use($options, $html, $menu) { |
| 35 |
|
| 36 |
if($atts) |
| 37 |
array_walk($atts, function($a, $b) use ($options) { $options[$b] = $a; }); |
| 38 |
|
| 39 |
$html = $this->view->make('button', ['options' => $options, 'button' => $html->getHtml()]); |
| 40 |
|
| 41 |
return $html . $this->view->make('menu', ['options' => $options, 'menu' => $menu->getHtml()]); |
| 42 |
|
| 43 |
}); |
| 44 |
endif; |
| 45 |
|
| 46 |
} |
| 47 |
|
| 48 |
} |
| 49 |
|