[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Joomla! Content Management System 5 * 6 * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> 7 * @license GNU General Public License version 2 or later; see LICENSE.txt 8 */ 9 10 namespace Joomla\CMS\Categories; 11 12 use Joomla\CMS\Factory; 13 use Joomla\CMS\Object\CMSObject; 14 use Joomla\CMS\Tree\NodeInterface; 15 use Joomla\CMS\Tree\NodeTrait; 16 use Joomla\Registry\Registry; 17 18 // phpcs:disable PSR1.Files.SideEffects 19 \defined('JPATH_PLATFORM') or die; 20 // phpcs:enable PSR1.Files.SideEffects 21 22 /** 23 * Helper class to load Categorytree 24 * 25 * @since 1.6 26 */ 27 class CategoryNode extends CMSObject implements NodeInterface 28 { 29 use NodeTrait; 30 31 /** 32 * Primary key 33 * 34 * @var integer 35 * @since 1.6 36 */ 37 public $id = null; 38 39 /** 40 * The id of the category in the asset table 41 * 42 * @var integer 43 * @since 1.6 44 */ 45 public $asset_id = null; 46 47 /** 48 * The id of the parent of category in the asset table, 0 for category root 49 * 50 * @var integer 51 * @since 1.6 52 */ 53 public $parent_id = null; 54 55 /** 56 * The lft value for this category in the category tree 57 * 58 * @var integer 59 * @since 1.6 60 */ 61 public $lft = null; 62 63 /** 64 * The rgt value for this category in the category tree 65 * 66 * @var integer 67 * @since 1.6 68 */ 69 public $rgt = null; 70 71 /** 72 * The depth of this category's position in the category tree 73 * 74 * @var integer 75 * @since 1.6 76 */ 77 public $level = null; 78 79 /** 80 * The extension this category is associated with 81 * 82 * @var integer 83 * @since 1.6 84 */ 85 public $extension = null; 86 87 /** 88 * The menu title for the category (a short name) 89 * 90 * @var string 91 * @since 1.6 92 */ 93 public $title = null; 94 95 /** 96 * The the alias for the category 97 * 98 * @var string 99 * @since 1.6 100 */ 101 public $alias = null; 102 103 /** 104 * Description of the category. 105 * 106 * @var string 107 * @since 1.6 108 */ 109 public $description = null; 110 111 /** 112 * The publication status of the category 113 * 114 * @var boolean 115 * @since 1.6 116 */ 117 public $published = null; 118 119 /** 120 * Whether the category is or is not checked out 121 * 122 * @var boolean 123 * @since 1.6 124 */ 125 public $checked_out = null; 126 127 /** 128 * The time at which the category was checked out 129 * 130 * @var string 131 * @since 1.6 132 */ 133 public $checked_out_time = null; 134 135 /** 136 * Access level for the category 137 * 138 * @var integer 139 * @since 1.6 140 */ 141 public $access = null; 142 143 /** 144 * JSON string of parameters 145 * 146 * @var string 147 * @since 1.6 148 */ 149 public $params = null; 150 151 /** 152 * Metadata description 153 * 154 * @var string 155 * @since 1.6 156 */ 157 public $metadesc = null; 158 159 /** 160 * Key words for metadata 161 * 162 * @var string 163 * @since 1.6 164 */ 165 public $metakey = null; 166 167 /** 168 * JSON string of other metadata 169 * 170 * @var string 171 * @since 1.6 172 */ 173 public $metadata = null; 174 175 /** 176 * The ID of the user who created the category 177 * 178 * @var integer 179 * @since 1.6 180 */ 181 public $created_user_id = null; 182 183 /** 184 * The time at which the category was created 185 * 186 * @var string 187 * @since 1.6 188 */ 189 public $created_time = null; 190 191 /** 192 * The ID of the user who last modified the category 193 * 194 * @var integer 195 * @since 1.6 196 */ 197 public $modified_user_id = null; 198 199 /** 200 * The time at which the category was modified 201 * 202 * @var string 203 * @since 1.6 204 */ 205 public $modified_time = null; 206 207 /** 208 * Number of times the category has been viewed 209 * 210 * @var integer 211 * @since 1.6 212 */ 213 public $hits = null; 214 215 /** 216 * The language for the category in xx-XX format 217 * 218 * @var string 219 * @since 1.6 220 */ 221 public $language = null; 222 223 /** 224 * Number of items in this category or descendants of this category 225 * 226 * @var integer 227 * @since 1.6 228 */ 229 public $numitems = null; 230 231 /** 232 * Number of children items 233 * 234 * @var integer 235 * @since 1.6 236 */ 237 public $childrennumitems = null; 238 239 /** 240 * Slug for the category (used in URL) 241 * 242 * @var string 243 * @since 1.6 244 */ 245 public $slug = null; 246 247 /** 248 * Array of assets 249 * 250 * @var array 251 * @since 1.6 252 */ 253 public $assets = null; 254 255 /** 256 * Path from root to this category 257 * 258 * @var array 259 * @since 1.6 260 */ 261 protected $_path = array(); 262 263 /** 264 * Flag if all children have been loaded 265 * 266 * @var boolean 267 * @since 1.6 268 */ 269 protected $_allChildrenloaded = false; 270 271 /** 272 * Constructor of this tree 273 * 274 * @var Categories 275 * @since 1.6 276 */ 277 protected $_constructor = null; 278 279 /** 280 * Class constructor 281 * 282 * @param array $category The category data. 283 * @param Categories $constructor The tree constructor. 284 * 285 * @since 1.6 286 */ 287 public function __construct($category = null, $constructor = null) 288 { 289 if ($category) { 290 $this->setProperties($category); 291 292 if ($constructor) { 293 $this->_constructor = $constructor; 294 } 295 296 return true; 297 } 298 299 return false; 300 } 301 302 /** 303 * Set the parent of this category 304 * 305 * If the category already has a parent, the link is unset 306 * 307 * @param CategoryNode|null $parent CategoryNode for the parent to be set or null 308 * 309 * @return void 310 * 311 * @since 1.6 312 */ 313 public function setParent(NodeInterface $parent) 314 { 315 if (!\is_null($this->_parent)) { 316 $key = array_search($this, $this->_parent->_children); 317 unset($this->_parent->_children[$key]); 318 } 319 320 $this->_parent = $parent; 321 322 $this->_parent->_children[] = & $this; 323 324 if (\count($this->_parent->_children) > 1) { 325 end($this->_parent->_children); 326 $this->_leftSibling = prev($this->_parent->_children); 327 $this->_leftSibling->_rightsibling = & $this; 328 } 329 330 if ($this->parent_id != 1) { 331 $this->_path = $parent->getPath(); 332 } 333 334 $this->_path[$this->id] = $this->id . ':' . $this->alias; 335 } 336 337 /** 338 * Get the children of this node 339 * 340 * @param boolean $recursive False by default 341 * 342 * @return CategoryNode[] The children 343 * 344 * @since 1.6 345 */ 346 public function &getChildren($recursive = false) 347 { 348 if (!$this->_allChildrenloaded) { 349 $temp = $this->_constructor->get($this->id, true); 350 351 if ($temp) { 352 $this->_children = $temp->getChildren(); 353 $this->_leftSibling = $temp->getSibling(false); 354 $this->_rightSibling = $temp->getSibling(true); 355 $this->setAllLoaded(); 356 } 357 } 358 359 if ($recursive) { 360 $items = array(); 361 362 foreach ($this->_children as $child) { 363 $items[] = $child; 364 $items = array_merge($items, $child->getChildren(true)); 365 } 366 367 return $items; 368 } 369 370 return $this->_children; 371 } 372 373 /** 374 * Returns the right or left sibling of a category 375 * 376 * @param boolean $right If set to false, returns the left sibling 377 * 378 * @return CategoryNode|null CategoryNode object with the sibling information or null if there is no sibling on that side. 379 * 380 * @since 1.6 381 */ 382 public function getSibling($right = true) 383 { 384 if (!$this->_allChildrenloaded) { 385 $temp = $this->_constructor->get($this->id, true); 386 $this->_children = $temp->getChildren(); 387 $this->_leftSibling = $temp->getSibling(false); 388 $this->_rightSibling = $temp->getSibling(true); 389 $this->setAllLoaded(); 390 } 391 392 if ($right) { 393 return $this->_rightSibling; 394 } else { 395 return $this->_leftSibling; 396 } 397 } 398 399 /** 400 * Returns the category parameters 401 * 402 * @return Registry 403 * 404 * @since 1.6 405 */ 406 public function getParams() 407 { 408 if (!($this->params instanceof Registry)) { 409 $this->params = new Registry($this->params); 410 } 411 412 return $this->params; 413 } 414 415 /** 416 * Returns the category metadata 417 * 418 * @return Registry A Registry object containing the metadata 419 * 420 * @since 1.6 421 */ 422 public function getMetadata() 423 { 424 if (!($this->metadata instanceof Registry)) { 425 $this->metadata = new Registry($this->metadata); 426 } 427 428 return $this->metadata; 429 } 430 431 /** 432 * Returns the category path to the root category 433 * 434 * @return array 435 * 436 * @since 1.6 437 */ 438 public function getPath() 439 { 440 return $this->_path; 441 } 442 443 /** 444 * Returns the user that created the category 445 * 446 * @param boolean $modifiedUser Returns the modified_user when set to true 447 * 448 * @return \Joomla\CMS\User\User A User object containing a userid 449 * 450 * @since 1.6 451 */ 452 public function getAuthor($modifiedUser = false) 453 { 454 if ($modifiedUser) { 455 return Factory::getUser($this->modified_user_id); 456 } 457 458 return Factory::getUser($this->created_user_id); 459 } 460 461 /** 462 * Set to load all children 463 * 464 * @return void 465 * 466 * @since 1.6 467 */ 468 public function setAllLoaded() 469 { 470 $this->_allChildrenloaded = true; 471 472 foreach ($this->_children as $child) { 473 $child->setAllLoaded(); 474 } 475 } 476 477 /** 478 * Returns the number of items. 479 * 480 * @param boolean $recursive If false number of children, if true number of descendants 481 * 482 * @return integer Number of children or descendants 483 * 484 * @since 1.6 485 */ 486 public function getNumItems($recursive = false) 487 { 488 if ($recursive) { 489 $count = $this->numitems; 490 491 foreach ($this->getChildren() as $child) { 492 $count = $count + $child->getNumItems(true); 493 } 494 495 return $count; 496 } 497 498 return $this->numitems; 499 } 500 }
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 |