JHtmlAccess/usergroup

From Joomla! Documentation

Jump to: navigation, search

Contents

Description

Displays a list of the available user groups.

Syntax

static JHtmlAccess::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
                        )
                );
        }
Personal tools