JHtmlAccess/usergroups
From Joomla! Documentation
< API16:JHtmlAccess
The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.
Description[edit]
Returns a UL list of user groups with check boxes
<! removed transcluded page call, red link never existed >
Syntax[edit]
static 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[edit]
string
Defined in[edit]
libraries/joomla/html/html/access.php
Importing[edit]
jimport( 'joomla.html.html.access' );
Source Body[edit]
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);
}
<! removed transcluded page call, red link never existed >
Examples[edit]
Code Examples[edit]