| [ Index ] |
PHP Cross Reference of Joomla 2.5.4 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @package Joomla.Administrator 4 * @subpackage com_search 5 * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. 6 * @license GNU General Public License version 2 or later; see LICENSE.txt 7 */ 8 9 // No direct access. 10 defined('_JEXEC') or die; 11 12 jimport('joomla.application.component.modellist'); 13 14 /** 15 * Methods supporting a list of search terms. 16 * 17 * @package Joomla.Administrator 18 * @subpackage com_search 19 * @since 1.6 20 */ 21 class SearchModelSearches extends JModelList 22 { 23 /** 24 * Constructor. 25 * 26 * @param array An optional associative array of configuration settings. 27 * @see JController 28 * @since 1.6 29 */ 30 public function __construct($config = array()) 31 { 32 if (empty($config['filter_fields'])) { 33 $config['filter_fields'] = array( 34 'search_term', 'a.search_term', 35 'hits', 'a.hits', 36 ); 37 } 38 39 parent::__construct($config); 40 } 41 42 /** 43 * Method to auto-populate the model state. 44 * 45 * Note. Calling getState in this method will result in recursion. 46 * 47 * @since 1.6 48 */ 49 protected function populateState($ordering = null, $direction = null) 50 { 51 // Initialise variables. 52 $app = JFactory::getApplication('administrator'); 53 54 // Load the filter state. 55 $search = $this->getUserStateFromRequest($this->context.'.filter.search', 'filter_search'); 56 $this->setState('filter.search', $search); 57 58 $showResults = $this->getUserStateFromRequest($this->context.'.filter.results', 'filter_results', null, 'int'); 59 $this->setState('filter.results', $showResults); 60 61 // Load the parameters. 62 $params = JComponentHelper::getParams('com_search'); 63 $this->setState('params', $params); 64 65 // List state information. 66 parent::populateState('a.hits', 'asc'); 67 } 68 69 /** 70 * Method to get a store id based on model configuration state. 71 * 72 * This is necessary because the model is used by the component and 73 * different modules that might need different sets of data or different 74 * ordering requirements. 75 * 76 * @param string $id A prefix for the store id. 77 * 78 * @return string A store id. 79 */ 80 protected function getStoreId($id = '') 81 { 82 // Compile the store id. 83 $id .= ':'.$this->getState('filter.search'); 84 $id .= ':'.$this->getState('filter.results'); 85 86 return parent::getStoreId($id); 87 } 88 89 /** 90 * Build an SQL query to load the list data. 91 * 92 * @return JDatabaseQuery 93 */ 94 protected function getListQuery() 95 { 96 // Create a new query object. 97 $db = $this->getDbo(); 98 $query = $db->getQuery(true); 99 100 // Select the required fields from the table. 101 $query->select( 102 $this->getState( 103 'list.select', 104 'a.*' 105 ) 106 ); 107 $query->from($db->quoteName('#__core_log_searches').' AS a'); 108 109 // Filter by access level. 110 if ($access = $this->getState('filter.access')) { 111 $query->where('a.access = '.(int) $access); 112 } 113 114 // Filter by search in title 115 $search = $this->getState('filter.search'); 116 if (!empty($search)) 117 { 118 $search = $db->Quote('%'.$db->escape($search, true).'%'); 119 $query->where('a.search_term LIKE '.$search); 120 } 121 122 // Add the list ordering clause. 123 $query->order($db->escape($this->getState('list.ordering', 'a.hits')).' '.$db->escape($this->getState('list.direction', 'ASC'))); 124 125 //echo nl2br(str_replace('#__','jos_',$query)); 126 return $query; 127 } 128 129 /** 130 * Override the parnet getItems to inject optional data. 131 * 132 * @return mixed An array of objects on success, false on failure. 133 */ 134 public function getItems() 135 { 136 $items = parent::getItems(); 137 138 // Determine if number of results for search item should be calculated 139 // by default it is `off` as it is highly query intensive 140 if ($this->getState('filter.results')) { 141 JPluginHelper::importPlugin('search'); 142 $app = JFactory::getApplication(); 143 144 if (!class_exists('JSite')) { 145 // This fools the routers in the search plugins into thinking it's in the frontend 146 JLoader::register('JSite', JPATH_COMPONENT.'/helpers/site.php'); 147 } 148 149 foreach ($items as &$item) { 150 $results = $app->triggerEvent('onContentSearch', array($item->search_term)); 151 $item->returns = 0; 152 foreach ($results as $result) { 153 $item->returns += count($result); 154 } 155 } 156 } 157 158 return $items; 159 } 160 161 /** 162 * Method to reset the seach log table. 163 * 164 * @return boolean 165 */ 166 public function reset() 167 { 168 $db = $this->getDbo(); 169 $db->setQuery( 170 'DELETE FROM #__core_log_searches' 171 ); 172 if (!$db->query()) { 173 $this->setError($db->getErrorMsg()); 174 return false; 175 } 176 177 return true; 178 } 179 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Apr 3 11:40:28 2012 | Cross-referenced by PHPXref 0.7.1 |