Actions

API16

JHtmlList/genericordering

From Joomla! Documentation

< API16:JHtmlList
Revision as of 21:57, 13 May 2013 by JoomlaWikiBot (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Returns an array of options

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >

Syntax

static genericordering($sql, $chop= '30')
Parameter Name Default Value Description
$sql $sql SQL with ordering As value and 'name field' AS text
$chop '30' $chop The length of the truncated headline

Returns

array An array of objects formatted for list processing

Defined in

libraries/joomla/html/html/list.php

Importing

jimport( 'joomla.html.html.list' );

Source Body

public static function genericordering($sql, $chop = '30')
{
        $db = &JFactory::getDbo();
        $options        = array();
        $db->setQuery($sql);
 
        $items = $db->loadObjectList();
 
        // Check for a database error.
        if ($db->getErrorNum()) {
                JError::raiseNotice(500, $db->getErrorMsg());
                return false;
        }
 
        if (empty($items)) {
                $options[] = JHtml::_('select.option',  1, JText::_('JOption_Order_First'));
                return $options;
        }
 
        $options[] = JHtml::_('select.option',  0, '0 '. JText::_('JOption_Order_First'));
        for ($i=0, $n=count($items); $i < $n; $i++)
        {
                if (JString::strlen($items[$i]->text) > $chop) {
                        $text = JString::substr($items[$i]->text,0,$chop)."...";
                } else {
                        $text = $items[$i]->text;
                }
 
                $options[] = JHtml::_('select.option',  $items[$i]->value, $items[$i]->value.' ('.$text.')');
        }
        $options[] = JHtml::_('select.option',  $items[$i-1]->value+1, ($items[$i-1]->value+1).' '. JText::_('JOption_Order_Last'));
 
        return $options;
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples

<CodeExamplesForm />