I have this custom module that shows all contacts based on some tags. I can add one or more tags in a field in the module
What I want is to add the option in the module to show:
- all contacts that have ALL tags as specified in the module
or
- all contacts that have one or more tags as specified in the module
The code I do have just does the latter. How can I add the possibility for option 1?
The code I do have is:
public static function getPeopleByTags($params)
{
//echo "<pre>";
$tags = $params->get("tags");
$model = JModelLegacy::getInstance('Field', 'FieldsModel', array('ignore_request' => true)); //load fields model
//get people info from database
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('id,catid,name,alias,image,email_to,published,user_id,tags.tag_id');
//$query->select('*');
$query->from($db->quoteName('#__contact_details').'AS contacts');
$query->join('right','#__contentitem_tag_map AS tags ON `tags`.`content_item_id` = `contacts`.`id`');
$query->where($db->quoteName("published") ." = 1 AND `tags`.`type_id` = 2 AND `tags`.`tag_id` IN (".implode(',',$tags).") ");
$query->group('`contacts`.`id`');
$db->setQuery($query);
$people = $db->loadObjectList();
return $people;
}
Joomla 3.9.0
#__contact_details
AS contacts RIGHT JOIN #__contentitem_tag_map AS tags ONtags
.content_item_id
=contacts
.id
WHEREpublished
= 1 ANDtags
.type_id
= 2 ANDtags
.tag_id
IN (45,186) GROUP BYcontacts
.id
I want to change it in showing all contacts with either tag 45 OR 186.