[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Site 5 * @subpackage com_newsfeeds 6 * 7 * @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 */ 10 11 namespace Joomla\Component\Newsfeeds\Site\Model; 12 13 use Joomla\CMS\Categories\Categories; 14 use Joomla\CMS\Categories\CategoryNode; 15 use Joomla\CMS\Factory; 16 use Joomla\CMS\MVC\Model\ListModel; 17 use Joomla\Registry\Registry; 18 19 // phpcs:disable PSR1.Files.SideEffects 20 \defined('_JEXEC') or die; 21 // phpcs:enable PSR1.Files.SideEffects 22 23 /** 24 * This models supports retrieving lists of newsfeed categories. 25 * 26 * @since 1.6 27 */ 28 class CategoriesModel extends ListModel 29 { 30 /** 31 * Model context string. 32 * 33 * @var string 34 */ 35 public $_context = 'com_newsfeeds.categories'; 36 37 /** 38 * The category context (allows other extensions to derived from this model). 39 * 40 * @var string 41 */ 42 protected $_extension = 'com_newsfeeds'; 43 44 /** 45 * Parent category of the current one 46 * 47 * @var CategoryNode|null 48 */ 49 private $_parent = null; 50 51 /** 52 * Array of child-categories 53 * 54 * @var CategoryNode[]|null 55 */ 56 private $_items = null; 57 58 /** 59 * Method to auto-populate the model state. 60 * 61 * Note. Calling getState in this method will result in recursion. 62 * 63 * @param string $ordering An optional ordering field 64 * @param string $direction An optional direction [asc|desc] 65 * 66 * @return void 67 * 68 * @throws \Exception 69 * 70 * @since 1.6 71 */ 72 protected function populateState($ordering = null, $direction = null) 73 { 74 $app = Factory::getApplication(); 75 $this->setState('filter.extension', $this->_extension); 76 77 // Get the parent id if defined. 78 $parentId = $app->input->getInt('id'); 79 $this->setState('filter.parentId', $parentId); 80 81 $params = $app->getParams(); 82 $this->setState('params', $params); 83 84 $this->setState('filter.published', 1); 85 $this->setState('filter.access', true); 86 } 87 88 /** 89 * Method to get a store id based on model configuration state. 90 * 91 * This is necessary because the model is used by the component and 92 * different modules that might need different sets of data or different 93 * ordering requirements. 94 * 95 * @param string $id A prefix for the store id. 96 * 97 * @return string A store id. 98 */ 99 protected function getStoreId($id = '') 100 { 101 // Compile the store id. 102 $id .= ':' . $this->getState('filter.extension'); 103 $id .= ':' . $this->getState('filter.published'); 104 $id .= ':' . $this->getState('filter.access'); 105 $id .= ':' . $this->getState('filter.parentId'); 106 107 return parent::getStoreId($id); 108 } 109 110 /** 111 * redefine the function and add some properties to make the styling easier 112 * 113 * @return mixed An array of data items on success, false on failure. 114 */ 115 public function getItems() 116 { 117 if ($this->_items === null) { 118 $app = Factory::getApplication(); 119 $menu = $app->getMenu(); 120 $active = $menu->getActive(); 121 122 if ($active) { 123 $params = $active->getParams(); 124 } else { 125 $params = new Registry(); 126 } 127 128 $options = array(); 129 $options['countItems'] = $params->get('show_cat_items_cat', 1) || !$params->get('show_empty_categories_cat', 0); 130 $categories = Categories::getInstance('Newsfeeds', $options); 131 $this->_parent = $categories->get($this->getState('filter.parentId', 'root')); 132 133 if (is_object($this->_parent)) { 134 $this->_items = $this->_parent->getChildren(); 135 } else { 136 $this->_items = false; 137 } 138 } 139 140 return $this->_items; 141 } 142 143 /** 144 * get the Parent 145 * 146 * @return null 147 */ 148 public function getParent() 149 { 150 if (!is_object($this->_parent)) { 151 $this->getItems(); 152 } 153 154 return $this->_parent; 155 } 156 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |