Back to ListHelper class

Method genericordering

public static array
genericordering
(mixed $query, mixed $chop = 30)
Returns an array of options
Parameters
  • \Joomla\Database\DatabaseQuery|string $query SQL with 'ordering' AS value and 'name field' AS text
  • int $chop The length of the truncated headline
Returns
  • array An array of objects formatted for JHtml list processing
Since
  • 1.5
Class: ListHelper
Project: Joomla

Method genericordering - Source code

/**
 * Returns an array of options
 *
 * @param   DatabaseQuery|string   $query  SQL with 'ordering' AS value and 'name field' AS text
 * @param   integer                $chop   The length of the truncated headline
 *
 * @return  array  An array of objects formatted for JHtml list processing
 *
 * @since   1.5
 */
public static function genericordering($query, $chop = 30)
{
    $db = Factory::getDbo();
    $options = array();
    $db->setQuery($query);
    $items = $db->loadObjectList();
    if (empty($items)) {
        $options[] = HTMLHelper::_('select.option', 1, Text::_('JLIB_FORM_FIELD_PARAM_INTEGER_FIRST_LABEL'));
        return $options;
    }
    $options[] = HTMLHelper::_('select.option', 0, ' - ' . Text::_('JLIB_FORM_FIELD_PARAM_INTEGER_FIRST_LABEL') . ' - ');
    for ($i = 0, $n = count($items); $i < $n; $i++) {
        $items[$i]->text = Text::_($items[$i]->text);
        if (StringHelper::strlen($items[$i]->text) > $chop) {
            $text = StringHelper::substr($items[$i]->text, 0, $chop) . '...';
        } else {
            $text = $items[$i]->text;
        }
        $options[] = HTMLHelper::_('select.option', $items[$i]->value, $text);
    }
    $options[] = HTMLHelper::_('select.option', $items[$i - 1]->value + 1, ' - ' . Text::_('JLIB_FORM_FIELD_PARAM_INTEGER_LAST_LABEL') . ' - ');
    return $options;
}