Source for file categories.php

Documentation is available at categories.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Legacy
  4.  * @subpackage  Categories
  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
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * JCategories Class.
  14.  *
  15.  * @package     Joomla.Legacy
  16.  * @subpackage  Categories
  17.  * @since       11.1
  18.  */
  19. {
  20.     /**
  21.      * Array to hold the object instances
  22.      *
  23.      * @var    array 
  24.      * @since  11.1
  25.      */
  26.     public static $instances array();
  27.  
  28.     /**
  29.      * Array of category nodes
  30.      *
  31.      * @var    mixed 
  32.      * @since  11.1
  33.      */
  34.     protected $_nodes;
  35.  
  36.     /**
  37.      * Array of checked categories -- used to save values when _nodes are null
  38.      *
  39.      * @var    array 
  40.      * @since  11.1
  41.      */
  42.     protected $_checkedCategories;
  43.  
  44.     /**
  45.      * Name of the extension the categories belong to
  46.      *
  47.      * @var    string 
  48.      * @since  11.1
  49.      */
  50.     protected $_extension = null;
  51.  
  52.     /**
  53.      * Name of the linked content table to get category content count
  54.      *
  55.      * @var    string 
  56.      * @since  11.1
  57.      */
  58.     protected $_table = null;
  59.  
  60.     /**
  61.      * Name of the category field
  62.      *
  63.      * @var    string 
  64.      * @since  11.1
  65.      */
  66.     protected $_field = null;
  67.  
  68.     /**
  69.      * Name of the key field
  70.      *
  71.      * @var    string 
  72.      * @since  11.1
  73.      */
  74.     protected $_key = null;
  75.  
  76.     /**
  77.      * Name of the items state field
  78.      *
  79.      * @var    string 
  80.      * @since  11.1
  81.      */
  82.     protected $_statefield = null;
  83.  
  84.     /**
  85.      * Array of options
  86.      *
  87.      * @var    array 
  88.      * @since  11.1
  89.      */
  90.     protected $_options = null;
  91.  
  92.     /**
  93.      * Class constructor
  94.      *
  95.      * @param   array  $options  Array of options
  96.      *
  97.      * @since   11.1
  98.      */
  99.     public function __construct($options)
  100.     {
  101.         $this->_extension = $options['extension'];
  102.         $this->_table = $options['table'];
  103.         $this->_field = (isset($options['field']&& $options['field']$options['field''catid';
  104.         $this->_key = (isset($options['key']&& $options['key']$options['key''id';
  105.         $this->_statefield = (isset($options['statefield'])) $options['statefield''state';
  106.         $options['access'(isset($options['access'])) $options['access''true';
  107.         $options['published'(isset($options['published'])) $options['published'1;
  108.         $this->_options = $options;
  109.  
  110.         return true;
  111.     }
  112.  
  113.     /**
  114.      * Returns a reference to a JCategories object
  115.      *
  116.      * @param   string  $extension  Name of the categories extension
  117.      * @param   array   $options    An array of options
  118.      *
  119.      * @return  JCategories         JCategories object
  120.      *
  121.      * @since   11.1
  122.      */
  123.     public static function getInstance($extension$options array())
  124.     {
  125.         $hash md5($extension serialize($options));
  126.  
  127.         if (isset(self::$instances[$hash]))
  128.         {
  129.             return self::$instances[$hash];
  130.         }
  131.  
  132.         $parts explode('.'$extension);
  133.         $component 'com_' strtolower($parts[0]);
  134.         $section count($parts$parts[1'';
  135.         $classname ucfirst(substr($component4)) ucfirst($section'Categories';
  136.  
  137.         if (!class_exists($classname))
  138.         {
  139.             $path JPATH_SITE '/components/' $component '/helpers/category.php';
  140.             if (is_file($path))
  141.             {
  142.                 include_once $path;
  143.             }
  144.             else
  145.             {
  146.                 return false;
  147.             }
  148.         }
  149.  
  150.         self::$instances[$hashnew $classname($options);
  151.  
  152.         return self::$instances[$hash];
  153.     }
  154.  
  155.     /**
  156.      * Loads a specific category and all its children in a JCategoryNode object
  157.      *
  158.      * @param   mixed    $id         an optional id integer or equal to 'root'
  159.      * @param   boolean  $forceload  True to force  the _load method to execute
  160.      *
  161.      * @return  mixed    JCategoryNode object or null if $id is not valid
  162.      *
  163.      * @since   11.1
  164.      */
  165.     public function get($id 'root'$forceload false)
  166.     {
  167.         if ($id !== 'root')
  168.         {
  169.             $id = (int) $id;
  170.  
  171.             if ($id == 0)
  172.             {
  173.                 $id 'root';
  174.             }
  175.         }
  176.  
  177.         // If this $id has not been processed yet, execute the _load method
  178.         if ((!isset($this->_nodes[$id]&& !isset($this->_checkedCategories[$id])) || $forceload)
  179.         {
  180.             $this->_load($id);
  181.         }
  182.  
  183.         // If we already have a value in _nodes for this $id, then use it.
  184.         if (isset($this->_nodes[$id]))
  185.         {
  186.             return $this->_nodes[$id];
  187.         }
  188.         // If we processed this $id already and it was not valid, then return null.
  189.         elseif (isset($this->_checkedCategories[$id]))
  190.         {
  191.             return null;
  192.         }
  193.  
  194.         return false;
  195.     }
  196.  
  197.     /**
  198.      * Load method
  199.      *
  200.      * @param   integer  $id  Id of category to load
  201.      *
  202.      * @return  void 
  203.      *
  204.      * @since   11.1
  205.      */
  206.     protected function _load($id)
  207.     {
  208.         $db JFactory::getDbo();
  209.         $user JFactory::getUser();
  210.         $extension $this->_extension;
  211.  
  212.         // Record that has this $id has been checked
  213.         $this->_checkedCategories[$idtrue;
  214.  
  215.         $query $db->getQuery(true);
  216.  
  217.         // Right join with c for category
  218.         $query->select('c.id, c.asset_id, c.access, c.alias, c.checked_out, c.checked_out_time,
  219.             c.created_time, c.created_user_id, c.description, c.extension, c.hits, c.language, c.level,
  220.             c.lft, c.metadata, c.metadesc, c.metakey, c.modified_time, c.note, c.params, c.parent_id,
  221.             c.path, c.published, c.rgt, c.title, c.modified_user_id, c.version');
  222.         $case_when ' CASE WHEN ';
  223.         $case_when .= $query->charLength('c.alias''!=''0');
  224.         $case_when .= ' THEN ';
  225.         $c_id $query->castAsChar('c.id');
  226.         $case_when .= $query->concatenate(array($c_id'c.alias')':');
  227.         $case_when .= ' ELSE ';
  228.         $case_when .= $c_id ' END as slug';
  229.         $query->select($case_when)
  230.             ->from('#__categories as c')
  231.             ->where('(c.extension=' $db->quote($extension' OR c.extension=' $db->quote('system'')');
  232.  
  233.         if ($this->_options['access'])
  234.         {
  235.             $query->where('c.access IN (' implode(','$user->getAuthorisedViewLevels()) ')');
  236.         }
  237.  
  238.         if ($this->_options['published'== 1)
  239.         {
  240.             $query->where('c.published = 1');
  241.         }
  242.  
  243.         $query->order('c.lft');
  244.  
  245.         // Note: s for selected id
  246.         if ($id != 'root')
  247.         {
  248.             // Get the selected category
  249.             $query->join('LEFT''#__categories AS s ON (s.lft <= c.lft AND s.rgt >= c.rgt) OR (s.lft > c.lft AND s.rgt < c.rgt)')
  250.                 ->where('s.id=' . (int) $id);
  251.         }
  252.  
  253.         $subQuery ' (SELECT cat.id as id FROM #__categories AS cat JOIN #__categories AS parent ' .
  254.             'ON cat.lft BETWEEN parent.lft AND parent.rgt WHERE parent.extension = ' $db->quote($extension.
  255.             ' AND parent.published != 1 GROUP BY cat.id) ';
  256.         $query->join('LEFT'$subQuery 'AS badcats ON badcats.id = c.id')
  257.             ->where('badcats.id is null');
  258.  
  259.         // Note: i for item
  260.         if (isset($this->_options['countItems']&& $this->_options['countItems'== 1)
  261.         {
  262.             if ($this->_options['published'== 1)
  263.             {
  264.                 $query->join(
  265.                     'LEFT',
  266.                     $db->quoteName($this->_table' AS i ON i.' $db->quoteName($this->_field' = c.id AND i.' $this->_statefield . ' = 1'
  267.                 );
  268.             }
  269.             else
  270.             {
  271.                 $query->join('LEFT'$db->quoteName($this->_table' AS i ON i.' $db->quoteName($this->_field' = c.id');
  272.             }
  273.  
  274.             $query->select('COUNT(i.' $db->quoteName($this->_key') AS numitems');
  275.         }
  276.  
  277.         // Group by
  278.         $query->group(
  279.             'c.id, c.asset_id, c.access, c.alias, c.checked_out, c.checked_out_time,
  280.              c.created_time, c.created_user_id, c.description, c.extension, c.hits, c.language, c.level,
  281.              c.lft, c.metadata, c.metadesc, c.metakey, c.modified_time, c.note, c.params, c.parent_id,
  282.              c.path, c.published, c.rgt, c.title, c.modified_user_id, c.version'
  283.         );
  284.  
  285.         // Get the results
  286.         $db->setQuery($query);
  287.         $results $db->loadObjectList('id');
  288.         $childrenLoaded false;
  289.  
  290.         if (count($results))
  291.         {
  292.             // Foreach categories
  293.             foreach ($results as $result)
  294.             {
  295.                 // Deal with root category
  296.                 if ($result->id == 1)
  297.                 {
  298.                     $result->id 'root';
  299.                 }
  300.  
  301.                 // Deal with parent_id
  302.                 if ($result->parent_id == 1)
  303.                 {
  304.                     $result->parent_id 'root';
  305.                 }
  306.  
  307.                 // Create the node
  308.                 if (!isset($this->_nodes[$result->id]))
  309.                 {
  310.                     // Create the JCategoryNode and add to _nodes
  311.                     $this->_nodes[$result->idnew JCategoryNode($result$this);
  312.  
  313.                     // If this is not root and if the current node's parent is in the list or the current node parent is 0
  314.                     if ($result->id != 'root' && (isset($this->_nodes[$result->parent_id]|| $result->parent_id == 1))
  315.                     {
  316.                         // Compute relationship between node and its parent - set the parent in the _nodes field
  317.                         $this->_nodes[$result->id]->setParent($this->_nodes[$result->parent_id]);
  318.                     }
  319.  
  320.                     // If the node's parent id is not in the _nodes list and the node is not root (doesn't have parent_id == 0),
  321.                     // then remove the node from the list
  322.                     if (!(isset($this->_nodes[$result->parent_id]|| $result->parent_id == 0))
  323.                     {
  324.                         unset($this->_nodes[$result->id]);
  325.                         continue;
  326.                     }
  327.  
  328.                     if ($result->id == $id || $childrenLoaded)
  329.                     {
  330.                         $this->_nodes[$result->id]->setAllLoaded();
  331.                         $childrenLoaded true;
  332.                     }
  333.                 }
  334.                 elseif ($result->id == $id || $childrenLoaded)
  335.                 {
  336.                     // Create the JCategoryNode
  337.                     $this->_nodes[$result->idnew JCategoryNode($result$this);
  338.  
  339.                     if ($result->id != 'root' && (isset($this->_nodes[$result->parent_id]|| $result->parent_id))
  340.                     {
  341.                         // Compute relationship between node and its parent
  342.                         $this->_nodes[$result->id]->setParent($this->_nodes[$result->parent_id]);
  343.                     }
  344.  
  345.                     if (!isset($this->_nodes[$result->parent_id]))
  346.                     {
  347.                         unset($this->_nodes[$result->id]);
  348.                         continue;
  349.                     }
  350.  
  351.                     if ($result->id == $id || $childrenLoaded)
  352.                     {
  353.                         $this->_nodes[$result->id]->setAllLoaded();
  354.                         $childrenLoaded true;
  355.                     }
  356.                 }
  357.             }
  358.         }
  359.         else
  360.         {
  361.             $this->_nodes[$idnull;
  362.         }
  363.     }
  364. }
  365.  
  366. /**
  367.  * Helper class to load Categorytree
  368.  *
  369.  * @package     Joomla.Legacy
  370.  * @subpackage  Categories
  371.  * @since       11.1
  372.  */
  373. class JCategoryNode extends JObject
  374. {
  375.     /**
  376.      * Primary key
  377.      *
  378.      * @var    integer 
  379.      * @since  11.1
  380.      */
  381.     public $id = null;
  382.  
  383.     /**
  384.      * The id of the category in the asset table
  385.      *
  386.      * @var    integer 
  387.      * @since  11.1
  388.      */
  389.     public $asset_id = null;
  390.  
  391.     /**
  392.      * The id of the parent of category in the asset table, 0 for category root
  393.      *
  394.      * @var    integer 
  395.      * @since  11.1
  396.      */
  397.     public $parent_id = null;
  398.  
  399.     /**
  400.      * The lft value for this category in the category tree
  401.      *
  402.      * @var    integer 
  403.      * @since  11.1
  404.      */
  405.     public $lft = null;
  406.  
  407.     /**
  408.      * The rgt value for this category in the category tree
  409.      *
  410.      * @var    integer 
  411.      * @since  11.1
  412.      */
  413.     public $rgt = null;
  414.  
  415.     /**
  416.      * The depth of this category's position in the category tree
  417.      *
  418.      * @var    integer 
  419.      * @since  11.1
  420.      */
  421.     public $level = null;
  422.  
  423.     /**
  424.      * The extension this category is associated with
  425.      *
  426.      * @var    integer 
  427.      * @since  11.1
  428.      */
  429.     public $extension = null;
  430.  
  431.     /**
  432.      * The menu title for the category (a short name)
  433.      *
  434.      * @var    string 
  435.      * @since  11.1
  436.      */
  437.     public $title = null;
  438.  
  439.     /**
  440.      * The the alias for the category
  441.      *
  442.      * @var    string 
  443.      * @since  11.1
  444.      */
  445.     public $alias = null;
  446.  
  447.     /**
  448.      * Description of the category.
  449.      *
  450.      * @var    string 
  451.      * @since  11.1
  452.      */
  453.     public $description = null;
  454.  
  455.     /**
  456.      * The publication status of the category
  457.      *
  458.      * @var    boolean 
  459.      * @since  11.1
  460.      */
  461.     public $published = null;
  462.  
  463.     /**
  464.      * Whether the category is or is not checked out
  465.      *
  466.      * @var    boolean 
  467.      * @since  11.1
  468.      */
  469.     public $checked_out = 0;
  470.  
  471.     /**
  472.      * The time at which the category was checked out
  473.      *
  474.      * @var    string 
  475.      * @since  11.1
  476.      */
  477.     public $checked_out_time = 0;
  478.  
  479.     /**
  480.      * Access level for the category
  481.      *
  482.      * @var    integer 
  483.      * @since  11.1
  484.      */
  485.     public $access = null;
  486.  
  487.     /**
  488.      * JSON string of parameters
  489.      *
  490.      * @var    string 
  491.      * @since  11.1
  492.      */
  493.     public $params = null;
  494.  
  495.     /**
  496.      * Metadata description
  497.      *
  498.      * @var    string 
  499.      * @since  11.1
  500.      */
  501.     public $metadesc = null;
  502.  
  503.     /**
  504.      * Key words for meta data
  505.      *
  506.      * @var    string 
  507.      * @since  11.1
  508.      */
  509.     public $metakey = null;
  510.  
  511.     /**
  512.      * JSON string of other meta data
  513.      *
  514.      * @var    string 
  515.      * @since  11.1
  516.      */
  517.     public $metadata = null;
  518.  
  519.     /**
  520.      * The ID of the user who created the category
  521.      *
  522.      * @var    integer 
  523.      * @since  11.1
  524.      */
  525.     public $created_user_id = null;
  526.  
  527.     /**
  528.      * The time at which the category was created
  529.      *
  530.      * @var    string 
  531.      * @since  11.1
  532.      */
  533.     public $created_time = null;
  534.  
  535.     /**
  536.      * The ID of the user who last modified the category
  537.      *
  538.      * @var    integer 
  539.      * @since  11.1
  540.      */
  541.     public $modified_user_id = null;
  542.  
  543.     /**
  544.      * The time at which the category was modified
  545.      *
  546.      * @var    string 
  547.      * @since  11.1
  548.      */
  549.     public $modified_time = null;
  550.  
  551.     /**
  552.      * Nmber of times the category has been viewed
  553.      *
  554.      * @var    integer 
  555.      * @since  11.1
  556.      */
  557.     public $hits = null;
  558.  
  559.     /**
  560.      * The language for the category in xx-XX format
  561.      *
  562.      * @var    string 
  563.      * @since  11.1
  564.      */
  565.     public $language = null;
  566.  
  567.     /**
  568.      * Number of items in this category or descendants of this category
  569.      *
  570.      * @var    integer 
  571.      * @since  11.1
  572.      */
  573.     public $numitems = null;
  574.  
  575.     /**
  576.      * Number of children items
  577.      *
  578.      * @var    integer 
  579.      * @since  11.1
  580.      */
  581.     public $childrennumitems = null;
  582.  
  583.     /**
  584.      * Slug fo the category (used in URL)
  585.      *
  586.      * @var    string 
  587.      * @since  11.1
  588.      */
  589.     public $slug = null;
  590.  
  591.     /**
  592.      * Array of  assets
  593.      *
  594.      * @var    array 
  595.      * @since  11.1
  596.      */
  597.     public $assets = null;
  598.  
  599.     /**
  600.      * Parent Category object
  601.      *
  602.      * @var    object 
  603.      * @since  11.1
  604.      */
  605.     protected $_parent = null;
  606.  
  607.     /**
  608.      * @var Array of Children
  609.      * @since  11.1
  610.      */
  611.     protected $_children = array();
  612.  
  613.     /**
  614.      * Path from root to this category
  615.      *
  616.      * @var    array 
  617.      * @since  11.1
  618.      */
  619.     protected $_path = array();
  620.  
  621.     /**
  622.      * Category left of this one
  623.      *
  624.      * @var    integer 
  625.      * @since  11.1
  626.      */
  627.     protected $_leftSibling = null;
  628.  
  629.     /**
  630.      * Category right of this one
  631.      *
  632.      * @var 
  633.      * @since  11.1
  634.      */
  635.     protected $_rightSibling = null;
  636.  
  637.     /**
  638.      * true if all children have been loaded
  639.      *
  640.      * @var boolean 
  641.      * @since  11.1
  642.      */
  643.     protected $_allChildrenloaded = false;
  644.  
  645.     /**
  646.      * Constructor of this tree
  647.      *
  648.      * @var 
  649.      * @since  11.1
  650.      */
  651.     protected $_constructor = null;
  652.  
  653.     /**
  654.      * Class constructor
  655.      *
  656.      * @param   array          $category     The category data.
  657.      * @param   JCategoryNode  $constructor  The tree constructor.
  658.      *
  659.      * @since   11.1
  660.      */
  661.     public function __construct($category null$constructor null)
  662.     {
  663.         if ($category)
  664.         {
  665.             $this->setProperties($category);
  666.             if ($constructor)
  667.             {
  668.                 $this->_constructor = $constructor;
  669.             }
  670.  
  671.             return true;
  672.         }
  673.  
  674.         return false;
  675.     }
  676.  
  677.     /**
  678.      * Set the parent of this category
  679.      *
  680.      * If the category already has a parent, the link is unset
  681.      *
  682.      * @param   mixed  $parent  JCategoryNode for the parent to be set or null
  683.      *
  684.      * @return  void 
  685.      *
  686.      * @since   11.1
  687.      */
  688.     public function setParent($parent)
  689.     {
  690.         if ($parent instanceof JCategoryNode || is_null($parent))
  691.         {
  692.             if (!is_null($this->_parent))
  693.             {
  694.                 $key array_search($this$this->_parent->_children);
  695.                 unset($this->_parent->_children[$key]);
  696.             }
  697.  
  698.             if (!is_null($parent))
  699.             {
  700.                 $parent->_children[$this;
  701.             }
  702.  
  703.             $this->_parent = $parent;
  704.  
  705.             if ($this->id != 'root')
  706.             {
  707.                 if ($this->parent_id != 1)
  708.                 {
  709.                     $this->_path = $parent->getPath();
  710.                 }
  711.                 $this->_path[$this->id . ':' $this->alias;
  712.             }
  713.  
  714.             if (count($parent->_children1)
  715.             {
  716.                 end($parent->_children);
  717.                 $this->_leftSibling = prev($parent->_children);
  718.                 $this->_leftSibling->_rightsibling $this;
  719.             }
  720.         }
  721.     }
  722.  
  723.     /**
  724.      * Add child to this node
  725.      *
  726.      * If the child already has a parent, the link is unset
  727.      *
  728.      * @param   JCategoryNode  $child  The child to be added.
  729.      *
  730.      * @return  void 
  731.      *
  732.      * @since   11.1
  733.      */
  734.     public function addChild($child)
  735.     {
  736.         if ($child instanceof JCategoryNode)
  737.         {
  738.             $child->setParent($this);
  739.         }
  740.     }
  741.  
  742.     /**
  743.      * Remove a specific child
  744.      *
  745.      * @param   integer  $id  ID of a category
  746.      *
  747.      * @return  void 
  748.      *
  749.      * @since   11.1
  750.      */
  751.     public function removeChild($id)
  752.     {
  753.         $key array_search($this$this->_parent->_children);
  754.         unset($this->_parent->_children[$key]);
  755.     }
  756.  
  757.     /**
  758.      * Get the children of this node
  759.      *
  760.      * @param   boolean  $recursive  False by default
  761.      *
  762.      * @return  array  The children
  763.      *
  764.      * @since   11.1
  765.      */
  766.     public function &getChildren($recursive false)
  767.     {
  768.         if (!$this->_allChildrenloaded)
  769.         {
  770.             $temp $this->_constructor->get($this->idtrue);
  771.             if ($temp)
  772.             {
  773.                 $this->_children = $temp->getChildren();
  774.                 $this->_leftSibling = $temp->getSibling(false);
  775.                 $this->_rightSibling = $temp->getSibling(true);
  776.                 $this->setAllLoaded();
  777.             }
  778.         }
  779.  
  780.         if ($recursive)
  781.         {
  782.             $items array();
  783.             foreach ($this->_children as $child)
  784.             {
  785.                 $items[$child;
  786.                 $items array_merge($items$child->getChildren(true));
  787.             }
  788.             return $items;
  789.         }
  790.  
  791.         return $this->_children;
  792.     }
  793.  
  794.     /**
  795.      * Get the parent of this node
  796.      *
  797.      * @return  mixed  JCategoryNode or null
  798.      *
  799.      * @since   11.1
  800.      */
  801.     public function getParent()
  802.     {
  803.         return $this->_parent;
  804.     }
  805.  
  806.     /**
  807.      * Test if this node has children
  808.      *
  809.      * @return  boolean  True if there is a child
  810.      *
  811.      * @since   11.1
  812.      */
  813.     public function hasChildren()
  814.     {
  815.         return count($this->_children);
  816.     }
  817.  
  818.     /**
  819.      * Test if this node has a parent
  820.      *
  821.      * @return  boolean    True if there is a parent
  822.      *
  823.      * @since   11.1
  824.      */
  825.     public function hasParent()
  826.     {
  827.         return $this->getParent(!= null;
  828.     }
  829.  
  830.     /**
  831.      * Function to set the left or right sibling of a category
  832.      *
  833.      * @param   JCategoryNode  $sibling  JCategoryNode object for the sibling
  834.      * @param   boolean        $right    If set to false, the sibling is the left one
  835.      *
  836.      * @return  void 
  837.      *
  838.      * @since   11.1
  839.      */
  840.     public function setSibling($sibling$right true)
  841.     {
  842.         if ($right)
  843.         {
  844.             $this->_rightSibling = $sibling;
  845.         }
  846.         else
  847.         {
  848.             $this->_leftSibling = $sibling;
  849.         }
  850.     }
  851.  
  852.     /**
  853.      * Returns the right or left sibling of a category
  854.      *
  855.      * @param   boolean  $right  If set to false, returns the left sibling
  856.      *
  857.      * @return  mixed  JCategoryNode object with the sibling information or
  858.      *                  NULL if there is no sibling on that side.
  859.      *
  860.      * @since          11.1
  861.      */
  862.     public function getSibling($right true)
  863.     {
  864.         if (!$this->_allChildrenloaded)
  865.         {
  866.             $temp $this->_constructor->get($this->idtrue);
  867.             $this->_children = $temp->getChildren();
  868.             $this->_leftSibling = $temp->getSibling(false);
  869.             $this->_rightSibling = $temp->getSibling(true);
  870.             $this->setAllLoaded();
  871.         }
  872.  
  873.         if ($right)
  874.         {
  875.             return $this->_rightSibling;
  876.         }
  877.         else
  878.         {
  879.             return $this->_leftSibling;
  880.         }
  881.     }
  882.  
  883.     /**
  884.      * Returns the category parameters
  885.      *
  886.      * @return  JRegistry 
  887.      *
  888.      * @since   11.1
  889.      */
  890.     public function getParams()
  891.     {
  892.         if (!($this->params instanceof JRegistry))
  893.         {
  894.             $temp new JRegistry;
  895.             $temp->loadString($this->params);
  896.             $this->params = $temp;
  897.         }
  898.  
  899.         return $this->params;
  900.     }
  901.  
  902.     /**
  903.      * Returns the category metadata
  904.      *
  905.      * @return  JRegistry  A JRegistry object containing the metadata
  906.      *
  907.      * @since   11.1
  908.      */
  909.     public function getMetadata()
  910.     {
  911.         if (!($this->metadata instanceof JRegistry))
  912.         {
  913.             $temp new JRegistry;
  914.             $temp->loadString($this->metadata);
  915.             $this->metadata = $temp;
  916.         }
  917.  
  918.         return $this->metadata;
  919.     }
  920.  
  921.     /**
  922.      * Returns the category path to the root category
  923.      *
  924.      * @return  array 
  925.      *
  926.      * @since   11.1
  927.      */
  928.     public function getPath()
  929.     {
  930.         return $this->_path;
  931.     }
  932.  
  933.     /**
  934.      * Returns the user that created the category
  935.      *
  936.      * @param   boolean  $modified_user  Returns the modified_user when set to true
  937.      *
  938.      * @return  JUser  A JUser object containing a userid
  939.      *
  940.      * @since   11.1
  941.      */
  942.     public function getAuthor($modified_user false)
  943.     {
  944.         if ($modified_user)
  945.         {
  946.             return JFactory::getUser($this->modified_user_id);
  947.         }
  948.  
  949.         return JFactory::getUser($this->created_user_id);
  950.     }
  951.  
  952.     /**
  953.      * Set to load all children
  954.      *
  955.      * @return  void 
  956.      *
  957.      * @since 11.1
  958.      */
  959.     public function setAllLoaded()
  960.     {
  961.         $this->_allChildrenloaded = true;
  962.         foreach ($this->_children as $child)
  963.         {
  964.             $child->setAllLoaded();
  965.         }
  966.     }
  967.  
  968.     /**
  969.      * Returns the number of items.
  970.      *
  971.      * @param   boolean  $recursive  If false number of children, if true number of descendants
  972.      *
  973.      * @return  integer  Number of children or descendants
  974.      *
  975.      * @since 11.1
  976.      */
  977.     public function getNumItems($recursive false)
  978.     {
  979.         if ($recursive)
  980.         {
  981.             $count $this->numitems;
  982.  
  983.             foreach ($this->getChildren(as $child)
  984.             {
  985.                 $count $count $child->getNumItems(true);
  986.             }
  987.  
  988.             return $count;
  989.         }
  990.  
  991.         return $this->numitems;
  992.     }
  993. }

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