API16:JHtmlCategory/options
From Joomla! Documentation
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 categories for the given extension.
Description:JHtmlCategory/options
Syntax
static options($extension, $config=array('filter.published'=> array(0, 1)))
| Parameter Name | Default Value | Description |
|---|---|---|
| $extension | The extension option. | |
| $config | array('filter.published'=> array(0, 1)) | An array of configuration options. By default, only published and unpulbished categories are returned. |
Returns
array
Defined in
libraries/joomla/html/html/category.php
Importing
jimport( 'joomla.html.html.category' );
Source Body
public static function options($extension, $config = array('filter.published' => array(0,1))) { $hash = md5($extension.'.'.serialize($config)); if (!isset(self::$items[$hash])) { $config = (array) $config; $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('a.id, a.title, a.level'); $query->from('#__categories AS a'); $query->where('a.parent_id > 0'); // Filter on extension. $query->where('extension = '.$db->quote($extension)); // Filter on the published state if (isset($config['filter.published'])) { if (is_numeric($config['filter.published'])) { $query->where('a.published = '.(int) $config['filter.published']); } else if (is_array($config['filter.published'])) { JArrayHelper::toInteger($config['filter.published']); $query->where('a.published IN ('.implode(',', $config['filter.published']).')'); } } $query->order('a.lft'); $db->setQuery($query); $items = $db->loadObjectList(); // Assemble the list options. self::$items[$hash] = array(); foreach ($items as &$item) { $item->title = str_repeat('- ', $item->level - 1).$item->title; self::$items[$hash][] = JHtml::_('select.option', $item->id, $item->title); } } return self::$items[$hash]; }
[Edit See Also] SeeAlso:JHtmlCategory/options
Examples
<CodeExamplesForm />
