[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Administrator 5 * @subpackage com_finder 6 * 7 * @copyright (C) 2011 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\Finder\Administrator\Indexer; 12 13 use Joomla\CMS\Component\ComponentHelper; 14 use Joomla\CMS\Tree\ImmutableNodeInterface; 15 16 // phpcs:disable PSR1.Files.SideEffects 17 \defined('_JEXEC') or die; 18 // phpcs:enable PSR1.Files.SideEffects 19 20 /** 21 * Result class for the Finder indexer package. 22 * 23 * This class uses magic __get() and __set() methods to prevent properties 24 * being added that might confuse the system. All properties not explicitly 25 * declared will be pushed into the elements array and can be accessed 26 * explicitly using the getElement() method. 27 * 28 * @since 2.5 29 */ 30 class Result implements \Serializable 31 { 32 /** 33 * An array of extra result properties. 34 * 35 * @var array 36 * @since 2.5 37 */ 38 protected $elements = array(); 39 40 /** 41 * This array tells the indexer which properties should be indexed and what 42 * weights to use for those properties. 43 * 44 * @var array 45 * @since 2.5 46 */ 47 protected $instructions = array( 48 Indexer::TITLE_CONTEXT => array('title', 'subtitle', 'id'), 49 Indexer::TEXT_CONTEXT => array('summary', 'body'), 50 Indexer::META_CONTEXT => array('meta', 'list_price', 'sale_price'), 51 Indexer::PATH_CONTEXT => array('path', 'alias'), 52 Indexer::MISC_CONTEXT => array('comments'), 53 ); 54 55 /** 56 * The indexer will use this data to create taxonomy mapping entries for 57 * the item so that it can be filtered by type, label, category, 58 * or whatever. 59 * 60 * @var array 61 * @since 2.5 62 */ 63 protected $taxonomy = array(); 64 65 /** 66 * The content URL. 67 * 68 * @var string 69 * @since 2.5 70 */ 71 public $url; 72 73 /** 74 * The content route. 75 * 76 * @var string 77 * @since 2.5 78 */ 79 public $route; 80 81 /** 82 * The content title. 83 * 84 * @var string 85 * @since 2.5 86 */ 87 public $title; 88 89 /** 90 * The content description. 91 * 92 * @var string 93 * @since 2.5 94 */ 95 public $description; 96 97 /** 98 * The published state of the result. 99 * 100 * @var integer 101 * @since 2.5 102 */ 103 public $published; 104 105 /** 106 * The content published state. 107 * 108 * @var integer 109 * @since 2.5 110 */ 111 public $state; 112 113 /** 114 * The content access level. 115 * 116 * @var integer 117 * @since 2.5 118 */ 119 public $access; 120 121 /** 122 * The content language. 123 * 124 * @var string 125 * @since 2.5 126 */ 127 public $language = '*'; 128 129 /** 130 * The publishing start date. 131 * 132 * @var string 133 * @since 2.5 134 */ 135 public $publish_start_date; 136 137 /** 138 * The publishing end date. 139 * 140 * @var string 141 * @since 2.5 142 */ 143 public $publish_end_date; 144 145 /** 146 * The generic start date. 147 * 148 * @var string 149 * @since 2.5 150 */ 151 public $start_date; 152 153 /** 154 * The generic end date. 155 * 156 * @var string 157 * @since 2.5 158 */ 159 public $end_date; 160 161 /** 162 * The item list price. 163 * 164 * @var mixed 165 * @since 2.5 166 */ 167 public $list_price; 168 169 /** 170 * The item sale price. 171 * 172 * @var mixed 173 * @since 2.5 174 */ 175 public $sale_price; 176 177 /** 178 * The content type id. This is set by the adapter. 179 * 180 * @var integer 181 * @since 2.5 182 */ 183 public $type_id; 184 185 /** 186 * The default language for content. 187 * 188 * @var string 189 * @since 3.0.2 190 */ 191 public $defaultLanguage; 192 193 /** 194 * Constructor 195 * 196 * @since 3.0.3 197 */ 198 public function __construct() 199 { 200 $this->defaultLanguage = ComponentHelper::getParams('com_languages')->get('site', 'en-GB'); 201 } 202 203 /** 204 * The magic set method is used to push additional values into the elements 205 * array in order to preserve the cleanliness of the object. 206 * 207 * @param string $name The name of the element. 208 * @param mixed $value The value of the element. 209 * 210 * @return void 211 * 212 * @since 2.5 213 */ 214 public function __set($name, $value) 215 { 216 $this->setElement($name, $value); 217 } 218 219 /** 220 * The magic get method is used to retrieve additional element values from the elements array. 221 * 222 * @param string $name The name of the element. 223 * 224 * @return mixed The value of the element if set, null otherwise. 225 * 226 * @since 2.5 227 */ 228 public function __get($name) 229 { 230 return $this->getElement($name); 231 } 232 233 /** 234 * The magic isset method is used to check the state of additional element values in the elements array. 235 * 236 * @param string $name The name of the element. 237 * 238 * @return boolean True if set, false otherwise. 239 * 240 * @since 2.5 241 */ 242 public function __isset($name) 243 { 244 return isset($this->elements[$name]); 245 } 246 247 /** 248 * The magic unset method is used to unset additional element values in the elements array. 249 * 250 * @param string $name The name of the element. 251 * 252 * @return void 253 * 254 * @since 2.5 255 */ 256 public function __unset($name) 257 { 258 unset($this->elements[$name]); 259 } 260 261 /** 262 * Method to retrieve additional element values from the elements array. 263 * 264 * @param string $name The name of the element. 265 * 266 * @return mixed The value of the element if set, null otherwise. 267 * 268 * @since 2.5 269 */ 270 public function getElement($name) 271 { 272 // Get the element value if set. 273 if (array_key_exists($name, $this->elements)) { 274 return $this->elements[$name]; 275 } 276 277 return null; 278 } 279 280 /** 281 * Method to retrieve all elements. 282 * 283 * @return array The elements 284 * 285 * @since 3.8.3 286 */ 287 public function getElements() 288 { 289 return $this->elements; 290 } 291 292 /** 293 * Method to set additional element values in the elements array. 294 * 295 * @param string $name The name of the element. 296 * @param mixed $value The value of the element. 297 * 298 * @return void 299 * 300 * @since 2.5 301 */ 302 public function setElement($name, $value) 303 { 304 $this->elements[$name] = $value; 305 } 306 307 /** 308 * Method to get all processing instructions. 309 * 310 * @return array An array of processing instructions. 311 * 312 * @since 2.5 313 */ 314 public function getInstructions() 315 { 316 return $this->instructions; 317 } 318 319 /** 320 * Method to add a processing instruction for an item property. 321 * 322 * @param string $group The group to associate the property with. 323 * @param string $property The property to process. 324 * 325 * @return void 326 * 327 * @since 2.5 328 */ 329 public function addInstruction($group, $property) 330 { 331 // Check if the group exists. We can't add instructions for unknown groups. 332 // Check if the property exists in the group. 333 if (array_key_exists($group, $this->instructions) && !in_array($property, $this->instructions[$group], true)) { 334 // Add the property to the group. 335 $this->instructions[$group][] = $property; 336 } 337 } 338 339 /** 340 * Method to remove a processing instruction for an item property. 341 * 342 * @param string $group The group to associate the property with. 343 * @param string $property The property to process. 344 * 345 * @return void 346 * 347 * @since 2.5 348 */ 349 public function removeInstruction($group, $property) 350 { 351 // Check if the group exists. We can't remove instructions for unknown groups. 352 if (array_key_exists($group, $this->instructions)) { 353 // Search for the property in the group. 354 $key = array_search($property, $this->instructions[$group]); 355 356 // If the property was found, remove it. 357 if ($key !== false) { 358 unset($this->instructions[$group][$key]); 359 } 360 } 361 } 362 363 /** 364 * Method to get the taxonomy maps for an item. 365 * 366 * @param string $branch The taxonomy branch to get. [optional] 367 * 368 * @return array An array of taxonomy maps. 369 * 370 * @since 2.5 371 */ 372 public function getTaxonomy($branch = null) 373 { 374 // Get the taxonomy branch if available. 375 if ($branch !== null && isset($this->taxonomy[$branch])) { 376 return $this->taxonomy[$branch]; 377 } 378 379 return $this->taxonomy; 380 } 381 382 /** 383 * Method to add a taxonomy map for an item. 384 * 385 * @param string $branch The title of the taxonomy branch to add the node to. 386 * @param string $title The title of the taxonomy node. 387 * @param integer $state The published state of the taxonomy node. [optional] 388 * @param integer $access The access level of the taxonomy node. [optional] 389 * @param string $language The language of the taxonomy. [optional] 390 * 391 * @return void 392 * 393 * @since 2.5 394 */ 395 public function addTaxonomy($branch, $title, $state = 1, $access = 1, $language = '') 396 { 397 // Filter the input. 398 $branch = preg_replace('#[^\pL\pM\pN\p{Pi}\p{Pf}\'+-.,_]+#mui', ' ', $branch); 399 400 // Create the taxonomy node. 401 $node = new \stdClass(); 402 $node->title = $title; 403 $node->state = (int) $state; 404 $node->access = (int) $access; 405 $node->language = $language; 406 $node->nested = false; 407 408 // Add the node to the taxonomy branch. 409 $this->taxonomy[$branch][] = $node; 410 } 411 412 /** 413 * Method to add a nested taxonomy map for an item. 414 * 415 * @param string $branch The title of the taxonomy branch to add the node to. 416 * @param ImmutableNodeInterface $contentNode The node object. 417 * @param integer $state The published state of the taxonomy node. [optional] 418 * @param integer $access The access level of the taxonomy node. [optional] 419 * @param string $language The language of the taxonomy. [optional] 420 * 421 * @return void 422 * 423 * @since 4.0.0 424 */ 425 public function addNestedTaxonomy($branch, ImmutableNodeInterface $contentNode, $state = 1, $access = 1, $language = '') 426 { 427 // Filter the input. 428 $branch = preg_replace('#[^\pL\pM\pN\p{Pi}\p{Pf}\'+-.,_]+#mui', ' ', $branch); 429 430 // Create the taxonomy node. 431 $node = new \stdClass(); 432 $node->title = $contentNode->title; 433 $node->state = (int) $state; 434 $node->access = (int) $access; 435 $node->language = $language; 436 $node->nested = true; 437 $node->node = $contentNode; 438 439 // Add the node to the taxonomy branch. 440 $this->taxonomy[$branch][] = $node; 441 } 442 443 /** 444 * Method to set the item language 445 * 446 * @return void 447 * 448 * @since 3.0 449 */ 450 public function setLanguage() 451 { 452 if ($this->language == '') { 453 $this->language = $this->defaultLanguage; 454 } 455 } 456 457 /** 458 * Helper function to serialise the data of a Result object 459 * 460 * @return string The serialised data 461 * 462 * @since 4.0.0 463 */ 464 public function serialize() 465 { 466 return serialize($this->__serialize()); 467 } 468 469 /** 470 * Helper function to unserialise the data for this object 471 * 472 * @param string $serialized Serialised data to unserialise 473 * 474 * @return void 475 * 476 * @since 4.0.0 477 */ 478 public function unserialize($serialized): void 479 { 480 $this->__unserialize(unserialize($serialized)); 481 } 482 483 /** 484 * Magic method used for serializing. 485 * 486 * @since 4.1.3 487 */ 488 public function __serialize(): array 489 { 490 $taxonomy = []; 491 492 foreach ($this->taxonomy as $branch => $nodes) { 493 $taxonomy[$branch] = []; 494 495 foreach ($nodes as $node) { 496 if ($node->nested) { 497 $n = clone $node; 498 unset($n->node); 499 $taxonomy[$branch][] = $n; 500 } else { 501 $taxonomy[$branch][] = $node; 502 } 503 } 504 } 505 506 // This order must match EXACTLY the order of the $properties in the self::__unserialize method 507 return [ 508 $this->access, 509 $this->defaultLanguage, 510 $this->description, 511 $this->elements, 512 $this->end_date, 513 $this->instructions, 514 $this->language, 515 $this->list_price, 516 $this->publish_end_date, 517 $this->publish_start_date, 518 $this->published, 519 $this->route, 520 $this->sale_price, 521 $this->start_date, 522 $this->state, 523 $taxonomy, 524 $this->title, 525 $this->type_id, 526 $this->url 527 ]; 528 } 529 530 /** 531 * Magic method used for unserializing. 532 * 533 * @since 4.1.3 534 */ 535 public function __unserialize(array $serialized): void 536 { 537 // This order must match EXACTLY the order of the array in the self::__serialize method 538 $properties = [ 539 'access', 540 'defaultLanguage', 541 'description', 542 'elements', 543 'end_date', 544 'instructions', 545 'language', 546 'list_price', 547 'publish_end_date', 548 'publish_start_date', 549 'published', 550 'route', 551 'sale_price', 552 'start_date', 553 'state', 554 'taxonomy', 555 'title', 556 'type_id', 557 'url', 558 ]; 559 560 foreach ($properties as $k => $v) { 561 $this->$v = $serialized[$k]; 562 } 563 564 foreach ($this->taxonomy as $nodes) { 565 foreach ($nodes as $node) { 566 $curTaxonomy = Taxonomy::getTaxonomy($node->id); 567 $node->state = $curTaxonomy->state; 568 $node->access = $curTaxonomy->access; 569 } 570 } 571 } 572 }
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 |