Source for file categories.php

Documentation is available at categories.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Site
  4.  * @subpackage  com_content
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. /**
  13.  * This models supports retrieving lists of article categories.
  14.  *
  15.  * @package     Joomla.Site
  16.  * @subpackage  com_content
  17.  * @since       1.6
  18.  */
  19. {
  20.     /**
  21.      * Model context string.
  22.      *
  23.      * @var        string 
  24.      */
  25.     public $_context = 'com_content.categories';
  26.  
  27.     /**
  28.      * The category context (allows other extensions to derived from this model).
  29.      *
  30.      * @var        string 
  31.      */
  32.     protected $_extension = 'com_content';
  33.  
  34.     private $_parent null;
  35.  
  36.     private $_items null;
  37.  
  38.     /**
  39.      * Method to auto-populate the model state.
  40.      *
  41.      * Note. Calling getState in this method will result in recursion.
  42.      *
  43.      * @since   1.6
  44.      */
  45.     protected function populateState($ordering null$direction null)
  46.     {
  47.         $app JFactory::getApplication();
  48.         $this->setState('filter.extension'$this->_extension);
  49.  
  50.         // Get the parent id if defined.
  51.         $parentId $app->input->getInt('id');
  52.         $this->setState('filter.parentId'$parentId);
  53.  
  54.         $params $app->getParams();
  55.         $this->setState('params'$params);
  56.  
  57.         $this->setState('filter.published',    1);
  58.         $this->setState('filter.access',    true);
  59.     }
  60.  
  61.     /**
  62.      * Method to get a store id based on model configuration state.
  63.      *
  64.      * This is necessary because the model is used by the component and
  65.      * different modules that might need different sets of data or different
  66.      * ordering requirements.
  67.      *
  68.      * @param   string  $id    A prefix for the store id.
  69.      *
  70.      * @return  string  A store id.
  71.      */
  72.     protected function getStoreId($id '')
  73.     {
  74.         // Compile the store id.
  75.         $id    .= ':'.$this->getState('filter.extension');
  76.         $id    .= ':'.$this->getState('filter.published');
  77.         $id    .= ':'.$this->getState('filter.access');
  78.         $id    .= ':'.$this->getState('filter.parentId');
  79.  
  80.         return parent::getStoreId($id);
  81.     }
  82.  
  83.     /**
  84.      * Redefine the function an add some properties to make the styling more easy
  85.      *
  86.      * @param   bool    $recursive    True if you want to return children recursively.
  87.      *
  88.      * @return  mixed  An array of data items on success, false on failure.
  89.      * @since   1.6
  90.      */
  91.     public function getItems($recursive false)
  92.     {
  93.         if (!count($this->_items))
  94.         {
  95.             $app JFactory::getApplication();
  96.             $menu $app->getMenu();
  97.             $active $menu->getActive();
  98.             $params new JRegistry;
  99.  
  100.             if ($active)
  101.             {
  102.                 $params->loadString($active->params);
  103.             }
  104.  
  105.             $options array();
  106.             $options['countItems'$params->get('show_cat_num_articles_cat'1|| !$params->get('show_empty_categories_cat'0);
  107.             $categories JCategories::getInstance('Content'$options);
  108.             $this->_parent $categories->get($this->getState('filter.parentId''root'));
  109.  
  110.             if (is_object($this->_parent))
  111.             {
  112.                 $this->_items $this->_parent->getChildren($recursive);
  113.             }
  114.             else {
  115.                 $this->_items false;
  116.             }
  117.         }
  118.  
  119.         return $this->_items;
  120.     }
  121.  
  122.     public function getParent()
  123.     {
  124.         if (!is_object($this->_parent))
  125.         {
  126.             $this->getItems();
  127.         }
  128.  
  129.         return $this->_parent;
  130.     }
  131. }

Documentation generated on Tue, 19 Nov 2013 14:55:13 +0100 by phpDocumentor 1.4.3