public static string
level
(mixed $name, mixed $selected, mixed $attribs = '', mixed $params = true, mixed $id = false)
/**
* Displays a list of the available access view levels
*
* @param string $name The form field name.
* @param string $selected The name of the selected section.
* @param string $attribs Additional attributes to add to the select field.
* @param mixed $params True to add "All Sections" option or an array of options
* @param mixed $id The form field id or false if not used
*
* @return string The required HTML for the SELECT tag.
*
* @see \Joomla\CMS\Form\Field\AccesslevelField
* @since 1.6
*/
public static function level($name, $selected, $attribs = '', $params = true, $id = false)
{
$db = Factory::getDbo();
$query = $db->getQuery(true)->select([$db->quoteName('a.id', 'value'), $db->quoteName('a.title', 'text')])->from($db->quoteName('#__viewlevels', 'a'))->group([$db->quoteName('a.id'), $db->quoteName('a.title'), $db->quoteName('a.ordering')])->order([$db->quoteName('a.ordering') . ' ASC', $db->quoteName('a.title') . ' ASC']);
// Get the options.
$db->setQuery($query);
$options = $db->loadObjectList();
// If params is an array, push these options to the array
if (is_array($params)) {
$options = array_merge($params, $options);
} elseif ($params) {
array_unshift($options, HTMLHelper::_('select.option', '', Text::_('JOPTION_ACCESS_SHOW_ALL_LEVELS')));
}
return HTMLHelper::_('select.genericlist', $options, $name, array('list.attr' => $attribs, 'list.select' => $selected, 'id' => $id));
}