Skip to content

Instantly share code, notes, and snippets.

@qwertik17
Created June 17, 2020 06:54
Show Gist options
  • Save qwertik17/f49cd4f83a0edbee890b5606c553f4aa to your computer and use it in GitHub Desktop.
Save qwertik17/f49cd4f83a0edbee890b5606c553f4aa to your computer and use it in GitHub Desktop.
Получаем все уникальные значения ТВ во всех ресурсах
<?php
$res = array();
$q = $modx->newQuery('modTemplateVarResource', array('tmplvarid' => $tv_id));
$template_id = 28;
$template_id = explode(',',$template_id);
$q->innerJoin('modResource', 'modResource', "modResource.id = modTemplateVarResource.contentid");
$q->select('contentid,value,modResource.template');
$q->where(array(
'modResource.template:IN' => $template_id,
'modResource.published' => 1,
'modResource.deleted' => 0
));
$q->groupby('value');
if ($q->prepare() && $q->stmt->execute()) {
while ($row = $q->stmt->fetch(PDO::FETCH_ASSOC)) {
$res[$row['contentid']] = $row['value'];
}
}
$result = implode('||',$res);
$result = explode('||',$result);
$result = array_unique($result);
$result = implode('||',$result);
return $result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment