getDbo(); $query = $db->getQuery(true); // Select all fields from the table. $query->select('a.*') ->from($db->quoteName('#__finder_filters') . ' AS a'); // Join over the users for the checked out user. $query->select('uc.name AS editor') ->join('LEFT', $db->quoteName('#__users') . ' AS uc ON uc.id=a.checked_out'); // Join over the users for the author. $query->select('ua.name AS user_name') ->join('LEFT', $db->quoteName('#__users') . ' AS ua ON ua.id = a.created_by'); // Check for a search filter. if ($this->getState('filter.search')) { $search = $db->quote('%' . str_replace(' ', '%', $db->escape(trim($this->getState('filter.search')), true) . '%')); $query->where('( a.title LIKE \'%' . $search . '%\' )'); } // If the model is set to check item state, add to the query. if (is_numeric($this->getState('filter.state'))) { $query->where('a.state = ' . (int) $this->getState('filter.state')); } // Add the list ordering clause. $query->order($db->escape($this->getState('list.ordering') . ' ' . $db->escape($this->getState('list.direction')))); return $query; } /** * Method to get a store id based on model configuration state. * * This is necessary because the model is used by the component and * different modules that might need different sets of data or different * ordering requirements. * * @param string $id A prefix for the store id. [optional] * * @return string A store id. * * @since 2.5 */ protected function getStoreId($id = '') { // Compile the store id. $id .= ':' . $this->getState('filter.search'); $id .= ':' . $this->getState('filter.state'); return parent::getStoreId($id); } /** * Method to auto-populate the model state. Calling getState in this method will result in recursion. * * @param string $ordering An optional ordering field. [optional] * @param string $direction An optional direction. [optional] * * @return void * * @since 2.5 */ protected function populateState($ordering = null, $direction = null) { // Load the filter state. $search = $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search'); $this->setState('filter.search', $search); $state = $this->getUserStateFromRequest($this->context . '.filter.state', 'filter_state', '', 'string'); $this->setState('filter.state', $state); // Load the parameters. $params = JComponentHelper::getParams('com_finder'); $this->setState('params', $params); // List state information. parent::populateState('a.title', 'asc'); } }