Find out if there are resources where the ID of the current resource can be found inside TV with comma separeated values.
<?php
/*
DESCRIPTION:
------------
Find out if there are resources where the ID of the current resource
can be found inside TV with comma separeated values.
Usefull for teaching getResources a new trick.
USAGE:
---------
[[!ppb_inArray? &id=`[[*id]]` &parents=`612` &tvId=`107` &ph=`neubauIds`]]
PARAMETERS:
-----------
&id = id of a resource
&parents = one or more parent IDs seperated by a comma.
&tvID = the id of the id containing the values.
&ph = the name of a plceholder that can be inserted into getResourcesto process the results.
[[!getResources?
&parents=`-1`
&resources=`[[+results]]`
...
]]
*/
<?php
$msg = array();
$kontextlinks = array();
$tvId = !empty($tvId) ? $tvId : 107;
$id = !empty($id) ? $id : false;
$parent = !empty($parent) ? $parent : false;
$ph = !empty($ph) ? $ph : 'ph';
if(!$parents OR !$id) return;
$parents = explode(',',$parents);
$childIds = array();
foreach($parents as $parent){
$childIds = array_merge($childIds, $modx->getChildIds($parent));
}
//return print_r($childIds,true);
$tv = $modx->getObject('modTemplateVar', $tvId);
if ($tv) {
foreach ($childIds as $childId) {
$renderedValue = $tv->renderOutput($childId);
$msg['childId_'.$childId] = $renderedValue;
$values = explode(',' , $renderedValue);
if(in_array($id,$values)){
$kontext[] = $childId;
}
}
} else {
$msg['error'] = "TV not found";
}
$kontext = implode(',' , $kontext);
$modx->setPlaceholder($ph,$kontext);
return;
return $kontext;
//return "<pre>".print_r($msg,true)."</pre>";