diff --git a/components/com_content/models/articles.php b/components/com_content/models/articles.php index baa2d56ed231d..e0afe91711c03 100644 --- a/components/com_content/models/articles.php +++ b/components/com_content/models/articles.php @@ -52,7 +52,6 @@ public function __construct($config = array()) 'images', 'a.images', 'urls', 'a.urls', 'filter_tag', - 'tag', ); } @@ -189,7 +188,7 @@ protected function getListQuery() $query->select( $this->getState( 'list.select', - 'DISTINCT a.id, a.title, a.alias, a.introtext, a.fulltext, ' . + 'a.id, a.title, a.alias, a.introtext, a.fulltext, ' . 'a.checked_out, a.checked_out_time, ' . 'a.catid, a.created, a.created_by, a.created_by_alias, ' . // Published/archived article in archive category is treats as archive article @@ -504,37 +503,39 @@ protected function getListQuery() // Filter by language if ($this->getState('filter.language')) { - $query->where('a.language in (' . $db->quote(JFactory::getLanguage()->getTag()) . ',' . $db->quote('*') . ')'); + $query->where('a.language IN (' . $db->quote(JFactory::getLanguage()->getTag()) . ',' . $db->quote('*') . ')'); } // Filter by a single or group of tags. - $hasTag = false; - $tagId = $this->getState('filter.tag'); + $tagId = $this->getState('filter.tag'); - if (!empty($tagId) && is_numeric($tagId)) + if (is_array($tagId) && count($tagId) === 1) { - $hasTag = true; - - $query->where($db->quoteName('tagmap.tag_id') . ' = ' . (int) $tagId); + $tagId = current($tagId); } - elseif (is_array($tagId)) + + if (is_array($tagId)) { - ArrayHelper::toInteger($tagId); - $tagId = implode(',', $tagId); + $tagId = implode(',', ArrayHelper::toInteger($tagId)); - if (!empty($tagId)) + if ($tagId) { - $hasTag = true; + $subQuery = $db->getQuery(true) + ->select('DISTINCT content_item_id') + ->from($db->quoteName('#__contentitem_tag_map')) + ->where('tag_id IN (' . $tagId . ')') + ->where('type_alias = ' . $db->quote('com_content.article')); - $query->where($db->quoteName('tagmap.tag_id') . ' IN (' . $tagId . ')'); + $query->innerJoin('(' . (string) $subQuery . ') AS tagmap ON tagmap.content_item_id = a.id'); } } - - if ($hasTag) + elseif ($tagId) { - $query->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') + $query->innerJoin( + $db->quoteName('#__contentitem_tag_map', 'tagmap') + . ' ON tagmap.tag_id = ' . (int) $tagId + . ' AND tagmap.content_item_id = a.id' + . ' AND tagmap.type_alias = ' . $db->quote('com_content.article') ); }