Source for file menuparent.php

Documentation is available at menuparent.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_menus
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8.  */
  9.  
  10. defined('JPATH_BASE'or die;
  11.  
  12.  
  13. /**
  14.  * Form Field class for the Joomla Framework.
  15.  *
  16.  * @package     Joomla.Administrator
  17.  * @subpackage  com_menus
  18.  * @since       1.6
  19.  */
  20. {
  21.     /**
  22.      * The form field type.
  23.      *
  24.      * @var        string 
  25.      * @since   1.6
  26.      */
  27.     protected $type = 'MenuParent';
  28.  
  29.     /**
  30.      * Method to get the field options.
  31.      *
  32.      * @return  array  The field option objects.
  33.      * @since   1.6
  34.      */
  35.     protected function getOptions()
  36.     {
  37.         $options array();
  38.  
  39.         $db JFactory::getDbo();
  40.         $query $db->getQuery(true)
  41.             ->select('a.id AS value, a.title AS text, a.level')
  42.             ->from('#__menu AS a')
  43.             ->join('LEFT'$db->quoteName('#__menu'' AS b ON a.lft > b.lft AND a.rgt < b.rgt');
  44.  
  45.         if ($menuType $this->form->getValue('menutype'))
  46.         {
  47.             $query->where('a.menutype = ' $db->quote($menuType));
  48.         }
  49.         else
  50.         {
  51.             $query->where('a.menutype != ' $db->quote(''));
  52.         }
  53.  
  54.         // Prevent parenting to children of this item.
  55.         if ($id $this->form->getValue('id'))
  56.         {
  57.             $query->join('LEFT'$db->quoteName('#__menu'' AS p ON p.id = ' . (int) $id)
  58.                 ->where('NOT(a.lft >= p.lft AND a.rgt <= p.rgt)');
  59.         }
  60.  
  61.         $query->where('a.published != -2')
  62.             ->group('a.id, a.title, a.level, a.lft, a.rgt, a.menutype, a.parent_id, a.published')
  63.             ->order('a.lft ASC');
  64.  
  65.         // Get the options.
  66.         $db->setQuery($query);
  67.  
  68.         try
  69.         {
  70.             $options $db->loadObjectList();
  71.         }
  72.         catch (RuntimeException $e)
  73.         {
  74.             JError::raiseWarning(500$e->getMessage());
  75.         }
  76.  
  77.         // Pad the option text with spaces using depth level as a multiplier.
  78.         for ($i 0$n count($options)$i $n$i++)
  79.         {
  80.             $options[$i]->text str_repeat('- '$options[$i]->level$options[$i]->text;
  81.         }
  82.  
  83.         // Merge any additional options in the XML definition.
  84.         $options array_merge(parent::getOptions()$options);
  85.  
  86.         return $options;
  87.     }
  88. }

Documentation generated on Tue, 19 Nov 2013 15:07:57 +0100 by phpDocumentor 1.4.3