Source for file result.php

Documentation is available at result.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_finder
  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('_JEXEC'or die;
  11.  
  12. JLoader::register('FinderIndexer'__DIR__ . '/indexer.php');
  13.  
  14. /**
  15.  * Result class for the Finder indexer package.
  16.  *
  17.  * This class uses magic __get() and __set() methods to prevent properties
  18.  * being added that might confuse the system. All properties not explicitly
  19.  * declared will be pushed into the elements array and can be accessed
  20.  * explicitly using the getElement() method.
  21.  *
  22.  * @package     Joomla.Administrator
  23.  * @subpackage  com_finder
  24.  * @since       2.5
  25.  */
  26. {
  27.     /**
  28.      * An array of extra result properties.
  29.      *
  30.      * @var    array 
  31.      * @since  2.5
  32.      */
  33.     protected $elements = array();
  34.  
  35.     /**
  36.      * This array tells the indexer which properties should be indexed and what
  37.      * weights to use for those properties.
  38.      *
  39.      * @var    array 
  40.      * @since  2.5
  41.      */
  42.     protected $instructions = array(
  43.         FinderIndexer::TITLE_CONTEXT => array('title''subtitle''id'),
  44.         FinderIndexer::TEXT_CONTEXT => array('summary''body'),
  45.         FinderIndexer::META_CONTEXT => array('meta''list_price''sale_price'),
  46.         FinderIndexer::PATH_CONTEXT => array('path''alias'),
  47.         FinderIndexer::MISC_CONTEXT => array('comments')
  48.     );
  49.  
  50.     /**
  51.      * The indexer will use this data to create taxonomy mapping entries for
  52.      * the item so that it can be filtered by type, label, category,
  53.      * or whatever.
  54.      *
  55.      * @var    array 
  56.      * @since  2.5
  57.      */
  58.     protected $taxonomy = array();
  59.  
  60.     /**
  61.      * The content URL.
  62.      *
  63.      * @var    string 
  64.      * @since  2.5
  65.      */
  66.     public $url;
  67.  
  68.     /**
  69.      * The content route.
  70.      *
  71.      * @var    string 
  72.      * @since  2.5
  73.      */
  74.     public $route;
  75.  
  76.     /**
  77.      * The content title.
  78.      *
  79.      * @var    string 
  80.      * @since  2.5
  81.      */
  82.     public $title;
  83.  
  84.     /**
  85.      * The content description.
  86.      *
  87.      * @var    string 
  88.      * @since  2.5
  89.      */
  90.     public $description;
  91.  
  92.     /**
  93.      * The published state of the result.
  94.      *
  95.      * @var    integer 
  96.      * @since  2.5
  97.      */
  98.     public $published;
  99.  
  100.     /**
  101.      * The content published state.
  102.      *
  103.      * @var    integer 
  104.      * @since  2.5
  105.      */
  106.     public $state;
  107.  
  108.     /**
  109.      * The content access level.
  110.      *
  111.      * @var    integer 
  112.      * @since  2.5
  113.      */
  114.     public $access;
  115.  
  116.     /**
  117.      * The content language.
  118.      *
  119.      * @var    string 
  120.      * @since  2.5
  121.      */
  122.     public $language = '*';
  123.  
  124.     /**
  125.      * The publishing start date.
  126.      *
  127.      * @var    string 
  128.      * @since  2.5
  129.      */
  130.     public $publish_start_date;
  131.  
  132.     /**
  133.      * The publishing end date.
  134.      *
  135.      * @var    string 
  136.      * @since  2.5
  137.      */
  138.     public $publish_end_date;
  139.  
  140.     /**
  141.      * The generic start date.
  142.      *
  143.      * @var    string 
  144.      * @since  2.5
  145.      */
  146.     public $start_date;
  147.  
  148.     /**
  149.      * The generic end date.
  150.      *
  151.      * @var    string 
  152.      * @since  2.5
  153.      */
  154.     public $end_date;
  155.  
  156.     /**
  157.      * The item list price.
  158.      *
  159.      * @var    mixed 
  160.      * @since  2.5
  161.      */
  162.     public $list_price;
  163.  
  164.     /**
  165.      * The item sale price.
  166.      *
  167.      * @var    mixed 
  168.      * @since  2.5
  169.      */
  170.     public $sale_price;
  171.  
  172.     /**
  173.      * The content type id. This is set by the adapter.
  174.      *
  175.      * @var    integer 
  176.      * @since  2.5
  177.      */
  178.     public $type_id;
  179.  
  180.     /**
  181.      * The default language for content.
  182.      *
  183.      * @var    string 
  184.      * @since  3.0.2
  185.      */
  186.     public $defaultLanguage;
  187.  
  188.     /**
  189.      * Constructor
  190.      *
  191.      * @since   3.0.3
  192.      */
  193.     public function __construct()
  194.     {
  195.         $this->defaultLanguage = JComponentHelper::getParams('com_languages')->get('site''en-GB');
  196.     }
  197.  
  198.     /**
  199.      * The magic set method is used to push additional values into the elements
  200.      * array in order to preserve the cleanliness of the object.
  201.      *
  202.      * @param   string  $name   The name of the element.
  203.      * @param   mixed   $value  The value of the element.
  204.      *
  205.      * @return  void 
  206.      *
  207.      * @since   2.5
  208.      */
  209.     public function __set($name$value)
  210.     {
  211.         $this->elements[$name$value;
  212.     }
  213.  
  214.     /**
  215.      * The magic get method is used to retrieve additional element values
  216.      * from the elements array.
  217.      *
  218.      * @param   string  $name  The name of the element.
  219.      *
  220.      * @return  mixed  The value of the element if set, null otherwise.
  221.      *
  222.      * @since   2.5
  223.      */
  224.     public function __get($name)
  225.     {
  226.         // Get the element value if set.
  227.         if (array_key_exists($name$this->elements))
  228.         {
  229.             return $this->elements[$name];
  230.         }
  231.         else
  232.         {
  233.             return null;
  234.         }
  235.     }
  236.  
  237.     /**
  238.      * The magic isset method is used to check the state of additional element
  239.      * values in the elements array.
  240.      *
  241.      * @param   string  $name  The name of the element.
  242.      *
  243.      * @return  boolean  True if set, false otherwise.
  244.      *
  245.      * @since   2.5
  246.      */
  247.     public function __isset($name)
  248.     {
  249.         return isset($this->elements[$name]);
  250.     }
  251.  
  252.     /**
  253.      * The magic unset method is used to unset additional element values in the
  254.      * elements array.
  255.      *
  256.      * @param   string  $name  The name of the element.
  257.      *
  258.      * @return  void 
  259.      *
  260.      * @since   2.5
  261.      */
  262.     public function __unset($name)
  263.     {
  264.         unset($this->elements[$name]);
  265.     }
  266.  
  267.     /**
  268.      * Method to retrieve additional element values from the elements array.
  269.      *
  270.      * @param   string  $name  The name of the element.
  271.      *
  272.      * @return  mixed  The value of the element if set, null otherwise.
  273.      *
  274.      * @since   2.5
  275.      */
  276.     public function getElement($name)
  277.     {
  278.         // Get the element value if set.
  279.         if (array_key_exists($name$this->elements))
  280.         {
  281.             return $this->elements[$name];
  282.         }
  283.         else
  284.         {
  285.             return null;
  286.         }
  287.     }
  288.  
  289.     /**
  290.      * Method to set additional element values in the elements array.
  291.      *
  292.      * @param   string  $name   The name of the element.
  293.      * @param   mixed   $value  The value of the element.
  294.      *
  295.      * @return  void 
  296.      *
  297.      * @since   2.5
  298.      */
  299.     public function setElement($name$value)
  300.     {
  301.         $this->elements[$name$value;
  302.     }
  303.  
  304.     /**
  305.      * Method to get all processing instructions.
  306.      *
  307.      * @return  array  An array of processing instructions.
  308.      *
  309.      * @since   2.5
  310.      */
  311.     public function getInstructions()
  312.     {
  313.         return $this->instructions;
  314.     }
  315.  
  316.     /**
  317.      * Method to add a processing instruction for an item property.
  318.      *
  319.      * @param   string  $group     The group to associate the property with.
  320.      * @param   string  $property  The property to process.
  321.      *
  322.      * @return  void 
  323.      *
  324.      * @since   2.5
  325.      */
  326.     public function addInstruction($group$property)
  327.     {
  328.         // Check if the group exists. We can't add instructions for unknown groups.
  329.         if (array_key_exists($group$this->instructions))
  330.         {
  331.             // Check if the property exists in the group.
  332.             if (!in_array($property$this->instructions[$group]))
  333.             {
  334.                 // Add the property to the group.
  335.                 $this->instructions[$group][$property;
  336.             }
  337.         }
  338.     }
  339.  
  340.     /**
  341.      * Method to remove a processing instruction for an item property.
  342.      *
  343.      * @param   string  $group     The group to associate the property with.
  344.      * @param   string  $property  The property to process.
  345.      *
  346.      * @return  void 
  347.      *
  348.      * @since   2.5
  349.      */
  350.     public function removeInstruction($group$property)
  351.     {
  352.         // Check if the group exists. We can't remove instructions for unknown groups.
  353.         if (array_key_exists($group$this->instructions))
  354.         {
  355.             // Search for the property in the group.
  356.             $key array_search($property$this->instructions[$group]);
  357.  
  358.             // If the property was found, remove it.
  359.             if ($key !== false)
  360.             {
  361.                 unset($this->instructions[$group][$key]);
  362.             }
  363.         }
  364.     }
  365.  
  366.     /**
  367.      * Method to get the taxonomy maps for an item.
  368.      *
  369.      * @param   string  $branch  The taxonomy branch to get. [optional]
  370.      *
  371.      * @return  array  An array of taxonomy maps.
  372.      *
  373.      * @since   2.5
  374.      */
  375.     public function getTaxonomy($branch null)
  376.     {
  377.         // Get the taxonomy branch if available.
  378.         if ($branch !== null && isset($this->taxonomy[$branch]))
  379.         {
  380.             // Filter the input.
  381.             $branch preg_replace('#[^\pL\pM\pN\p{Pi}\p{Pf}\'+-.,]+#mui'' '$branch);
  382.  
  383.             return $this->taxonomy[$branch];
  384.         }
  385.  
  386.         return $this->taxonomy;
  387.     }
  388.  
  389.     /**
  390.      * Method to add a taxonomy map for an item.
  391.      *
  392.      * @param   string   $branch  The title of the taxonomy branch to add the node to.
  393.      * @param   string   $title   The title of the taxonomy node.
  394.      * @param   integer  $state   The published state of the taxonomy node. [optional]
  395.      * @param   integer  $access  The access level of the taxonomy node. [optional]
  396.      *
  397.      * @return  void 
  398.      *
  399.      * @since   2.5
  400.      */
  401.     public function addTaxonomy($branch$title$state 1$access 1)
  402.     {
  403.         // Filter the input.
  404.         $branch preg_replace('#[^\pL\pM\pN\p{Pi}\p{Pf}\'+-.,]+#mui'' '$branch);
  405.  
  406.         // Create the taxonomy node.
  407.         $node new JObject;
  408.         $node->title $title;
  409.         $node->state = (int) $state;
  410.         $node->access = (int) $access;
  411.  
  412.         // Add the node to the taxonomy branch.
  413.         $this->taxonomy[$branch][$node->title$node;
  414.     }
  415.  
  416.     /**
  417.      * Method to set the item language
  418.      *
  419.      * @return  void 
  420.      *
  421.      * @since   3.0
  422.      */
  423.     public function setLanguage()
  424.     {
  425.         if ($this->language == '*' || $this->language == '')
  426.         {
  427.             $this->language = $this->defaultLanguage;
  428.         }
  429.     }
  430. }

Documentation generated on Tue, 19 Nov 2013 15:12:18 +0100 by phpDocumentor 1.4.3