getDbo(); $query = $db->getQuery(true); // Select the required fields from the table. $query->select( $this->getState( 'list.select', 'a.id, a.title, a.alias, a.checked_out, a.checked_out_time, a.catid, a.state, a.access, a.created, a.hits,' . 'a.featured, a.language, a.created_by_alias, a.publish_up, a.publish_down' ) ); $query->from('#__content AS a'); // Join over the language $query->select('l.title AS language_title') ->join('LEFT', $db->quoteName('#__languages') . ' AS l ON l.lang_code = a.language'); // Join over the content table. $query->select('fp.ordering') ->join('INNER', '#__content_frontpage AS fp ON fp.content_id = a.id'); // Join over the users for the checked out user. $query->select('uc.name AS editor') ->join('LEFT', '#__users AS uc ON uc.id=a.checked_out'); // Join over the asset groups. $query->select('ag.title AS access_level') ->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access'); // Join over the categories. $query->select('c.title AS category_title') ->join('LEFT', '#__categories AS c ON c.id = a.catid'); // Join over the users for the author. $query->select('ua.name AS author_name') ->join('LEFT', '#__users AS ua ON ua.id = a.created_by'); // Filter by access level. if ($access = $this->getState('filter.access')) { $query->where('a.access = ' . (int) $access); } // Filter by published state $published = $this->getState('filter.published'); if (is_numeric($published)) { $query->where('a.state = ' . (int) $published); } elseif ($published === '') { $query->where('(a.state = 0 OR a.state = 1)'); } // Filter by a single or group of categories. $baselevel = 1; $categoryId = $this->getState('filter.category_id'); if (is_numeric($categoryId)) { $cat_tbl = JTable::getInstance('Category', 'JTable'); $cat_tbl->load($categoryId); $rgt = $cat_tbl->rgt; $lft = $cat_tbl->lft; $baselevel = (int) $cat_tbl->level; $query->where('c.lft >= ' . (int) $lft) ->where('c.rgt <= ' . (int) $rgt); } elseif (is_array($categoryId)) { JArrayHelper::toInteger($categoryId); $categoryId = implode(',', $categoryId); $query->where('a.catid IN (' . $categoryId . ')'); } // Filter on the level. if ($level = $this->getState('filter.level')) { $query->where('c.level <= ' . ((int) $level + (int) $baselevel - 1)); } // Filter by author $authorId = $this->getState('filter.author_id'); if (is_numeric($authorId)) { $type = $this->getState('filter.author_id.include', true) ? '= ' : '<>'; $query->where('a.created_by ' . $type . (int) $authorId); } // 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 = $db->quote('%' . str_replace(' ', '%', $db->escape(trim($search), true) . '%')); $query->where('a.title LIKE ' . $search . ' OR a.alias LIKE ' . $search); } } // Filter on the language. if ($language = $this->getState('filter.language')) { $query->where('a.language = ' . $db->quote($language)); } // Filter by a single tag. $tagId = $this->getState('filter.tag'); if (is_numeric($tagId)) { $query->where($db->quoteName('tagmap.tag_id') . ' = ' . (int) $tagId) ->join( 'LEFT', $db->quoteName('#__contentitem_tag_map', 'tagmap') . ' ON ' . $db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id') . ' AND ' . $db->quoteName('tagmap.type_alias') . ' = ' . $db->quote('com_content.article') ); } // Add the list ordering clause. $query->order($db->escape($this->getState('list.ordering', 'a.title')) . ' ' . $db->escape($this->getState('list.direction', 'ASC'))); return $query; } }