Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: Joomla-Framework

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5
Source code for file /joomla/application/search.php

Documentation is available at search.php

  1. <?php
  2. /**
  3.  * @version        $Id: search.php 6712 2007-02-24 02:00:40Z hackwar $
  4.  * @package        Joomla.Framework
  5.  * @subpackage    Application
  6.  * @copyright    Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
  7.  * @license        GNU/GPL, see LICENSE.php
  8.  *  Joomla! is free software. This version may have been modified pursuant to the
  9.  *  GNU General Public License, and as distributed it includes or is derivative
  10.  *  of works licensed under the GNU General Public License or other free or open
  11.  *  source software licenses. See COPYRIGHT.php for copyright notices and
  12.  *  details.
  13.  */
  14.  
  15. // Check to ensure this file is within the rest of the framework
  16. defined('JPATH_BASE'or die();
  17.  
  18. /**
  19.  * Base search class
  20.  *
  21.  * @author        Andrew Eddie
  22.  * @package     Joomla.Framework
  23.  * @subpackage    Application
  24.  * @since        1.5
  25.  */
  26. class JSearch extends JObject
  27. {
  28.     /**
  29.      * @var string The text or phrase to search for
  30.      */
  31.     var $needle = null;
  32.  
  33.     /**
  34.      * @var string The ordering for the search
  35.      */
  36.     var $ordering = null;
  37.  
  38.     /**
  39.      * @var string The match type: all|any|exact
  40.      */
  41.     var $matchType = null;
  42.  
  43.     /**
  44.      * @var int The pagination for the complete result set
  45.      */
  46.     var $limitstart = null;
  47.  
  48.     /**
  49.      * @var int The total number of rows to return
  50.      */
  51.     var $limit = null;
  52.  
  53.     /**
  54.      * @var int The number of results already returned
  55.      */
  56.     var $count = null;
  57.  
  58.     /**
  59.      * @var array An array of results
  60.      */
  61.     var $results = null;
  62.  
  63.     /**
  64.      * @var int 
  65.      * @access private
  66.      */
  67.     var $_queryLimitStart null;
  68.  
  69.     /**
  70.      * @var int 
  71.      * @access private
  72.      */
  73.     var $_queryLimit null;
  74.  
  75.     /**
  76.      * Constructor
  77.      */
  78.     function __construct$needle$matchType$ordering$areas$limitstart=0$limit=)
  79.     {
  80.         $this->needle        = $needle;
  81.         $this->matchType    = $matchType;
  82.         $this->ordering        = $ordering;
  83.         $this->areas        $areas;
  84.         $this->limitstart    = $limitstart;
  85.         $this->limit        = $limit;
  86.  
  87.         $this->count        = 0;
  88.         $this->results        = array();
  89.     }
  90.  
  91.     /**
  92.      * @param int 
  93.      */
  94.     function setLimitStart$value {
  95.         $this->limitstart = 0;
  96.     }
  97.  
  98.     /**
  99.      * @param int 
  100.      */
  101.     function setLimit$value {
  102.         $this->limit = 0;
  103.     }
  104.  
  105.     /**
  106.      * @return string 
  107.      */
  108.     function getOrdering({
  109.         return $this->ordering;
  110.     }
  111.  
  112.     /**
  113.      * @return string 
  114.      */
  115.     function getMatchType({
  116.         return $this->matchType;
  117.     }
  118.  
  119.     /**
  120.      * @return string 
  121.      */
  122.     function getNeedle({
  123.         return $this->needle;
  124.     }
  125.  
  126.     /**
  127.      * @return array 
  128.      */
  129.     function getAreas({
  130.         return $this->areas;
  131.     }
  132.  
  133.     /**
  134.      * Adds the total number of returns of the current search plugin to the
  135.      * running total and determines the limit and limitstart for the query
  136.      * @param int 
  137.      */
  138.     function addResultCount$n )
  139.     {
  140.         // the start and end points for this query
  141.         $qStart $this->count;
  142.         $this->count += $n;
  143.         $qEnd $this->count;
  144.  
  145.         // the count for the start and end of the search
  146.         $sStart    $this->limitstart;
  147.         $sEnd    $this->limitstart + $this->limit;
  148.  
  149. //echo "<br>n=$n | qStart=$qStart, qEnd=$qEnd | sStart=$sStart, sEnd=$sEnd<br>";
  150.  
  151.         $this->_queryLimitStart    0;
  152.         $this->_queryLimit        0;
  153.  
  154.         if ($n == 0{
  155.             // do nothing
  156.         else if ($qEnd $sStart{
  157.             // not yet at the right page of results
  158.             // do nothing
  159.         else if ($qStart >= $sEnd{
  160.             // we are passed the end of the page
  161.             // do nothing
  162.         else if ($qStart $sStart{
  163.             // these results clip the beginning of the results page
  164.             $this->_queryLimitStart    $sStart $qStart;
  165.             $this->_queryLimit        max$this->limit$qEnd $this->_queryLimitStart );
  166.         else if ($qStart >= $sStart {
  167.             // these results start within the results page
  168.             $this->_queryLimitStart    $qStart;
  169.             $this->_queryLimit        max$this->limit$qEnd $this->_queryLimitStart );
  170.         }
  171.     }
  172.  
  173.     /**
  174.      * @return int 
  175.      */
  176.     function getResultCount({
  177.         return $this->count;
  178.     }
  179.  
  180.     /**
  181.      * Returns the limit start for the next search query
  182.      * @return int 
  183.      */
  184.     function getQueryLimitStart({
  185.         // used to skip over the paged results
  186.         return $this->_queryLimitStart;
  187.     }
  188.  
  189.     /**
  190.      * Returns the limit for the next search query
  191.      * @return int 
  192.      */
  193.     function getQueryLimit({
  194.         // used to return how many records to actually get from the current query
  195.         return $this->_queryLimit;
  196.     }
  197.  
  198.     /**
  199.      * @param array An array of object results
  200.      */
  201.     function addResults$array {
  202.         $this->results = array_merge$this->results$array );
  203.     }
  204.  
  205.     /**
  206.      * @return array 
  207.      */
  208.     function getResults({
  209.         return $this->results;
  210.     }
  211. }
  212.  
  213. /**
  214.  * Search helper class
  215.  *
  216.  * @author        Andrew Eddie
  217.  * @package     Joomla.Framework
  218.  * @subpackage    Application
  219.  * @since        1.5
  220.  */
  221. {
  222.     /**
  223.      * @return JParameter Parameters for the serach plugin
  224.      */
  225.     function &getPluginParams$folder$name )
  226.     {
  227.         if ($folder && $name{
  228.              $plugin =JPluginHelper::getPlugin($folder$name);
  229.              $pluginParams new JParameter$plugin->params );
  230.         else {
  231.              $pluginParams new JParameter'' );
  232.         }
  233.  
  234.          return $pluginParams;
  235.     }
  236.  
  237.     /**
  238.      * @param array A flat array of search areas
  239.      * @param array A named array of search areas for the plugin
  240.      * @return boolean 
  241.      */
  242.     function inArea$formAreas$pluginAreas )
  243.     {
  244.         if (is_array$formAreas )) {
  245.             if (!array_intersect$formAreasarray_keys$pluginAreas ) )) {
  246.                 return false;
  247.             }
  248.         }
  249.         return true;
  250.     }
  251. }
  252. ?>

Documentation generated on Mon, 05 Mar 2007 21:20:37 +0000 by phpDocumentor 1.3.1