PageRenderTime 38ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/redirect/code/trunk/administrator/components/com_redirect/libraries/jxtended/form/fields/usergroup.php

https://bitbucket.org/eddieajau/the-art-of-joomla-archive
PHP | 62 lines | 25 code | 8 blank | 29 comment | 1 complexity | 18449dca465127ad68ae929b264c6f6c MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: usergroup.php 390 2010-11-05 11:35:33Z eddieajau $
  4. * @package JXtended.Libraries
  5. * @subpackage Form
  6. * @copyright Copyright 2005 - 2010 New Life in IT Pty Ltd. All rights reserved.
  7. * @license GNU General Public License
  8. * @link http://www.theartofjoomla.com
  9. */
  10. defined('JPATH_BASE') or die('Restricted Access');
  11. jimport('joomla.html.html');
  12. require_once dirname(__FILE__).'/list.php';
  13. /**
  14. * Form Field class for JXtended Libraries.
  15. *
  16. * @package JXtended.Libraries
  17. * @subpackage Form
  18. * @since 1.1
  19. */
  20. class JFormFieldUserGroup extends JFormFieldList
  21. {
  22. /**
  23. * The field type.
  24. *
  25. * @var string
  26. */
  27. protected $type = 'UserGroup';
  28. /**
  29. * Method to get a list of options for a list input.
  30. *
  31. * @return array An array of JHtml options.
  32. */
  33. protected function _getOptions()
  34. {
  35. // Get a database object.
  36. $db = &JFactory::getDbo();
  37. // Get the user groups from the database.
  38. $db->setQuery(
  39. 'SELECT a.id AS value, a.title AS text, COUNT(DISTINCT b.id) AS level' .
  40. ' FROM #__usergroups AS a' .
  41. ' LEFT JOIN `#__usergroups` AS b ON a.lft > b.lft AND a.rgt < b.rgt' .
  42. ' GROUP BY a.id' .
  43. ' ORDER BY a.lft ASC'
  44. );
  45. $options = $db->loadObjectList();
  46. // Pad the option text with spaces using depth level as a multiplier.
  47. for ($i=0,$n=count($options); $i < $n; $i++) {
  48. $options[$i]->text = str_repeat('- ',$options[$i]->level).$options[$i]->text;
  49. }
  50. // Merge any additional options in the XML definition.
  51. $options = array_merge(parent::_getOptions(), $options);
  52. return $options;
  53. }
  54. }