Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 36 additions & 21 deletions administrator/components/com_content/Model/ArticlesModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Joomla\CMS\Table\Table;
use Joomla\CMS\Workflow\Workflow;
use Joomla\Component\Content\Administrator\Extension\ContentComponent;
use Joomla\Database\ParameterType;
use Joomla\Utilities\ArrayHelper;

/**
Expand Down Expand Up @@ -204,7 +205,7 @@ protected function getListQuery()
$query->select(
$this->getState(
'list.select',
'DISTINCT a.id, a.title, a.alias, a.checked_out, a.checked_out_time, a.catid' .
'a.id, a.title, a.alias, a.checked_out, a.checked_out_time, a.catid' .
', a.state, a.access, a.created, a.created_by, a.created_by_alias, a.modified, a.ordering, a.featured, a.language, a.hits' .
', a.publish_up, a.publish_down, a.introtext, a.note'
)
Expand Down Expand Up @@ -461,34 +462,48 @@ protected function getListQuery()
}

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

if (is_numeric($tagId))
// Run simplified query when filtering by one tag.
if (\is_array($tag) && \count($tag) === 1)
{
$hasTag = true;

$query->where($db->quoteName('tagmap.tag_id') . ' = ' . (int) $tagId);
$tag = $tag[0];
}
elseif (is_array($tagId))

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

if (!empty($tagId))
{
$hasTag = true;
$subQuery = $db->getQuery(true)
->select('DISTINCT ' . $db->quoteName('content_item_id'))
->from($db->quoteName('#__contentitem_tag_map'))
->where(
[
$db->quoteName('tag_id') . ' IN (' . implode(',', $query->bindArray($tag)) . ')',
$db->quoteName('type_alias') . ' = ' . $db->quote('com_content.article'),
]
);

$query->where($db->quoteName('tagmap.tag_id') . ' IN (' . $tagId . ')');
}
$query->join(
'INNER',
'(' . $subQuery . ') AS ' . $db->quoteName('tagmap'),
$db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id')
);
}

if ($hasTag)
elseif ($tag = (int) $tag)
{
$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->join(
'INNER',
$db->quoteName('#__contentitem_tag_map', 'tagmap'),
$db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id')
)
->where(
[
$db->quoteName('tagmap.tag_id') . ' = :tag',
$db->quoteName('tagmap.type_alias') . ' = ' . $db->quote('com_content.article'),
]
)
->bind(':tag', $tag, ParameterType::INTEGER);
}

// Add the list ordering clause.
Expand Down