Back to TemplatestyleField class

Method getGroups

protected array
getGroups
()
Method to get the list of template style options grouped by template.
Returns
  • array The field option objects as a nested array in groups.
Since
  • 1.6

Method getGroups - Source code

/**
 * Method to get the list of template style options grouped by template.
 * Use the client attribute to specify a specific client.
 * Use the template attribute to specify a specific template
 *
 * @return  array  The field option objects as a nested array in groups.
 *
 * @since   1.6
 */
protected function getGroups()
{
    $groups = array();
    $lang = Factory::getLanguage();
    // Get the client and client_id.
    $client = ApplicationHelper::getClientInfo($this->clientName, true);
    // Get the template.
    $template = $this->template;
    // Get the database object and a new query object.
    $db = Factory::getDbo();
    $query = $db->getQuery(true);
    // Build the query.
    $query->select([$db->quoteName('s.id'), $db->quoteName('s.title'), $db->quoteName('e.name'), $db->quoteName('s.template')])->from($db->quoteName('#__template_styles', 's'))->where($db->quoteName('s.client_id') . ' = :clientId')->bind(':clientId', $client->id, ParameterType::INTEGER)->order([$db->quoteName('template'), $db->quoteName('title')]);
    if ($template) {
        $query->where('s.template = ' . $db->quote($template));
    }
    $query->join('LEFT', '#__extensions as e on e.element=s.template')->where('e.enabled = 1')->where($db->quoteName('e.type') . ' = ' . $db->quote('template'));
    // Set the query and load the styles.
    $db->setQuery($query);
    $styles = $db->loadObjectList();
    // Build the grouped list array.
    if ($styles) {
        foreach ($styles as $style) {
            $template = $style->template;
            $lang->load('tpl_' . $template . '.sys', $client->path) || $lang->load('tpl_' . $template . '.sys', $client->path . '/templates/' . $template);
            $name = Text::_($style->name);
            // Initialize the group if necessary.
            if (!isset($groups[$name])) {
                $groups[$name] = array();
            }
            $groups[$name][] = HTMLHelper::_('select.option', $style->id, $style->title);
        }
    }
    // Merge any additional groups in the XML definition.
    $groups = array_merge(parent::getGroups(), $groups);
    return $groups;
}