PageRenderTime 16ms CodeModel.GetById 13ms app.highlight 2ms RepoModel.GetById 0ms app.codeStats 0ms

/components/com_finder/models/suggestions.php

https://bitbucket.org/eternaware/joomus
PHP | 132 lines | 48 code | 16 blank | 68 comment | 0 complexity | 3c765dfd289d6ba11726778edb246619 MD5 | raw file
Possible License(s): LGPL-2.1
  1<?php
  2/**
  3 * @package     Joomla.Site
  4 * @subpackage  com_finder
  5 *
  6 * @copyright   Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
  7 * @license     GNU General Public License version 2 or later; see LICENSE
  8 */
  9
 10defined('_JEXEC') or die;
 11
 12/**
 13 * Suggestions model class for the Finder package.
 14 *
 15 * @package     Joomla.Site
 16 * @subpackage  com_finder
 17 * @since       2.5
 18 */
 19class FinderModelSuggestions extends JModelList
 20{
 21	/**
 22	 * Context string for the model type.
 23	 *
 24	 * @var    string
 25	 * @since  2.5
 26	 */
 27	protected $context = 'com_finder.suggestions';
 28
 29	/**
 30	 * Method to get an array of data items.
 31	 *
 32	 * @return  array  An array of data items.
 33	 *
 34	 * @since   2.5
 35	 */
 36	public function getItems()
 37	{
 38		// Get the items.
 39		$items = parent::getItems();
 40
 41		// Convert them to a simple array.
 42		foreach ($items as $k => $v)
 43		{
 44			$items[$k] = $v->term;
 45		}
 46
 47		return $items;
 48	}
 49
 50	/**
 51	 * Method to build a database query to load the list data.
 52	 *
 53	 * @return  JDatabaseQuery  A database query
 54	 *
 55	 * @since   2.5
 56	 */
 57	protected function getListQuery()
 58	{
 59		// Create a new query object.
 60		$db = $this->getDbo();
 61		$query = $db->getQuery(true);
 62
 63		// Select required fields
 64		$query->select('t.term');
 65		$query->from($db->quoteName('#__finder_terms') . ' AS t');
 66		$query->where('t.term LIKE ' . $db->quote($db->escape($this->getState('input'), true) . '%'));
 67		$query->where('t.common = 0');
 68		$query->order('t.links DESC');
 69		$query->order('t.weight DESC');
 70
 71		return $query;
 72	}
 73
 74	/**
 75	 * Method to get a store id based on model the configuration state.
 76	 *
 77	 * This is necessary because the model is used by the component and
 78	 * different modules that might need different sets of data or different
 79	 * ordering requirements.
 80	 *
 81	 * @param   string  $id  An identifier string to generate the store id. [optional]
 82	 *
 83	 * @return  string  A store id.
 84	 *
 85	 * @since   2.5
 86	 */
 87	protected function getStoreId($id = '')
 88	{
 89		// Add the search query state.
 90		$id .= ':' . $this->getState('input');
 91		$id .= ':' . $this->getState('language');
 92
 93		// Add the list state.
 94		$id .= ':' . $this->getState('list.start');
 95		$id .= ':' . $this->getState('list.limit');
 96
 97		return parent::getStoreId($id);
 98	}
 99
100	/**
101	 * Method to auto-populate the model state.  Calling getState in this method will result in recursion.
102	 *
103	 * @param   string  $ordering   An optional ordering field.
104	 * @param   string  $direction  An optional direction (asc|desc).
105	 *
106	 * @return  void
107	 *
108	 * @since   2.5
109	 */
110	protected function populateState($ordering = null, $direction = null)
111	{
112		// Get the configuration options.
113		$app = JFactory::getApplication();
114		$input = $app->input;
115		$params = JComponentHelper::getParams('com_finder');
116		$user = JFactory::getUser();
117
118		// Get the query input.
119		$this->setState('input', $input->request->get('q', '', 'string'));
120		$this->setState('language', $input->request->get('l', '', 'string'));
121
122		// Load the list state.
123		$this->setState('list.start', 0);
124		$this->setState('list.limit', 10);
125
126		// Load the parameters.
127		$this->setState('params', $params);
128
129		// Load the user state.
130		$this->setState('user.id', (int) $user->get('id'));
131	}
132}