Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
usergroup.php
Aller à la documentation de ce fichier.
1 <?php
2 /**
3  * @package Joomla.Platform
4  * @subpackage Form
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
8  */
9 
10 defined('JPATH_PLATFORM') or die;
11 
12 /**
13  * Form Field class for the Joomla Platform.
14  * Supports a nested check box field listing user groups.
15  * Multiselect is available by default.
16  *
17  * @package Joomla.Platform
18  * @subpackage Form
19  * @since 11.1
20  */
22 {
23  /**
24  * The form field type.
25  *
26  * @var string
27  * @since 11.1
28  */
29  protected $type = 'Usergroup';
30 
31  /**
32  * Method to get the user group field input markup.
33  *
34  * @return string The field input markup.
35  *
36  * @since 11.1
37  */
38  protected function getInput()
39  {
40  $options = array();
41  $attr = '';
42 
43  // Initialize some field attributes.
44  $attr .= !empty($this->class) ? ' class="' . $this->class . '"' : '';
45  $attr .= $this->disabled ? ' disabled' : '';
46  $attr .= $this->size ? ' size="' . $this->size . '"' : '';
47  $attr .= $this->multiple ? ' multiple' : '';
48  $attr .= $this->required ? ' required aria-required="true"' : '';
49  $attr .= $this->autofocus ? ' autofocus' : '';
50 
51  // Initialize JavaScript field attributes.
52  $attr .= !empty($this->onchange) ? ' onchange="' . $this->onchange . '"' : '';
53  $attr .= !empty($this->onclick) ? ' onclick="' . $this->onclick . '"' : '';
54 
55  // Iterate through the children and build an array of options.
56  foreach ($this->element->children() as $option)
57  {
58  // Only add <option /> elements.
59  if ($option->getName() != 'option')
60  {
61  continue;
62  }
63 
64  $disabled = (string) $option['disabled'];
65  $disabled = ($disabled == 'true' || $disabled == 'disabled' || $disabled == '1');
66 
67  // Create a new option object based on the <option /> element.
68  $tmp = JHtml::_(
69  'select.option', (string) $option['value'], trim((string) $option), 'value', 'text',
70  $disabled
71  );
72 
73  // Set some option attributes.
74  $tmp->class = (string) $option['class'];
75 
76  // Set some JavaScript option attributes.
77  $tmp->onclick = (string) $option['onclick'];
78 
79  // Add the option object to the result set.
80  $options[] = $tmp;
81  }
82 
83  return JHtml::_('access.usergroup', $this->name, $this->value, $attr, $options, $this->id);
84  }
85 }