Source for file groupparent.php

Documentation is available at groupparent.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_users
  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_users
  18.  * @since       1.6
  19.  */
  20. {
  21.     /**
  22.      * The form field type.
  23.      *
  24.      * @var        string 
  25.      * @since   1.6
  26.      */
  27.     protected $type = 'GroupParent';
  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.         $user JFactory::getUser();
  41.         $query $db->getQuery(true)
  42.             ->select('a.id AS value, a.title AS text, COUNT(DISTINCT b.id) AS level')
  43.             ->from('#__usergroups AS a')
  44.             ->join('LEFT'$db->quoteName('#__usergroups'' AS b ON a.lft > b.lft AND a.rgt < b.rgt');
  45.  
  46.         // Prevent parenting to children of this item.
  47.         if ($id $this->form->getValue('id'))
  48.         {
  49.             $query->join('LEFT'$db->quoteName('#__usergroups'' AS p ON p.id = ' . (int) $id)
  50.                 ->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.             ->order('a.lft ASC');
  55.  
  56.         // Get the options.
  57.         $db->setQuery($query);
  58.  
  59.         try
  60.         {
  61.             $options $db->loadObjectList();
  62.         }
  63.         catch (RuntimeException $e)
  64.         {
  65.             JError::raiseWarning(500$e->getMessage());
  66.         }
  67.  
  68.         // Pad the option text with spaces using depth level as a multiplier.
  69.         for ($i 0$n count($options)$i $n$i++)
  70.         {
  71.             // Show groups only if user is super admin or group is not super admin
  72.             if ($user->authorise('core.admin'|| (!JAccess::checkGroup($options[$i]->value'core.admin')))
  73.             {
  74.                 $options[$i]->text str_repeat('- '$options[$i]->level$options[$i]->text;
  75.             }
  76.             else
  77.             {
  78.                 unset($options[$i]);
  79.             }
  80.         }
  81.  
  82.         // Merge any additional options in the XML definition.
  83.         $options array_merge(parent::getOptions()$options);
  84.  
  85.         return $options;
  86.     }
  87. }

Documentation generated on Tue, 19 Nov 2013 15:04:08 +0100 by phpDocumentor 1.4.3