[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/libraries/joomla/html/html/ -> category.php (source)

   1  <?php
   2  /**
   3   * @package     Joomla.Platform
   4   * @subpackage  HTML
   5   *
   6   * @copyright   Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
   7   * @license     GNU General Public License version 2 or later; see LICENSE
   8   */
   9  
  10  defined('JPATH_PLATFORM') or die;
  11  
  12  /**
  13   * Utility class for categories
  14   *
  15   * @package     Joomla.Platform
  16   * @subpackage  HTML
  17   * @since       11.1
  18   */
  19  abstract class JHtmlCategory
  20  {
  21      /**
  22       * Cached array of the category items.
  23       *
  24       * @var    array
  25       * @since  11.1
  26       */
  27      protected static $items = array();
  28  
  29      /**
  30       * Returns an array of categories for the given extension.
  31       *
  32       * @param   string  $extension  The extension option e.g. com_something.
  33       * @param   array   $config     An array of configuration options. By default, only
  34       *                              published and unpublished categories are returned.
  35       *
  36       * @return  array
  37       *
  38       * @since   11.1
  39       */
  40  	public static function options($extension, $config = array('filter.published' => array(0, 1)))
  41      {
  42          $hash = md5($extension . '.' . serialize($config));
  43  
  44          if (!isset(self::$items[$hash]))
  45          {
  46              $config = (array) $config;
  47              $db = JFactory::getDbo();
  48              $query = $db->getQuery(true);
  49  
  50              $query->select('a.id, a.title, a.level');
  51              $query->from('#__categories AS a');
  52              $query->where('a.parent_id > 0');
  53  
  54              // Filter on extension.
  55              $query->where('extension = ' . $db->quote($extension));
  56  
  57              // Filter on the published state
  58              if (isset($config['filter.published']))
  59              {
  60                  if (is_numeric($config['filter.published']))
  61                  {
  62                      $query->where('a.published = ' . (int) $config['filter.published']);
  63                  }
  64                  elseif (is_array($config['filter.published']))
  65                  {
  66                      JArrayHelper::toInteger($config['filter.published']);
  67                      $query->where('a.published IN (' . implode(',', $config['filter.published']) . ')');
  68                  }
  69              }
  70  
  71              $query->order('a.lft');
  72  
  73              $db->setQuery($query);
  74              $items = $db->loadObjectList();
  75  
  76              // Assemble the list options.
  77              self::$items[$hash] = array();
  78  
  79              foreach ($items as &$item)
  80              {
  81                  $repeat = ($item->level - 1 >= 0) ? $item->level - 1 : 0;
  82                  $item->title = str_repeat('- ', $repeat) . $item->title;
  83                  self::$items[$hash][] = JHtml::_('select.option', $item->id, $item->title);
  84              }
  85          }
  86  
  87          return self::$items[$hash];
  88      }
  89  
  90      /**
  91       * Returns an array of categories for the given extension.
  92       *
  93       * @param   string  $extension  The extension option.
  94       * @param   array   $config     An array of configuration options. By default, only published and unpublished categories are returned.
  95       *
  96       * @return  array   Categories for the extension
  97       *
  98       * @since   11.1
  99       */
 100  	public static function categories($extension, $config = array('filter.published' => array(0, 1)))
 101      {
 102          $hash = md5($extension . '.' . serialize($config));
 103  
 104          if (!isset(self::$items[$hash]))
 105          {
 106              $config = (array) $config;
 107              $db = JFactory::getDbo();
 108              $query = $db->getQuery(true);
 109  
 110              $query->select('a.id, a.title, a.level, a.parent_id');
 111              $query->from('#__categories AS a');
 112              $query->where('a.parent_id > 0');
 113  
 114              // Filter on extension.
 115              $query->where('extension = ' . $db->quote($extension));
 116  
 117              // Filter on the published state
 118              if (isset($config['filter.published']))
 119              {
 120                  if (is_numeric($config['filter.published']))
 121                  {
 122                      $query->where('a.published = ' . (int) $config['filter.published']);
 123                  }
 124                  elseif (is_array($config['filter.published']))
 125                  {
 126                      JArrayHelper::toInteger($config['filter.published']);
 127                      $query->where('a.published IN (' . implode(',', $config['filter.published']) . ')');
 128                  }
 129              }
 130  
 131              $query->order('a.lft');
 132  
 133              $db->setQuery($query);
 134              $items = $db->loadObjectList();
 135  
 136              // Assemble the list options.
 137              self::$items[$hash] = array();
 138  
 139              foreach ($items as &$item)
 140              {
 141                  $repeat = ($item->level - 1 >= 0) ? $item->level - 1 : 0;
 142                  $item->title = str_repeat('- ', $repeat) . $item->title;
 143                  self::$items[$hash][] = JHtml::_('select.option', $item->id, $item->title);
 144              }
 145              // Special "Add to root" option:
 146              self::$items[$hash][] = JHtml::_('select.option', '1', JText::_('JLIB_HTML_ADD_TO_ROOT'));
 147          }
 148  
 149          return self::$items[$hash];
 150      }
 151  }


Generated: Tue Apr 3 11:40:28 2012 Cross-referenced by PHPXref 0.7.1