JHtmlAccess/usergroups
From Joomla! Documentation
Contents |
Description
Returns a UL list of user groups with check boxes
Syntax
static JHtmlAccess::usergroups($name, $selected)
| Parameter Name | Default Value | Description |
|---|---|---|
| $name | $name The name of the checkbox controls array | |
| $selected | $selected An array of the checked boxes |
Returns
string
Defined in
libraries/joomla/html/html/access.php
Importing
jimport( 'joomla.html.html.access' );
Source Body
public static function usergroups($name, $selected)
{
static $count;
$count++;
$db = &JFactory::getDbo();
$db->setQuery(
'SELECT a.*, 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'
);
$groups = $db->loadObjectList();
// Check for a database error.
if ($db->getErrorNum()) {
JError::raiseNotice(500, $db->getErrorMsg());
return null;
}
$html = array();
$html[] = '<ul class="checklist usergroups">';
for ($i=0, $n=count($groups); $i < $n; $i++)
{
$item = &$groups[$i];
// Setup the variable attributes.
$eid = $count.'group_'.$item->id;
// don't call in_array unless something is selected
$checked = '';
if ($selected) {
$checked = in_array($item->id, $selected) ? ' checked="checked"' : '';
}
$rel = ($item->parent_id > 0) ? ' rel="'.$count.'group_'.$item->parent_id.'"' : '';
// Build the HTML for the item.
$html[] = ' <li>';
$html[] = ' <input type="checkbox" name="'.$name.'[]" value="'.$item->id.'" id="'.$eid.'"';
$html[] = ' '.$checked.$rel.' />';
$html[] = ' <label for="'.$eid.'">';
$html[] = ' '.str_repeat('<span class="gi">|—</span>', $item->level).$item->title;
$html[] = ' </label>';
$html[] = ' </li>';
}
$html[] = '</ul>';
return implode("\n", $html);
}