/libraries/joomla/form/fields/usergroup.php

https://bitbucket.org/eternaware/joomus · PHP · 80 lines · 31 code · 12 blank · 37 comment · 4 complexity · ac2c20a5481f6ab33417c50d912c6bff MD5 · raw file

  1. <?php
  2. /**
  3. * @package Joomla.Platform
  4. * @subpackage Form
  5. *
  6. * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE
  8. */
  9. defined('JPATH_PLATFORM') or die;
  10. /**
  11. * Form Field class for the Joomla Platform.
  12. * Supports a nested check box field listing user groups.
  13. * Multiselect is available by default.
  14. *
  15. * @package Joomla.Platform
  16. * @subpackage Form
  17. * @since 11.1
  18. */
  19. class JFormFieldUsergroup extends JFormField
  20. {
  21. /**
  22. * The form field type.
  23. *
  24. * @var string
  25. * @since 11.1
  26. */
  27. protected $type = 'Usergroup';
  28. /**
  29. * Method to get the user group field input markup.
  30. *
  31. * @return string The field input markup.
  32. *
  33. * @since 11.1
  34. */
  35. protected function getInput()
  36. {
  37. $options = array();
  38. $attr = '';
  39. // Initialize some field attributes.
  40. $attr .= $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
  41. $attr .= ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
  42. $attr .= $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
  43. $attr .= $this->multiple ? ' multiple="multiple"' : '';
  44. // Initialize JavaScript field attributes.
  45. $attr .= $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : '';
  46. // Iterate through the children and build an array of options.
  47. foreach ($this->element->children() as $option)
  48. {
  49. // Only add <option /> elements.
  50. if ($option->getName() != 'option')
  51. {
  52. continue;
  53. }
  54. // Create a new option object based on the <option /> element.
  55. $tmp = JHtml::_(
  56. 'select.option', (string) $option['value'], trim((string) $option), 'value', 'text',
  57. ((string) $option['disabled'] == 'true')
  58. );
  59. // Set some option attributes.
  60. $tmp->class = (string) $option['class'];
  61. // Set some JavaScript option attributes.
  62. $tmp->onclick = (string) $option['onclick'];
  63. // Add the option object to the result set.
  64. $options[] = $tmp;
  65. }
  66. return JHtml::_('access.usergroup', $this->name, $this->value, $attr, $options, $this->id);
  67. }
  68. }