Skip to content

Instantly share code, notes, and snippets.

@denysbutenko
Created February 4, 2013 05:20
Show Gist options
  • Save denysbutenko/f164e92f2d205478bc12 to your computer and use it in GitHub Desktop.
Save denysbutenko/f164e92f2d205478bc12 to your computer and use it in GitHub Desktop.
getAllTVs
<?php
$pdoFetch = $modx->getService('pdofetch','pdoFetch',$modx->getOption('pdotools.core_path',null,$modx->getOption('core_path').'components/pdotools/').'model/pdotools/',$scriptProperties);
if (!($pdoFetch instanceof pdoFetch)) return '';
$where = array(
'contentid' => $modx->resource->id
);
if (!empty($excludeTVs)) {
$where['mTV.id:NOT IN'] = explode(',',$excludeTVs);
}
if(empty($templateid)){
$templateid = $modx->resource->template;
}
$default = array(
'class' => 'modTemplateVarResource'
,'where' => json_encode($where)
,'leftJoin' => '[
{"class":"modTemplateVarTemplate","alias":"mTVT","on":"mTVT.tmplvarid=modTemplateVarResource.tmplvarid AND mTVT.templateid='.$templateid.'"}
,{"class":"modTemplateVar","alias":"mTV","on":"mTV.id=mTVT.tmplvarid"}
]'
,'select' => '{
"modTemplateVarResource":"all"
,"mTV":"mTV.caption,mTV.rank"
}'
,'sortby' => 'rank'
,'sortdir' => 'asc'
,'limit' => $limit
,'fastMode' => false
,'return' => 'data'
);
$pdoFetch->config = array_merge($pdoFetch->config, $default, $scriptProperties);
$pdoFetch->config['tplOuter'] = $tplOuter;
$rows = $pdoFetch->run();
$output = null;
foreach ($rows as $k => $v) {
foreach ($v as $field => $value) {
$v[$field] = $value;
}
if (empty($pdoFetch->config['tpl'])) {
$output[] = '<pre>'.print_r($v, true).'</pre>';
}
else {
$output[] = $pdoFetch->getChunk($pdoFetch->config['tpl'], $v, $pdoFetch->config['fastMode']);
}
}
$pdoFetch->addTime('Returning processed chunks');
if (!empty($output)) {
$output = implode($pdoFetch->config['outputSeparator'], $output);
if(!emprty($pdoFetch->config['tplOuter'])){
$output = $pdoFetch->getChunk($pdoFetch->config['tplOuter'], array('rows' => $output), $pdoFetch->config['fastMode']);
}
}
if ($modx->user->hasSessionContext('mgr')) {
$output .= '<pre>' . print_r($pdoFetch->getTime(), 1) . '</pre>';
}
$pdoFetch->timings = array();
return $output;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment