From 20f52212cacf84309f95ec69ad554bc6cced78cc Mon Sep 17 00:00:00 2001 From: Kookabura Date: Sat, 28 Jan 2017 16:29:32 +0300 Subject: [PATCH] Tags for non default resource class It's good to have an ability to use tags for custom classes. I've added parameter $class for that. --- .../elements/snippets/taggergetresourceswhere.snippet.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core/components/tagger/elements/snippets/taggergetresourceswhere.snippet.php b/core/components/tagger/elements/snippets/taggergetresourceswhere.snippet.php index 7f43036..de3ad85 100644 --- a/core/components/tagger/elements/snippets/taggergetresourceswhere.snippet.php +++ b/core/components/tagger/elements/snippets/taggergetresourceswhere.snippet.php @@ -15,6 +15,7 @@ * &tagField string optional Field that will be used to compare with given tags. Default: alias * &matchAll int optional If set to 1, resource must have all specified tags. Default: 0 * &field string optional modResource field that will be used to compare with assigned resource ID + * &class string optional * * USAGE: * @@ -32,6 +33,7 @@ $matchAll = (int) $modx->getOption('matchAll', $scriptProperties, 0); $field = $modx->getOption('field', $scriptProperties, 'id'); $where = $modx->fromJSON($where); +$class = $modx->getOption('class', $scriptProperties, 'modResource'); if ($where == false) { $where = array(); } @@ -133,9 +135,9 @@ } if ($matchAll == 0) { - $where[] = "EXISTS (SELECT 1 FROM {$modx->getTableName('TaggerTagResource')} r WHERE r.tag IN (" . implode(',', $tagIDs) . ") AND r.resource = modResource." . $field . ")"; + $where[] = "EXISTS (SELECT 1 FROM {$modx->getTableName('TaggerTagResource')} r WHERE r.tag IN (" . implode(',', $tagIDs) . ") AND r.resource = ".$class."." . $field . ")"; } else { - $where[] = "EXISTS (SELECT 1 as found FROM {$modx->getTableName('TaggerTagResource')} r WHERE r.tag IN (" . implode(',', $tagIDs) . ") AND r.resource = modResource." . $field . " GROUP BY found HAVING count(found) = " . $tagsCount . ")"; + $where[] = "EXISTS (SELECT 1 as found FROM {$modx->getTableName('TaggerTagResource')} r WHERE r.tag IN (" . implode(',', $tagIDs) . ") AND r.resource = ".$class."." . $field . " GROUP BY found HAVING count(found) = " . $tagsCount . ")"; } -return $modx->toJSON($where); \ No newline at end of file +return $modx->toJSON($where);