/**
* Returns a UL list of user groups with checkboxes
*
* @param string $name The name of the checkbox controls array
* @param array $selected An array of the checked boxes
* @param boolean $checkSuperAdmin If false only super admins can add to super admin groups
*
* @return string
*
* @since 1.6
*/
public static function usergroups($name, $selected, $checkSuperAdmin = false)
{
static $count;
$count++;
$isSuperAdmin = Factory::getUser()->authorise('core.admin');
$groups = array_values(UserGroupsHelper::getInstance()->getAll());
$html = array();
for ($i = 0, $n = count($groups); $i < $n; $i++) {
$item =& $groups[$i];
// If checkSuperAdmin is true, only add item if the user is superadmin or the group is not super admin
if (!$checkSuperAdmin || $isSuperAdmin || !AccessCheck::checkGroup($item->id, 'core.admin')) {
// 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[] = ' <div class="control-group">';
$html[] = ' <div class="controls">';
$html[] = ' <label class="form-check-label checkbox" for="' . $eid . '">';
$html[] = ' <input class="form-check-input" type="checkbox" name="' . $name . '[]" value="' . $item->id . '" id="' . $eid . '"';
$html[] = ' ' . $checked . $rel . '>';
$html[] = ' ' . LayoutHelper::render('joomla.html.treeprefix', array('level' => $item->level + 1)) . $item->title;
$html[] = ' </label>';
$html[] = ' </div>';
$html[] = ' </div>';
}
}
return implode("\n", $html);
}