Hi!
Long time lurker, first time poster. I've been able to pretty much answer 99% of my modx questions by just searching the forum but I've come to a bit of stop with the question in the title.
I'm a junior web developer and I'm still getting my head around how modx works, so if you think I'm doing something wrong, than please tell me!
This is my snippet call
[[!getOptions? &parents=`232` &name=`ScholarCollege` &"noEmptySchools" => $noEmptySchools=`1`]]
(I've missed a few steps, basically it's fed through another snippet and chunk which creates the <select> <option> nothing really important)
and this is my snippet getOptions
<?php
//Set resource ids to include
$resources = !empty($resources) ? $resources : false;
//Set parent resources to search within
$parents = !empty($parents) ? $parents : false;
//Set whether or not to include resources that are containers
$includeContainers = !empty($includeContainers) ? $includeContainers : 0;
//Set whether or not to include resources that have been deleted
$includeDeleted = !empty($includeDeleted) ? $includeDeleted : 0;
//Set whether or not to include resources that have been deleted
$options = !empty($options) ? $options : false;
if(!$options) {
//Create object for resource
$query = $modx->newQuery('modResource');
//Get children of resource
if($parents) {
$parentsArray = explode(',',$parents);
$query->where(array('OR:modResource.parent:IN' => $parentsArray), xPDOQuery::SQL_OR);
}
//Get resources
if($resources) {
$resourcesArray = explode(',',$resources);
$query->where(array('OR:modResource.id:IN' => $resourcesArray), xPDOQuery::SQL_OR);
}
//build remaining conditions
$query->where(array(
//'parent' => $parents,
'isfolder' => $includeContainers,
'deleted' => $includeDeleted,
));
//sort by page title
$query->sortby('pagetitle','ASC');
$options = $modx->getCollection('modResource',$query);
}
$optionList = '';
foreach ($options as $item):
if($excludeEmptyParents):
if($item->hasChildren('id')):
$optionList .= $item->get('pagetitle') . "==" . $item->get('id') . "||";
endif;
else:
$optionList .= $item->get('pagetitle') . "==" . $item->get('id') . "||";
endif;
#if($noEmptySchools):
#$optionList .= $item->getTVValue($item->get('id')). "==" . $item->getTVValue('id') . "||";
#endif;
endforeach;
$optionList = substr($optionList, 0, -2);
return $optionList;
Basically, the code is pretty straight forward, I'm building a list of resources from a given parent ID and then fed them into a select item, the resourceid is the value of the select item and the page name is the title of the select item.
I'm using the snippet for a few things (hence why there's "excludeEmptyParents", you can ignore that).
The part I'm interested in is the lines 48-50.
I want to check if the ID of the resource in the select item, exists as a value in the template variable table, if a template variable with the value of that resource ID exists then I want to show it in the drop down boxes, if it doesn't exist then I don't want it to be visible.
What would be the best approach to do such a task? I have searched and I haven't anything which matches what I'm trying to achieve (Although maybe I have and I'm just to blind to see).
If anyway has any input on the subject I would be forever grateful!
Thanks!
Kingsley