Source for file suggestions.php

Documentation is available at suggestions.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Site
  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. define('FINDER_PATH_INDEXER'JPATH_ADMINISTRATOR '/components/com_finder/helpers/indexer');
  13. JLoader::register('FinderIndexerHelper'FINDER_PATH_INDEXER '/helper.php');
  14.  
  15. /**
  16.  * Suggestions model class for the Finder package.
  17.  *
  18.  * @package     Joomla.Site
  19.  * @subpackage  com_finder
  20.  * @since       2.5
  21.  */
  22. {
  23.     /**
  24.      * Context string for the model type.
  25.      *
  26.      * @var    string 
  27.      * @since  2.5
  28.      */
  29.     protected $context = 'com_finder.suggestions';
  30.  
  31.     /**
  32.      * Method to get an array of data items.
  33.      *
  34.      * @return  array  An array of data items.
  35.      *
  36.      * @since   2.5
  37.      */
  38.     public function getItems()
  39.     {
  40.         // Get the items.
  41.         $items parent::getItems();
  42.  
  43.         // Convert them to a simple array.
  44.         foreach ($items as $k => $v)
  45.         {
  46.             $items[$k$v->term;
  47.         }
  48.  
  49.         return $items;
  50.     }
  51.  
  52.     /**
  53.      * Method to build a database query to load the list data.
  54.      *
  55.      * @return  JDatabaseQuery  A database query
  56.      *
  57.      * @since   2.5
  58.      */
  59.     protected function getListQuery()
  60.     {
  61.         // Create a new query object.
  62.         $db $this->getDbo();
  63.         $query $db->getQuery(true);
  64.  
  65.         // Select required fields
  66.         $query->select('t.term')
  67.             ->from($db->quoteName('#__finder_terms'' AS t')
  68.             ->where('t.term LIKE ' $db->quote($db->escape($this->getState('input')true'%'))
  69.             ->where('t.common = 0')
  70.             ->where('t.language IN (' $db->quote($db->escape($this->getState('language')true)) ', ' $db->quote('*'')')
  71.             ->order('t.links DESC')
  72.             ->order('t.weight DESC');
  73.  
  74.         return $query;
  75.     }
  76.  
  77.     /**
  78.      * Method to get a store id based on model the configuration state.
  79.      *
  80.      * This is necessary because the model is used by the component and
  81.      * different modules that might need different sets of data or different
  82.      * ordering requirements.
  83.      *
  84.      * @param   string  $id  An identifier string to generate the store id. [optional]
  85.      *
  86.      * @return  string  A store id.
  87.      *
  88.      * @since   2.5
  89.      */
  90.     protected function getStoreId($id '')
  91.     {
  92.         // Add the search query state.
  93.         $id .= ':' $this->getState('input');
  94.         $id .= ':' $this->getState('language');
  95.  
  96.         // Add the list state.
  97.         $id .= ':' $this->getState('list.start');
  98.         $id .= ':' $this->getState('list.limit');
  99.  
  100.         return parent::getStoreId($id);
  101.     }
  102.  
  103.     /**
  104.      * Method to auto-populate the model state.  Calling getState in this method will result in recursion.
  105.      *
  106.      * @param   string  $ordering   An optional ordering field.
  107.      * @param   string  $direction  An optional direction (asc|desc).
  108.      *
  109.      * @return  void 
  110.      *
  111.      * @since   2.5
  112.      */
  113.     protected function populateState($ordering null$direction null)
  114.     {
  115.         // Get the configuration options.
  116.         $app JFactory::getApplication();
  117.         $input $app->input;
  118.         $params JComponentHelper::getParams('com_finder');
  119.         $user JFactory::getUser();
  120.  
  121.         // Get the query input.
  122.         $this->setState('input'$input->request->get('q''''string'));
  123.  
  124.         // Set the query language
  125.         $lang FinderIndexerHelper::getDefaultLanguage();
  126.         $lang FinderIndexerHelper::getPrimaryLanguage($lang);
  127.         $this->setState('language'$lang);
  128.  
  129.         // Load the list state.
  130.         $this->setState('list.start'0);
  131.         $this->setState('list.limit'10);
  132.  
  133.         // Load the parameters.
  134.         $this->setState('params'$params);
  135.  
  136.         // Load the user state.
  137.         $this->setState('user.id'(int) $user->get('id'));
  138.     }
  139. }

Documentation generated on Tue, 19 Nov 2013 15:14:44 +0100 by phpDocumentor 1.4.3