[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/administrator/components/com_users/models/fields/ -> groupparent.php (source)

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


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