Skip to content

Commit 750e38e

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

File tree

2 files changed

+51
-9
lines changed

2 files changed

+51
-9
lines changed

administrator/components/com_newsfeeds/forms/filter_newsfeeds.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@
6060
mode="nested"
6161
custom="false"
6262
class="js-select-submit-on-change"
63-
/>
63+
default=""
64+
>
65+
<option value="0">JNONE_FILTER</option>
66+
</field>
6467

6568
<field
6669
name="level"

administrator/components/com_newsfeeds/src/Model/NewsfeedsModel.php

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,13 @@ protected function getListQuery()
270270
}
271271

272272
if ($tag && \is_array($tag)) {
273-
$tag = ArrayHelper::toInteger($tag);
273+
$tag = ArrayHelper::toInteger($tag);
274+
$includeNone = false;
275+
276+
if (\in_array(0, $tag)) {
277+
$tag = array_filter($tag);
278+
$includeNone = true;
279+
}
274280

275281
$subQuery = $db->getQuery(true)
276282
->select('DISTINCT ' . $db->quoteName('content_item_id'))
@@ -283,23 +289,56 @@ protected function getListQuery()
283289
);
284290

285291
$query->join(
286-
'INNER',
292+
$includeNone ? 'LEFT' : 'INNER',
287293
'(' . $subQuery . ') AS ' . $db->quoteName('tagmap'),
288294
$db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id')
289295
);
290-
} elseif ($tag = (int) $tag) {
291-
$query->join(
292-
'INNER',
293-
$db->quoteName('#__contentitem_tag_map', 'tagmap'),
294-
$db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id')
295-
)
296+
297+
if ($includeNone) {
298+
$subQuery2 = $db->getQuery(true)
299+
->select('DISTINCT ' . $db->quoteName('content_item_id'))
300+
->from($db->quoteName('#__contentitem_tag_map'))
301+
->where($db->quoteName('type_alias') . ' = ' . $db->quote('com_newsfeeds.newsfeed'));
302+
$query->join(
303+
'LEFT',
304+
'(' . $subQuery2 . ') AS ' . $db->quoteName('tagmap2'),
305+
$db->quoteName('tagmap2.content_item_id') . ' = ' . $db->quoteName('a.id')
306+
)
307+
->where(
308+
'(' . $db->quoteName('tagmap.content_item_id') . ' IS NOT NULL OR '
309+
. $db->quoteName('tagmap2.content_item_id') . ' IS NULL)'
310+
);
311+
}
312+
} elseif (is_numeric($tag)) {
313+
$tag = (int) $tag;
314+
315+
if ($tag === 0) {
316+
$subQuery = $db->getQuery(true)
317+
->select('DISTINCT ' . $db->quoteName('content_item_id'))
318+
->from($db->quoteName('#__contentitem_tag_map'))
319+
->where($db->quoteName('type_alias') . ' = ' . $db->quote('com_newsfeeds.newsfeed'));
320+
321+
// Only show newsfeeds without tags
322+
$query->join(
323+
'LEFT',
324+
'(' . $subQuery . ') AS ' . $db->quoteName('tagmap'),
325+
$db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id')
326+
)
327+
->where($db->quoteName('tagmap.content_item_id') . ' IS NULL');
328+
} else {
329+
$query->join(
330+
'INNER',
331+
$db->quoteName('#__contentitem_tag_map', 'tagmap'),
332+
$db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id')
333+
)
296334
->where(
297335
[
298336
$db->quoteName('tagmap.tag_id') . ' = :tag',
299337
$db->quoteName('tagmap.type_alias') . ' = ' . $db->quote('com_newsfeeds.newsfeed'),
300338
]
301339
)
302340
->bind(':tag', $tag, ParameterType::INTEGER);
341+
}
303342
}
304343

305344
// Add the list ordering clause.

0 commit comments

Comments
 (0)