[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/libraries/joomla/html/parameter/element/ -> menuitem.php (source)

   1  <?php
   2  /**
   3   * @package     Joomla.Platform
   4   * @subpackage  HTML
   5   *
   6   * @copyright   Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
   7   * @license     GNU General Public License version 2 or later; see LICENSE
   8   */
   9  
  10  defined('JPATH_PLATFORM') or die;
  11  
  12  /**
  13   * Renders a menu item element
  14   *
  15   * @package     Joomla.Platform
  16   * @subpackage  Parameter
  17   * @since       11.1
  18   * @deprecated  Use JformFieldMenuItem instead
  19   */
  20  class JElementMenuItem extends JElement
  21  {
  22      /**
  23       * Element name
  24       *
  25       * @var    string
  26       */
  27      protected $_name = 'MenuItem';
  28  
  29      /**
  30       * Fetch menu item element HTML
  31       *
  32       * @param   string       $name          Element name
  33       * @param   string       $value         Element value
  34       * @param   JXMLElement  &$node         JXMLElement node object containing the settings for the element
  35       * @param   string       $control_name  Control name
  36       *
  37       * @return  string
  38       *
  39       * @deprecated    12.1  useJFormFieldMenuItem::getGroups
  40       * @since   11.1
  41       *
  42       */
  43  	public function fetchElement($name, $value, &$node, $control_name)
  44      {
  45          // Deprecation warning.
  46          JLog::add('JElementMenuitem::fetchElement() is deprecated.', JLog::WARNING, 'deprecated');
  47  
  48          $db = JFactory::getDbo();
  49  
  50          $menuType = $this->_parent->get('menu_type');
  51          if (!empty($menuType))
  52          {
  53              $where = ' WHERE menutype = ' . $db->Quote($menuType);
  54          }
  55          else
  56          {
  57              $where = ' WHERE 1';
  58          }
  59  
  60          // Load the list of menu types
  61          // TODO: move query to model
  62          $query = 'SELECT menutype, title' . ' FROM #__menu_types' . ' ORDER BY title';
  63          $db->setQuery($query);
  64          $menuTypes = $db->loadObjectList();
  65  
  66          if ($state = $node->attributes('state'))
  67          {
  68              $where .= ' AND published = ' . (int) $state;
  69          }
  70  
  71          // load the list of menu items
  72          // TODO: move query to model
  73          $query = 'SELECT id, parent_id, title, menutype, type' . ' FROM #__menu' . $where . ' ORDER BY menutype, parent_id, ordering';
  74  
  75          $db->setQuery($query);
  76          $menuItems = $db->loadObjectList();
  77  
  78          // Establish the hierarchy of the menu
  79          // TODO: use node model
  80          $children = array();
  81  
  82          if ($menuItems)
  83          {
  84              // First pass - collect children
  85              foreach ($menuItems as $v)
  86              {
  87                  $pt = $v->parent_id;
  88                  $list = @$children[$pt] ? $children[$pt] : array();
  89                  array_push($list, $v);
  90                  $children[$pt] = $list;
  91              }
  92          }
  93  
  94          // Second pass - get an indent list of the items
  95          $list = JHtml::_('menu.treerecurse', 0, '', array(), $children, 9999, 0, 0);
  96  
  97          // Assemble into menutype groups
  98          $n = count($list);
  99          $groupedList = array();
 100          foreach ($list as $k => $v)
 101          {
 102              $groupedList[$v->menutype][] = &$list[$k];
 103          }
 104  
 105          // Assemble menu items to the array
 106          $options = array();
 107          $options[] = JHtml::_('select.option', '', JText::_('JOPTION_SELECT_MENU_ITEM'));
 108  
 109          foreach ($menuTypes as $type)
 110          {
 111              if ($menuType == '')
 112              {
 113                  $options[] = JHtml::_('select.option', '0', '&#160;', 'value', 'text', true);
 114                  $options[] = JHtml::_('select.option', $type->menutype, $type->title . ' - ' . JText::_('JGLOBAL_TOP'), 'value', 'text', true);
 115              }
 116              if (isset($groupedList[$type->menutype]))
 117              {
 118                  $n = count($groupedList[$type->menutype]);
 119                  for ($i = 0; $i < $n; $i++)
 120                  {
 121                      $item = &$groupedList[$type->menutype][$i];
 122  
 123                      // If menutype is changed but item is not saved yet, use the new type in the list
 124                      if (JRequest::getString('option', '', 'get') == 'com_menus')
 125                      {
 126                          $currentItemArray = JRequest::getVar('cid', array(0), '', 'array');
 127                          $currentItemId = (int) $currentItemArray[0];
 128                          $currentItemType = JRequest::getString('type', $item->type, 'get');
 129                          if ($currentItemId == $item->id && $currentItemType != $item->type)
 130                          {
 131                              $item->type = $currentItemType;
 132                          }
 133                      }
 134  
 135                      $disable = strpos($node->attributes('disable'), $item->type) !== false ? true : false;
 136                      $options[] = JHtml::_('select.option', $item->id, '&#160;&#160;&#160;' . $item->treename, 'value', 'text', $disable);
 137  
 138                  }
 139              }
 140          }
 141  
 142          return JHtml::_(
 143              'select.genericlist',
 144              $options,
 145              $control_name . '[' . $name . ']',
 146              array('id' => $control_name . $name, 'list.attr' => 'class="inputbox"', 'list.select' => $value)
 147          );
 148      }
 149  }


Generated: Tue Apr 3 11:40:28 2012 Cross-referenced by PHPXref 0.7.1