2015-10-05 16:54:25 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Aviat\AnimeClient;
|
|
|
|
|
|
|
|
use Aviat\Ion\Di\ContainerInterface;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper object to manage menu creation and selection
|
|
|
|
*/
|
|
|
|
class MenuGenerator extends RoutingBase {
|
|
|
|
|
|
|
|
use \Aviat\Ion\Di\ContainerAware;
|
|
|
|
use \Aviat\Ion\StringWrapper;
|
|
|
|
use \Aviat\Ion\ArrayWrapper;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Html generation helper
|
|
|
|
*
|
|
|
|
* @var Aura\Html\HelperLocator
|
|
|
|
*/
|
|
|
|
protected $helper;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Menu config array
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $menus;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create menu generator
|
|
|
|
*
|
|
|
|
* @param ContainerInterface $container
|
|
|
|
*/
|
|
|
|
public function __construct(ContainerInterface $container)
|
|
|
|
{
|
|
|
|
parent::__construct($container);
|
2015-10-06 12:15:19 -04:00
|
|
|
$this->menus = $this->config->get('menus');
|
2015-10-05 16:54:25 -04:00
|
|
|
$this->helper = $container->get('html-helper');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate the full menu structure from the config files
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function parse_config()
|
|
|
|
{
|
|
|
|
// Note: Children menus have urls based on the
|
|
|
|
// current url path
|
|
|
|
/*
|
|
|
|
$parsed = [
|
|
|
|
'menu_name' => [
|
|
|
|
'items' => [
|
|
|
|
'title' => 'full_url_path',
|
|
|
|
],
|
|
|
|
'children' => [
|
|
|
|
'title' => 'full_url_path'
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
*/
|
|
|
|
|
|
|
|
$parsed = [];
|
|
|
|
|
2015-10-06 10:24:48 -04:00
|
|
|
foreach ($this->menus as $name => $menu)
|
2015-10-05 16:54:25 -04:00
|
|
|
{
|
|
|
|
$parsed[$name] = [];
|
2015-10-06 10:24:48 -04:00
|
|
|
foreach ($menu['items'] as $path_name => $partial_path)
|
2015-10-05 16:54:25 -04:00
|
|
|
{
|
|
|
|
$title = $this->string($path_name)->humanize()->titleize();
|
|
|
|
$parsed[$name]['items'][$title] = $this->string($menu['route_prefix'])->append($partial_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
// @TODO: Handle child menu(s)
|
|
|
|
if (count($menu['children']) > 0)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $parsed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate the html structure of the menu selected
|
|
|
|
*
|
|
|
|
* @param string $menu
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function generate($menu)
|
|
|
|
{
|
2015-10-06 10:24:48 -04:00
|
|
|
$parsed_config = $this->parse_config();
|
2015-10-05 16:54:25 -04:00
|
|
|
$menu_config = $parsed_config[$menu];
|
|
|
|
|
|
|
|
// Array of list items to add to the main menu
|
|
|
|
$main_menu = [];
|
|
|
|
|
|
|
|
|
|
|
|
// Start the menu list
|
|
|
|
$helper->ul();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// End of MenuGenerator.php
|