/** * Get a list of the user groups for filtering. * * @return array An array of JHtmlOption elements. * * @since 1.6 */ public static function getGroups() { $options = JHelperUsergroups::getInstance()->getAll(); foreach ($options as &$option) { $option->value = $option->id; $option->text = str_repeat('- ', $option->level) . $option->title; } return $options; }
/** * Method to get the options to populate list * * @return array The field option objects. * * @since 3.2 */ protected function getOptions() { // Hash for caching $hash = md5($this->element); if (!isset(static::$options[$hash])) { static::$options[$hash] = parent::getOptions(); $groups = JHelperUsergroups::getInstance()->getAll(); $options = array(); foreach ($groups as $group) { $options[] = (object) array('text' => str_repeat('- ', $group->level) . $group->title, 'value' => $group->id, 'level' => $group->level); } static::$options[$hash] = array_merge(static::$options[$hash], $options); } return static::$options[$hash]; }
/** * Displays a list of user groups. * * @param boolean $includeSuperAdmin true to include super admin groups, false to exclude them * * @return array An array containing a list of user groups. * * @since 2.5 */ public static function groups($includeSuperAdmin = false) { $options = array_values(JHelperUsergroups::getInstance()->getAll()); for ($i = 0, $n = count($options); $i < $n; $i++) { $options[$i]->value = $options[$i]->id; $options[$i]->text = str_repeat('- ', $options[$i]->level) . $options[$i]->title; $groups[] = JHtml::_('select.option', $options[$i]->value, $options[$i]->text); } // Exclude super admin groups if requested if (!$includeSuperAdmin) { $filteredGroups = array(); foreach ($groups as $group) { if (!JAccess::checkGroup($group->value, 'core.admin')) { $filteredGroups[] = $group; } } $groups = $filteredGroups; } return $groups; }
/** * Method to get the options to populate list * * @return array The field option objects. * * @since 3.2 */ protected function getOptions() { // Hash for caching $hash = md5($this->element); if (!isset(static::$options[$hash])) { static::$options[$hash] = parent::getOptions(); $groups = JHelperUsergroups::getInstance()->getAll(); $checkSuperUser = (int) $this->getAttribute('checksuperusergroup', 0); $isSuperUser = JFactory::getUser()->authorise('core.admin'); $options = array(); foreach ($groups as $group) { // Don't show super user groups to non super users. if ($checkSuperUser && !$isSuperUser && JAccess::checkGroup($group->id, 'core.admin')) { continue; } $options[] = (object) array('text' => str_repeat('- ', $group->level) . $group->title, 'value' => $group->id, 'level' => $group->level); } static::$options[$hash] = array_merge(static::$options[$hash], $options); } return static::$options[$hash]; }
/** * Method to get the field options. * * @return array The field option objects * * @since 1.6 */ protected function getOptions() { $options = JHelperUsergroups::getInstance()->getAll(); $user = JFactory::getUser(); // Prevent parenting to children of this item. if ($id = $this->form->getValue('id')) { unset($options[$id]); } $options = array_values($options); // Pad the option text with spaces using depth level as a multiplier. for ($i = 0, $n = count($options); $i < $n; $i++) { // Show groups only if user is super admin or group is not super admin if ($user->authorise('core.admin') || !JAccess::checkGroup($options[$i]->value, 'core.admin')) { $options[$i]->value = $options[$i]->id; $options[$i]->text = str_repeat('- ', $options[$i]->level) . $options[$i]->title; } else { unset($options[$i]); } } // Merge any additional options in the XML definition. $options = array_merge(parent::getOptions(), $options); return $options; }
/** * 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 = JFactory::getUser()->authorise('core.admin'); $groups = array_values(JHelperUsergroups::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 || !JAccess::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="checkbox" for="' . $eid . '">'; $html[] = ' <input type="checkbox" name="' . $name . '[]" value="' . $item->id . '" id="' . $eid . '"'; $html[] = ' ' . $checked . $rel . ' />'; $html[] = ' ' . JLayoutHelper::render('joomla.html.treeprefix', array('level' => $item->level + 1)) . $item->title; $html[] = ' </label>'; $html[] = ' </div>'; $html[] = ' </div>'; } } return implode("\n", $html); }
/** * Gets the parent groups that a leaf group belongs to in its branch back to the root of the tree * (including the leaf group id). * * @param mixed $groupId An integer or array of integers representing the identities to check. * * @return mixed True if allowed, false for an explicit deny, null for an implicit deny. * * @since 11.1 */ protected static function getGroupPath($groupId) { // Load all the groups to improve performance on intensive groups checks $groups = JHelperUsergroups::getInstance()->getAll(); if (!isset($groups[$groupId])) { return array(); } return $groups[$groupId]->path; }
/** * Get a list of the user groups. * * @return array * * @since 11.1 */ protected function getUserGroups() { $options = JHelperUsergroups::getInstance()->getAll(); foreach ($options as &$option) { $option->value = $option->id; $option->text = $option->title; } return array_values($options); }