/** * Build an SQL query to load the list data. * * @return JQuery */ protected function _getListQuery() { // Create a new query object. $query = new JQuery(); // Select the required fields from the table. $query->select($this->getState('list.select', 'a.id, a.template, a.title, a.home, a.client_id')); $query->from('`#__template_styles` AS a'); // Join on menus. $query->select('COUNT(m.template_style_id) AS assigned'); $query->leftjoin('#__menu AS m ON m.template_style_id = a.id'); $query->group('a.id'); // Filter by template. if ($template = $this->getState('filter.template')) { $query->where('a.template = ' . $this->_db->quote($template)); } // Filter by client. $clientId = $this->getState('filter.client_id'); if (is_numeric($clientId)) { $query->where('a.client_id = ' . (int) $clientId); } // Filter by search in title $search = $this->getState('filter.search'); if (!empty($search)) { if (stripos($search, 'id:') === 0) { $query->where('a.id = ' . (int) substr($search, 3)); } else { $search = $this->_db->Quote('%' . $this->_db->getEscaped($search, true) . '%'); $query->where('a.template LIKE ' . $search . ' OR a.title LIKE ' . $search); } } // Add the list ordering clause. $query->order($this->_db->getEscaped($this->getState('list.ordering', 'a.name')) . ' ' . $this->_db->getEscaped($this->getState('list.direction', 'ASC'))); //echo nl2br(str_replace('#__','jos_',$query)); return $query; }