Skip to content

Commit 9bbcaa2

Browse files
[5.4] Add tag filter none com_categories (joomla#45461)
* [5.4] Add tag filter none com_categories --------- Co-authored-by: Richard Fath <[email protected]>
1 parent 750e38e commit 9bbcaa2

File tree

2 files changed

+53
-9
lines changed

2 files changed

+53
-9
lines changed

administrator/components/com_categories/forms/filter_categories.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@
4949
mode="nested"
5050
custom="false"
5151
class="js-select-submit-on-change"
52-
/>
52+
default=""
53+
>
54+
<option value="0">JNONE_FILTER</option>
55+
</field>
5356

5457
<field
5558
name="level"

administrator/components/com_categories/src/Model/CategoriesModel.php

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,13 @@ protected function getListQuery()
333333
}
334334

335335
if ($tag && \is_array($tag)) {
336-
$tag = ArrayHelper::toInteger($tag);
336+
$tag = ArrayHelper::toInteger($tag);
337+
$includeNone = false;
338+
339+
if (\in_array(0, $tag)) {
340+
$tag = array_filter($tag);
341+
$includeNone = true;
342+
}
337343

338344
$subQuery = $db->getQuery(true)
339345
->select('DISTINCT ' . $db->quoteName('content_item_id'))
@@ -346,17 +352,51 @@ protected function getListQuery()
346352
);
347353

348354
$query->join(
349-
'INNER',
355+
$includeNone ? 'LEFT' : 'INNER',
350356
'(' . $subQuery . ') AS ' . $db->quoteName('tagmap'),
351357
$db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id')
352358
)
359+
->bind(':typeAlias', $typeAlias);
360+
361+
if ($includeNone) {
362+
$subQuery2 = $db->getQuery(true)
363+
->select('DISTINCT ' . $db->quoteName('content_item_id'))
364+
->from($db->quoteName('#__contentitem_tag_map'))
365+
->where($db->quoteName('type_alias') . ' = :typeAlias2');
366+
$query->join(
367+
'LEFT',
368+
'(' . $subQuery2 . ') AS ' . $db->quoteName('tagmap2'),
369+
$db->quoteName('tagmap2.content_item_id') . ' = ' . $db->quoteName('a.id')
370+
)
371+
->where(
372+
'(' . $db->quoteName('tagmap.content_item_id') . ' IS NOT NULL OR '
373+
. $db->quoteName('tagmap2.content_item_id') . ' IS NULL)'
374+
)
375+
->bind(':typeAlias2', $typeAlias);
376+
}
377+
} elseif (is_numeric($tag)) {
378+
$tag = (int) $tag;
379+
380+
if ($tag === 0) {
381+
$subQuery = $db->getQuery(true)
382+
->select('DISTINCT ' . $db->quoteName('content_item_id'))
383+
->from($db->quoteName('#__contentitem_tag_map'))
384+
->where($db->quoteName('type_alias') . ' = :typeAlias');
385+
386+
// Only show categories without tags
387+
$query->join(
388+
'LEFT',
389+
'(' . $subQuery . ') AS ' . $db->quoteName('tagmap'),
390+
$db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id')
391+
)
392+
->where($db->quoteName('tagmap.content_item_id') . ' IS NULL')
353393
->bind(':typeAlias', $typeAlias);
354-
} elseif ($tag = (int) $tag) {
355-
$query->join(
356-
'INNER',
357-
$db->quoteName('#__contentitem_tag_map', 'tagmap'),
358-
$db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id')
359-
)
394+
} else {
395+
$query->join(
396+
'INNER',
397+
$db->quoteName('#__contentitem_tag_map', 'tagmap'),
398+
$db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id')
399+
)
360400
->where(
361401
[
362402
$db->quoteName('tagmap.tag_id') . ' = :tag',
@@ -365,6 +405,7 @@ protected function getListQuery()
365405
)
366406
->bind(':tag', $tag, ParameterType::INTEGER)
367407
->bind(':typeAlias', $typeAlias);
408+
}
368409
}
369410

370411
// Add the list ordering clause

0 commit comments

Comments
 (0)