[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

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

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


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1