public function generateMenu() { $menu = new ioMenu(); if ($this->getCurrentApp() == Menu::FRONTEND_APP) { $routings = sfYaml::load(sfConfig::get('sf_apps_dir') . '/' . Menu::FRONTEND_APP . '/config/routing.yml'); } else { $routings = sfYaml::load(sfConfig::get('sf_apps_dir') . '/' . Menu::BACKEND_APP . '/config/routing.yml'); } foreach ($this->getItems() as $item) { foreach ($routings as $key => $routing) { if ("@" . $key == $item->routing) { if (!empty($item->section)) { //Set class "active" if the item is a link to the current page if ($menu->getChild($item->section, false) == null) { $menu->addChild($item->section, $item->section_routing)->setLinkOptions(array('class' => 'link')); } $menu->getChild($item->section)->addChild($item->text, $item->routing)->setLinkOptions(array('class' => 'link large')); } else { //Set class "active" if the item is a link to the current page $menu->addChild($item->text, $item->routing)->setLinkOptions(array('class' => 'link')); } } } } return $menu; }
function get_ioMenu($name = null) { $ioMenus = (include sfContext::getInstance()->getConfigCache()->checkConfig('config/navigation.yml')); $menu = ioMenu::createFromArray($ioMenus[$name]); return $menu; }
require_once dirname(__FILE__) . '/../bootstrap/functional.php'; require_once $_SERVER['SYMFONY'] . '/vendor/lime/lime.php'; require_once sfConfig::get('sf_lib_dir') . '/test/unitHelper.php'; // @BeforeAll $file = dirname(__FILE__) . '/../fixtures/project/apps/frontend/config/navigation.yml'; $ch = new ioMenuConfigHandler(); $testCount = 12; $t = new lime_test($testCount); // @Test general validation $t->diag('testing cache file'); $t->is($ch->execute(array()), false, 'fast quit for no config files found'); $t->is($buffer = $ch->execute(array($file)), true, 'buffer written'); $t->is(substr($buffer, 0, 5), '<?php', 'The cache config value begins with <?php'); $buffer = substr($buffer, 5); // remove the open <?php from the cache config $buffer = eval($buffer); $t->isa_ok($buffer, 'array', 'buffer is a menu array'); // @Test single level menus $t->diag('testing single level menu'); $t->ok(isset($buffer['singleLevel']), 'single level menu correctly generated'); $menu = ioMenu::createFromArray($buffer['singleLevel']); $t->is(get_class($menu), 'ioMenuItem', 'menu correctly instanciated'); $t->is(count($menu), 2, 'item count is correct'); // @Test single level menus $t->diag('testing 1 cascade menu'); $t->ok(isset($buffer['multiLevel']), 'multi level menu correctly generated'); $menu = ioMenu::createFromArray($buffer['multiLevel']); $t->is(get_class($menu), 'ioMenuItem', 'menu correctly instanciated'); $t->is(count($menu), 1, 'item count is correct'); $t->is(count($menu->getChild('level_1_1', false)), 2, 'childnodes added correctly'); $t->is(count($menu->getChild('level_1_1', false)->getChild('level_2_1', false)), 3, 'childnodes deeper inside added correctly');
<?php slot('leftcol'); $menu = new ioMenu(array('id' => 'charge_new_menu', 'class' => 'vert-menu')); $menu->addChild('Add a new vehicle', '@vehicle_new'); echo $menu->render(); end_slot();
<?php require_once dirname(__FILE__) . '/../bootstrap/functional.php'; require_once $_SERVER['SYMFONY'] . '/vendor/lime/lime.php'; $t = new lime_test(3); class ioMenuItemTest extends ioMenuItem { } $t->info('1 - Basic checks on the ioMenu object'); $menu = new ioMenu(array('class' => 'root'), 'ioMenuItemTest'); $ch1 = $menu->addChild('ch1'); $t->is($menu->getName(), null, 'The menu item has a null name'); $t->is($menu->getRoute(), null, 'The menu item has a null route'); $t->is(get_class($ch1), 'ioMenuItemTest', 'The children are created with the class passed into the constructor.');
<?php $menu = new ioMenu(array('id' => 'charts_menu', 'class' => 'vert-menu')); $menu->addChild('Performance Indicators', '@chart_index'); $menu->addChild('Costs'); $menu->addChild('Travel'); $menu->addChild('Fuel consumption'); $menu['Costs']->addChild('Cost per km', '@chart_cost_per_km'); $menu['Costs']->addChild('Cost per year', '@chart_cost_per_year'); $menu['Costs']->addChild('Cost allocation', '@chart_cost_allocation'); $menu['Travel']->addChild('Annual travel', '@chart_trip_annual'); $menu['Travel']->addChild('Monthly travel', '@chart_trip_monthly'); $menu['Fuel consumption']->addChild('Litres per 100 km', '@chart_consumption_per_distance'); $menu['Fuel consumption']->addChild('Litres per month', ''); echo $menu->render();
} $t->info(' 3.4 - Test ->getChild()'); $t->is($ch4->getChild('Grandchild 1'), $gc1, '->getChild(Grandchild 1) returns gc1.'); $t->is($ch4->getChild('gc4')->getName(), 'gc4', '->getChild() on a non-existent menu (gc4) creates a new child'); $t->is(count($ch4), 4, 'count(ch4) now returns 4, reflecting this new child.'); $t->is($ch4->getChild('nonexistent', false), null, '->getChild() on a non-existent menu passing false as the 2nd argument returns null without creating a new child.'); $t->info(' 3.5 - Test ->removeChildren()'); $t->info(' a) ch4 now has 4 children (gc1, gc2, gc3, gc4). Remove gc4.'); $gc4 = $ch4['gc4']; // so we can try to re-add it later $ch4->removeChild('gc4'); $t->is(count($ch4), 3, 'count(ch4) now returns only 3 children.'); $t->is($ch4->getChild('Grandchild 1')->isFirst(), true, '->isFirst() on gc1 correctly returns true.'); $t->is($ch4->getChild('gc3')->isLast(), true, '->isLast() on gc3 now returns true.'); $t->info('Now that gc4 has been removed, we can add it to another menu without an exception.'); $tmpMenu = new ioMenu(); try { $tmpMenu->addChild($gc4); $t->pass('No exception thrown.'); } catch (sfException $e) { $t->fail('Exception still thrown: ' . $e->getMessage()); } $t->info(' b) ch4 now has 3 children (gc1, gc2, gc3). Remove gc2.'); $ch4->removeChild('gc2'); $t->is(count($ch4), 2, 'count(ch4) now returns only 2 children.'); $t->is($ch4->getChild('Grandchild 1')->isFirst(), true, '->isFirst() on gc1 correctly returns true.'); $t->is($ch4->getChild('gc3')->isLast(), true, '->isLast() on gc3 now returns true'); $t->is($gc1->getNum(), 0, '->getNum() on gc1 returns 0'); $t->is($ch4->getChild('gc3')->getNum(), 1, '->getNum() on gc3 returns 1'); $t->info(' c) ch4 now has 2 children (gc1, gc3). Remove gc3.'); $ch4->removeChild('gc3');
<div class="five columns centered"> <?php $menu = new ioMenu(array('id' => 'bottommenu1', 'class' => 'hor-menu')); $menu->addChild('About Otokou', ''); $menu->addChild('Contact', ''); echo $menu->render(); ?> </div>
<div class="six columns"> <?php $menu = new ioMenu(array('id' => 'topmenu1', 'class' => 'hor-menu')); $menu->addChild('Homepage', '@homepage_welcome'); $menu->addChild('Charges', '@charge')->requiresAuth(true); $menu->addChild('Charts', '@chart_index')->requiresAuth(true); $menu->addChild('Reports', '@report_index')->requiresAuth(true); echo $menu->render(); ?> </div> <div class="two columns offset-by-four"> <?php $menu = new ioMenu(array('id' => 'topmenu2', 'class' => 'hor-menu')); $menu->addChild('Settings', '@user_settings_account')->requiresAuth(true); $menu->addChild('Login', '@sf_guard_signin', array('id' => 'login'))->requiresNoAuth(true); $menu->addChild('Logout', '@sf_guard_signout', array('id' => 'logout'))->requiresAuth(true); echo $menu->render(); ?> </div>
<?php $menu = new ioMenu(array('id' => 'user_settigns_menu', 'class' => 'vert-menu')); $menu->addChild('Account', '@user_settings_account'); $menu->addChild('Change password', '@sf_guard_forgot_password'); $menu->addChild('Manage vehicles', '@vehicle'); echo $menu->render();
<?php $menu = new ioMenu(array('id' => 'reports_menu', 'class' => 'vert-menu')); $menu->addChild('Create a new report', '@report_new'); $menu->addChild('(Un)archive vehicles', '@vehicle'); $nr = Doctrine_Core::getTable('Report')->countNewCustomReports($sf_user->getGuardUser()->getId()); if ($nr) { $msg = '<span class="vehicle_reports_count">(' . $nr . ' new)</span>'; } else { $msg = ''; } $menu->addChild('Custom reports' . $msg, '@reports_list_custom'); $menu->addChild('By Vehicle', '@report_index'); foreach ($vehicles as $vehicle) { $class = $vehicle->getIsArchived() ? 'vehicle_archived' : 'vehicle_active'; $nr = $vehicle->countNewOwnReports(); if ($nr) { $reports = get_partial('report/new_reports', array('nr' => $nr)); } else { $reports = ''; } $label = $vehicle->getName() . $reports; $menu['By Vehicle']->addChild($label, '@reports_list_vehicle?slug=' . $vehicle->getSlug(), array('class' => $class)); } echo $menu->render();