Answer the question
In order to leave comments, you need to log in
How to select resources by multiple TV fields?
Hello!
Tell me how to select resources from the parent folder by several TV fields?
I can’t figure out how to adapt this code, which works fine for selecting one field:
$where = $modx->newQuery('modResource');
$where->leftJoin('modTemplateVarResource', 'TemplateVarResources');
$where->leftJoin('modTemplateVar', 'tv', "tv.id=TemplateVarResources.tmplvarid");
$where->limit(5);// Лимит
$where->where(array(
array(
'tv.name' => 'tags', // Имя TV
'TemplateVarResources.value' => 'modx',// Значение TV
'parent' => '1'// Родитель
)
));
$resources = $modx->getCollection('modResource',$where);
foreach ($resources as $id => $res) {
$output .= '<p>['.$id.'] => '.$res->get('pagetitle').'</p>';
}
return $output;
));
$resources = $modx->getCollection('modResource',$where);
if (is_array($resources)) {
$output = '';
$request_objects_array = array();
$departmentToEntries = array();
$count_request = 1;
foreach ($resources as $request_object) {
$searhed_object = $modx->getObject('modResource',$request_object->get('id'));
$department_name = $searhed_object->getTVValue('RequestDepartment');
$departmentToEntries[$department_name] = array('department_name' => $department_name, 'entries' => array());
$departmentToEntries[$department_name]['entries'][$request_object->get('id')]['position'] = $count_request;
$departmentToEntries[$department_name]['entries'][$request_object->get('id')]['id'] = $request_object->get('id');
$departmentToEntries[$department_name]['entries'][$request_object->get('id')]['pagetitle'] = $request_object->get('pagetitle');
$departmentToEntries[$department_name]['entries'][$request_object->get('id')]['user'] = $request_object->getTVValue('RequestUser');
$departmentToEntries[$department_name]['entries'][$request_object->get('id')]['department'] = $request_object->getTVValue('RequestDepartment');
$departmentToEntries[$department_name]['entries'][$request_object->get('id')]['status'] = $request_object->getTVValue('RequestStatus');
$departmentToEntries[$department_name]['entries'][$request_object->get('id')]['archive'] = $request_object->getTVValue('RequestArchive');
$departmentToEntries[$department_name]['entries'][$request_object->get('id')]['comment'] = $request_object->getTVValue('RequestComment');
$count_request++;
}
echo "<pre>";
print_r($departmentToEntries);
foreach ($departmentToEntries as $department) {
$entriesoutput = '';
if (is_array($department['entries'])) {
foreach ($department['entries'] as $entry) {
$entriesoutput .= $modx->getChunk('RequestItemView', $entry);
}
}
$properties = array();
$properties['department'] = $department['department_name'];
$properties['entries'] = $entriesoutput;
$output .= $modx->getChunk('RequestSectionView', $properties);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question