Skip to content

Commit a0d6375

Browse files
authored
[5.4] Add tag filter none com_contact (#45459)
New '- None -' tag filter option in the contacts view --------- Signed-off-by: BrianTeeman <[email protected]>
1 parent 8f6a981 commit a0d6375

File tree

2 files changed

+51
-9
lines changed

2 files changed

+51
-9
lines changed

administrator/components/com_contact/forms/filter_contacts.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@
7474
custom="false"
7575
hint="JOPTION_SELECT_TAG"
7676
class="js-select-submit-on-change"
77-
/>
77+
default=""
78+
>
79+
<option value="0">JNONE_FILTER</option>
80+
</field>
7881

7982
<field
8083
name="level"

administrator/components/com_contact/src/Model/ContactsModel.php

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

285285
if ($tag && \is_array($tag)) {
286-
$tag = ArrayHelper::toInteger($tag);
286+
$tag = ArrayHelper::toInteger($tag);
287+
$includeNone = false;
288+
289+
if (\in_array(0, $tag)) {
290+
$tag = array_filter($tag);
291+
$includeNone = true;
292+
}
287293

288294
$subQuery = $db->getQuery(true)
289295
->select('DISTINCT ' . $db->quoteName('content_item_id'))
@@ -296,23 +302,56 @@ protected function getListQuery()
296302
);
297303

298304
$query->join(
299-
'INNER',
305+
$includeNone ? 'LEFT' : 'INNER',
300306
'(' . $subQuery . ') AS ' . $db->quoteName('tagmap'),
301307
$db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id')
302308
);
303-
} elseif ($tag = (int) $tag) {
304-
$query->join(
305-
'INNER',
306-
$db->quoteName('#__contentitem_tag_map', 'tagmap'),
307-
$db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id')
308-
)
309+
310+
if ($includeNone) {
311+
$subQuery2 = $db->getQuery(true)
312+
->select('DISTINCT ' . $db->quoteName('content_item_id'))
313+
->from($db->quoteName('#__contentitem_tag_map'))
314+
->where($db->quoteName('type_alias') . ' = ' . $db->quote('com_contact.contact'));
315+
$query->join(
316+
'LEFT',
317+
'(' . $subQuery2 . ') AS ' . $db->quoteName('tagmap2'),
318+
$db->quoteName('tagmap2.content_item_id') . ' = ' . $db->quoteName('a.id')
319+
)
320+
->where(
321+
'(' . $db->quoteName('tagmap.content_item_id') . ' IS NOT NULL OR '
322+
. $db->quoteName('tagmap2.content_item_id') . ' IS NULL)'
323+
);
324+
}
325+
} elseif (is_numeric($tag)) {
326+
$tag = (int) $tag;
327+
328+
if ($tag === 0) {
329+
$subQuery = $db->getQuery(true)
330+
->select('DISTINCT ' . $db->quoteName('content_item_id'))
331+
->from($db->quoteName('#__contentitem_tag_map'))
332+
->where($db->quoteName('type_alias') . ' = ' . $db->quote('com_contact.contact'));
333+
334+
// Only show contacts without tags
335+
$query->join(
336+
'LEFT',
337+
'(' . $subQuery . ') AS ' . $db->quoteName('tagmap'),
338+
$db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id')
339+
)
340+
->where($db->quoteName('tagmap.content_item_id') . ' IS NULL');
341+
} else {
342+
$query->join(
343+
'INNER',
344+
$db->quoteName('#__contentitem_tag_map', 'tagmap'),
345+
$db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id')
346+
)
309347
->where(
310348
[
311349
$db->quoteName('tagmap.tag_id') . ' = :tag',
312350
$db->quoteName('tagmap.type_alias') . ' = ' . $db->quote('com_contact.contact'),
313351
]
314352
)
315353
->bind(':tag', $tag, ParameterType::INTEGER);
354+
}
316355
}
317356

318357
// Filter by categories and by level

0 commit comments

Comments
 (0)