Skip to content

Commit

Permalink
[com_content] Featured articles tag filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
SharkyKZ committed Jul 16, 2018
1 parent 0c59b29 commit 1ca980c
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions administrator/components/com_content/models/featured.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,18 +212,38 @@ protected function getListQuery()
$query->where('a.language = ' . $db->quote($language));
}

// Filter by a single tag.
// Filter by a single or group of tags.
$tagId = $this->getState('filter.tag');

if (is_numeric($tagId))
if (is_array($tagId) && count($tagId) === 1)
{
$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')
);
$tagId = current($tagId);
}

if (is_array($tagId))
{
$tagId = implode(',', ArrayHelper::toInteger($tagId));

if ($tagId)
{
$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->join('INNER', '(' . (string) $subQuery . ') AS tagmap ON tagmap.content_item_id = a.id');
}
}
elseif ($tagId)
{
$query->join(
'INNER',
$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')
);
}

// Add the list ordering clause.
Expand Down

0 comments on commit 1ca980c

Please sign in to comment.