API16:JHtmlAccess/usergroup
From Joomla! Documentation
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.
Contents |
Description
Displays a list of the available user groups.
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
Syntax
static usergroup($name, $selected, $attribs= '', $allowAll=true)
| Parameter Name | Default Value | Description |
|---|---|---|
| $name | The form field name. | |
| $selected | The name of the selected section. | |
| $attribs | Additional attributes to add to the select field. | |
| $allowAll | true | True to add "All Groups" option. |
Returns
string The required HTML for the SELECT tag.
Defined in
libraries/joomla/html/html/access.php
Importing
jimport( 'joomla.html.html.access' );
Source Body
public static function usergroup($name, $selected, $attribs = '', $allowAll = true) { $db = &JFactory::getDbo(); $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(); // Check for a database error. if ($db->getErrorNum()) { JError::raiseNotice(500, $db->getErrorMsg()); return null; } for ($i=0,$n=count($options); $i < $n; $i++) { $options[$i]->text = str_repeat('- ',$options[$i]->level).$options[$i]->text; } // If all usergroups is allowed, push it into the array. if ($allowAll) { array_unshift($options, JHtml::_('select.option', '', JText::_('JOption_Access_Show_All_Groups'))); } return JHtml::_('select.genericlist', $options, $name, array( 'list.attr' => $attribs, 'list.select' => $selected ) ); }
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples
<CodeExamplesForm />
