Files
@ 7ec91347b83f
Branch filter:
Location: hot67beta/libraries/joomla/html/parameter/element/menuitem.php
7ec91347b83f
3.8 KiB
text/x-php
there we go
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | <?php
/**
* @version $Id: menuitem.php 11324 2008-12-05 19:06:24Z kdevine $
* @package Joomla.Framework
* @subpackage Parameter
* @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
// Check to ensure this file is within the rest of the framework
defined('JPATH_BASE') or die();
/**
* Renders a menu item element
*
* @package Joomla.Framework
* @subpackage Parameter
* @since 1.5
*/
class JElementMenuItem extends JElement
{
/**
* Element name
*
* @access protected
* @var string
*/
var $_name = 'MenuItem';
function fetchElement($name, $value, &$node, $control_name)
{
$db =& JFactory::getDBO();
$menuType = $this->_parent->get('menu_type');
if (!empty($menuType)) {
$where = ' WHERE menutype = '.$db->Quote($menuType);
} else {
$where = ' WHERE 1';
}
// load the list of menu types
// TODO: move query to model
$query = 'SELECT menutype, title' .
' FROM #__menu_types' .
' ORDER BY title';
$db->setQuery( $query );
$menuTypes = $db->loadObjectList();
if ($state = $node->attributes('state')) {
$where .= ' AND published = '.(int) $state;
}
// load the list of menu items
// TODO: move query to model
$query = 'SELECT id, parent, name, menutype, type' .
' FROM #__menu' .
$where .
' ORDER BY menutype, parent, ordering'
;
$db->setQuery($query);
$menuItems = $db->loadObjectList();
// establish the hierarchy of the menu
// TODO: use node model
$children = array();
if ($menuItems)
{
// first pass - collect children
foreach ($menuItems as $v)
{
$pt = $v->parent;
$list = @$children[$pt] ? $children[$pt] : array();
array_push( $list, $v );
$children[$pt] = $list;
}
}
// second pass - get an indent list of the items
$list = JHTML::_('menu.treerecurse', 0, '', array(), $children, 9999, 0, 0 );
// assemble into menutype groups
$n = count( $list );
$groupedList = array();
foreach ($list as $k => $v) {
$groupedList[$v->menutype][] = &$list[$k];
}
// assemble menu items to the array
$options = array();
$options[] = JHTML::_('select.option', '', '- '.JText::_('Select Item').' -');
foreach ($menuTypes as $type)
{
if ($menuType == '')
{
$options[] = JHTML::_('select.option', '0', ' ', 'value', 'text', true);
$options[] = JHTML::_('select.option', $type->menutype, $type->title . ' - ' . JText::_( 'Top' ), 'value', 'text', true );
}
if (isset( $groupedList[$type->menutype] ))
{
$n = count( $groupedList[$type->menutype] );
for ($i = 0; $i < $n; $i++)
{
$item = &$groupedList[$type->menutype][$i];
//If menutype is changed but item is not saved yet, use the new type in the list
if ( JRequest::getString('option', '', 'get') == 'com_menus' ) {
$currentItemArray = JRequest::getVar('cid', array(0), '', 'array');
$currentItemId = (int) $currentItemArray[0];
$currentItemType = JRequest::getString('type', $item->type, 'get');
if ( $currentItemId == $item->id && $currentItemType != $item->type) {
$item->type = $currentItemType;
}
}
$disable = strpos($node->attributes('disable'), $item->type) !== false ? true : false;
$options[] = JHTML::_('select.option', $item->id, ' ' .$item->treename, 'value', 'text', $disable );
}
}
}
return JHTML::_('select.genericlist', $options, ''.$control_name.'['.$name.']', 'class="inputbox"', 'value', 'text', $value, $control_name.$name);
}
}
|