I’m trying to display all resources from a Tagger Group by adding this to a pdoResources snippet:
&where=`[[!TaggerGetResourcesWhere?
&groups=`3`
]]`
But no luck : ( Maybe I am missing something obvious?
I’m trying to display all resources from a Tagger Group by adding this to a pdoResources snippet:
&where=`[[!TaggerGetResourcesWhere?
&groups=`3`
]]`
But no luck : ( Maybe I am missing something obvious?
No, this just doesn’t work like this.
Either list all the tags in the group in the property &tags
or write your own snippet (as a replacement for TaggerGetResourcesWhere) that queries all the tags in the group and creates the correct subquery ("EXISTS (SELECT 1 FROM `modx_tagger_tag_resources` r WHERE ...)"
) for pdoResources.
I see, thanks!
Would you happen to know what the custom mySQL query for this would be? I presume you can then just do this inside pdoResources?
&where=`("EXISTS (SELECT 1 FROM `modx_tagger_tag_resources` r WHERE ...)")`
Maybe this snippet code does what you want:
<?php
$tagger = $modx->getService('tagger','Tagger',$modx->getOption('tagger.core_path',null,$modx->getOption('core_path').'components/tagger/').'model/tagger/',$scriptProperties);
if (!($tagger instanceof Tagger)) return '';
$field = $modx->getOption('field', $scriptProperties, 'id');
$where = $modx->getOption('where', $scriptProperties, '');
$where = $modx->fromJSON($where);
if ($where == false) {
$where = array();
}
$groups = $modx->getOption('groups', $scriptProperties, '');
$groups = $tagger->explodeAndClean($groups);
$c = $modx->newQuery('TaggerTag');
$c->select($modx->getSelectColumns('TaggerTag', 'TaggerTag', '', array('id')));
$c->leftJoin('TaggerGroup', 'Group');
$c->where(array(
'Group.id:IN' => $groups,
'OR:Group.name:IN' => $groups,
'OR:Group.alias:IN' => $groups,
));
$c->prepare();
$c->stmt->execute();
$tagIDs = $c->stmt->fetchAll(PDO::FETCH_COLUMN, 0);
if (count($tagIDs) == 0) {
$tagIDs[] = 0;
}
$where[] = "EXISTS (SELECT 1 FROM {$modx->getTableName('TaggerTagResource')} r WHERE r.tag IN (" . implode(',', $tagIDs) . ") AND r.resource = modResource." . $field . ")";
return $modx->toJSON($where);