PageRenderTime 27ms CodeModel.GetById 18ms app.highlight 2ms RepoModel.GetById 0ms app.codeStats 0ms

/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
Possible License(s): LGPL-2.1
 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
10defined('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 */
21class JFormFieldUsergroup extends JFormField
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 .= $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
45		$attr .= ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
46		$attr .= $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
47		$attr .= $this->multiple ? ' multiple="multiple"' : '';
48
49		// Initialize JavaScript field attributes.
50		$attr .= $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : '';
51
52		// Iterate through the children and build an array of options.
53		foreach ($this->element->children() as $option)
54		{
55
56			// Only add <option /> elements.
57			if ($option->getName() != 'option')
58			{
59				continue;
60			}
61
62			// Create a new option object based on the <option /> element.
63			$tmp = JHtml::_(
64				'select.option', (string) $option['value'], trim((string) $option), 'value', 'text',
65				((string) $option['disabled'] == 'true')
66			);
67
68			// Set some option attributes.
69			$tmp->class = (string) $option['class'];
70
71			// Set some JavaScript option attributes.
72			$tmp->onclick = (string) $option['onclick'];
73
74			// Add the option object to the result set.
75			$options[] = $tmp;
76		}
77
78		return JHtml::_('access.usergroup', $this->name, $this->value, $attr, $options, $this->id);
79	}
80}