/redirect/code/trunk/administrator/components/com_redirect/libraries/jxtended/form/fields/usergroup.php
PHP | 62 lines | 25 code | 8 blank | 29 comment | 1 complexity | 18449dca465127ad68ae929b264c6f6c MD5 | raw file
- <?php
- /**
- * @version $Id: usergroup.php 390 2010-11-05 11:35:33Z eddieajau $
- * @package JXtended.Libraries
- * @subpackage Form
- * @copyright Copyright 2005 - 2010 New Life in IT Pty Ltd. All rights reserved.
- * @license GNU General Public License
- * @link http://www.theartofjoomla.com
- */
- defined('JPATH_BASE') or die('Restricted Access');
- jimport('joomla.html.html');
- require_once dirname(__FILE__).'/list.php';
- /**
- * Form Field class for JXtended Libraries.
- *
- * @package JXtended.Libraries
- * @subpackage Form
- * @since 1.1
- */
- class JFormFieldUserGroup extends JFormFieldList
- {
- /**
- * The field type.
- *
- * @var string
- */
- protected $type = 'UserGroup';
- /**
- * Method to get a list of options for a list input.
- *
- * @return array An array of JHtml options.
- */
- protected function _getOptions()
- {
- // Get a database object.
- $db = &JFactory::getDbo();
- // Get the user groups from the database.
- $db->setQuery(
- 'SELECT a.id AS value, a.title AS text, COUNT(DISTINCT b.id) AS level' .
- ' FROM #__usergroups AS a' .
- ' LEFT JOIN `#__usergroups` AS b ON a.lft > b.lft AND a.rgt < b.rgt' .
- ' GROUP BY a.id' .
- ' ORDER BY a.lft ASC'
- );
- $options = $db->loadObjectList();
- // Pad the option text with spaces using depth level as a multiplier.
- for ($i=0,$n=count($options); $i < $n; $i++) {
- $options[$i]->text = str_repeat('- ',$options[$i]->level).$options[$i]->text;
- }
- // Merge any additional options in the XML definition.
- $options = array_merge(parent::_getOptions(), $options);
- return $options;
- }
- }