/** * Returns an array of menu items groups by menu. * * @param array An array of configuration options. * * @return array */ public static function menuitems($config = array()) { if (empty(self::$items)) { $db = JFactory::getDbo(); $db->setQuery('SELECT menutype AS value, title AS text' . ' FROM #__menu_types' . ' ORDER BY title'); $menus = $db->loadObjectList(); $query = $db->getQuery(true); $query->select('a.id AS value, a.title AS text, a.level, a.menutype'); $query->from('#__menu AS a'); $query->where('a.parent_id > 0'); $query->where('a.type <> ' . $db->quote('url')); $query->where('a.client_id = 0'); // Filter on the published state if (isset($config['published'])) { if (is_numeric($config['published'])) { $query->where('a.published = ' . (int) $config['published']); } else { if ($config['published'] === '') { $query->where('a.published IN (0,1)'); } } } $query->order('a.lft'); $db->setQuery($query); $items = $db->loadObjectList(); // Collate menu items based on menutype $lookup = array(); foreach ($items as &$item) { if (!isset($lookup[$item->menutype])) { $lookup[$item->menutype] = array(); } $lookup[$item->menutype][] =& $item; $item->text = str_repeat('- ', $item->level) . $item->text; } self::$items = array(); foreach ($menus as &$menu) { // Start group: self::$items[] = JHtml::_('select.optgroup', $menu->text); // Special "Add to this Menu" option: self::$items[] = JHtml::_('select.option', $menu->value . '.1', JText::_('JLIB_HTML_ADD_TO_THIS_MENU')); // Menu items: if (isset($lookup[$menu->value])) { foreach ($lookup[$menu->value] as &$item) { self::$items[] = JHtml::_('select.option', $menu->value . '.' . $item->value, $item->text); } } // Finish group: self::$items[] = JHtml::_('select.optgroup', $menu->text); } } return self::$items; }
/** * Returns an array of menu items groups by menu. * * @param array An array of configuration options. * * @return array */ public static function menuitems($config = array()) { if (empty(self::$items)) { $db =& JFactory::getDbo(); $db->setQuery('SELECT menutype As value, title As text' . ' FROM #__menu_types' . ' ORDER BY title'); $menus = $db->loadObjectList(); $query = new JQuery(); $query->select('a.id AS value, a.title As text, a.level, a.menutype'); $query->from('#__menu AS a'); $query->where('a.parent_id > 0'); $query->where('a.type <> ' . $db->quote('url')); // Filter on the published state if (isset($config['published'])) { $query->where('a.published = ' . (int) $config['published']); } $query->order('a.lft'); $db->setQuery($query); $items = $db->loadObjectList(); // Collate menu items based on menutype $lookup = array(); foreach ($items as &$item) { if (!isset($lookup[$item->menutype])) { $lookup[$item->menutype] = array(); } $lookup[$item->menutype][] =& $item; $item->text = str_repeat('- ', $item->level) . $item->text; } self::$items = array(); foreach ($menus as &$menu) { self::$items[] = JHtml::_('select.optgroup', $menu->text); self::$items[] = JHtml::_('select.option', $menu->value . '.0', JText::_('Menus_Add_to_this_menu')); if (isset($lookup[$menu->value])) { foreach ($lookup[$menu->value] as &$item) { self::$items[] = JHtml::_('select.option', $menu->value . '.' . $item->value, $item->text); } } } } return self::$items; }