/** * @covers MenuItem::getId */ public function testGetId() { $id = $this->menuItem->getId(); $actual = "" . $id; $excepted = "dashboard"; $this->assertSame($excepted, $actual); }
public function getItems() { $user = Transaction::getInstance()->getUser(); $items = array(); foreach ($this->xml->item as $element) { $item = new MenuItem($this, $element); if ($item->getId() == $this->mainMenuId) { $item->setSelected(true); } if (!$item->isAdminOnly() || $user->isAdmin()) { $items[] = $item; } } return $items; }
public function __construct($menu, $xmlElement) { $this->attributes = self::getXmlElementAttributes($xmlElement); $this->menu = $menu; $this->id = $xmlElement['id']; $this->adminOnly = $xmlElement['adminOnly']; $this->name = $xmlElement->name; $this->href = $xmlElement->href; $this->onclick = $xmlElement->onclick; $this->class = $xmlElement->class; $this->content = $xmlElement->content; $this->subcontent = $xmlElement->subcontent; $this->add = $xmlElement->add; $this->display = $xmlElement->disp; $this->xmlElement = $xmlElement; foreach ($xmlElement->item as $childItem) { $item = new MenuItem($this->menu, $childItem); if ($item->getId() == $menu->getSubMenuId()) { $item->setSelected(true); } $this->items[] = $item; } }
public function getAddEditForm($target = '/admin/Menu') { require_once 'Menu.php'; if (isset($_REQUEST['id'])) { $item = new MenuItem($_REQUEST['id']); } $status = array('active' => 'Active', 'disabled' => 'Disabled'); $defaultValues['status'] = @array($item->status); $menu = new Menu(); $parent = $menu->toArray(); $defaultValues['parent'] = @array($item->parent); $form = new Form('menu_addedit', 'POST', $target, '', array('class' => 'admin')); if (@$item) { $form->setConstants(array('id' => $item->getId(), 'section' => 'addedit')); $form->addElement('hidden', 'id'); $links = $menu->getLinkables($item->module_id); } else { $form->setConstants(array('section' => 'addedit')); } $form->addElement('hidden', 'section'); $form->addElement('text', 'display', 'Display Name', array('value' => @$item->display)); $active = Config::getActiveModules(); $linkableType = array(); foreach ($active as $module) { $modulename = 'Module_' . $module['module']; include_once SITE_ROOT . '/modules/' . $module['module'] . '/' . $module['module'] . '.php'; $obj = new $modulename(); $test = new ReflectionClass($modulename); if ($test->hasMethod('getValidLinks')) { $linkableType[$module['id']] = $obj->linkType(); } } if (@(!$item)) { $keys = array_keys($linkableType); $links = $menu->getLinkables($keys[0]); } $defaultValues['link'] = @array($item->link_id); $defaultValues['linktype'] = @array($item->module_id); $defaultValues['target'] = @array($item->target); $form->addElement('select', 'status', 'Status', $status); $form->addElement('select', 'linktype', 'Link Type', $linkableType); $form->addElement('select', 'link', 'Link To', $links); $form->addElement('select', 'target', 'Open In', array('same' => 'Same Window', 'new' => 'New Window')); $form->addElement('select', 'parent', 'Parent Item', $parent); $form->addElement('submit', 'submit', 'Save'); $form->applyFilter('display', 'trim'); $form->addRule('display', 'Please enter a display name', 'required', null, 'client'); $form->addRule('parent', 'Please choose a parent', 'required', null, 'client'); $form->addRule('linktype', 'Please choose a link type', 'required', null, 'client'); $form->addRule('link', 'Please choose a link page', 'required', null, 'client'); $form->addRule('target', 'Please choose a target', 'required', null, 'client'); $form->addRule('status', 'Please choose a status', 'required', null, 'client'); $form->setDefaults($defaultValues); if (isset($_REQUEST['submit']) && $form->validate()) { $this->template = 'admin/menu.tpl'; $this->doMenuSubmit(); return false; } else { if (isset($_REQUEST['submit'])) { $formArray['errors'] = $form->_errors; } } return $form; }
private function _extractMenuItemToArray(MenuItem $menuItem) { $menu['id'] = $menuItem->getId(); $menu['menuTitle'] = $menuItem->getMenuTitle(); $menu['level'] = $menuItem->getLevel(); $menu['module'] = ''; $menu['action'] = ''; $menu['subMenuItems'] = array(); $screen = $menuItem->getScreen(); if ($screen instanceof Screen) { $menu['module'] = $screen->getModule()->getName(); $menu['action'] = $screen->getActionUrl(); $menu['urlExtras'] = $menuItem->getUrlExtras(); } return $menu; }
$menu_item->setName('ABOUT US'); $menu_item->setParentId($root_id); $menu_item->setUri('about'); $menu_item->save(); $menu_item = new MenuItem(); $menu_item->setWeight($weight++); $menu_item->setMenuId($menu->getId()); $menu_item->setName('CONTACT'); $menu_item->setParentId($root_id); $menu_item->setUri('contact'); $menu_item->save(); $menu_item = new MenuItem(); $menu_item->setWeight($weight++); $menu_item->setMenuId($menu->getId()); $menu_item->setName('Student service'); $menu_item->setParentId($menu_item_1->getId()); $menu_item->setUri('services/student'); $menu_item->save(); $menu_item = new MenuItem(); $menu_item->setWeight($weight++); $menu_item->setMenuId($menu->getId()); $menu_item->setName('Immigration service'); $menu_item->setParentId($menu_item_1->getId()); $menu_item->setUri('services/immigration'); $menu_item->save(); $menu = new Menu(); $menu->setName('底部LINKS'); $menu->setReserved(1); $menu->save(); $menu_item = new MenuItem(); $menu_item->setWeight($weight++);
/// proceed submission // proceed for $name $object->setName($name); // proceed for $country_id $object->setCountryId($country_id); if ($error_flag == false) { if ($object->save()) { // create root menu_it $menu_item = new MenuItem(); $menu_item->setWeight(0); $menu_item->setMenuId($object->getId()); $menu_item->setName('root'); $menu_item->setParentId(null); $menu_item->setUri(''); $menu_item->save(); $object->setRootMenuItemId($menu_item->getId()); $object->save(); Message::register(new Message(Message::SUCCESS, i18n(array("en" => "Record saved", "zh" => "记录保存成功")))); HTML::forwardBackToReferer(); } else { Message::register(new Message(Message::DANGER, i18n(array("en" => "Record failed to save", "zh" => "记录保存失败")))); } } } $html = new HTML(); $html->renderOut('core/backend/html_header', array('title' => i18n(array('en' => 'Create Menu', 'zh' => 'Create 菜单')))); $html->output('<div id="wrapper">'); $html->renderOut('core/backend/header'); $html->renderOut('menu/backend/menu_create', array('object' => $object)); $html->output('</div>'); $html->renderOut('core/backend/html_footer');
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param MenuItem $value A MenuItem object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(MenuItem $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } // if key === null self::$instances[$key] = $obj; } }