/** * get the list of objects referenced inside another object * @param array | int $p params * @return json response */ public static function getAssociatedObjects($p) { $data = array(); if (is_numeric($p)) { $p = array('id' => $p); } if (empty($p['id']) && empty($p['template_id'])) { return array('success' => true, 'data' => $data, 's' => '1'); } $ids = array(); $template = null; if (!empty($p['id'])) { // SECURITY: check if current user has at least read access to this case if (!Security::canRead($p['id'])) { throw new \Exception(L\get('Access_denied')); } /* select distinct associated case ids from the case */ $obj = new Objects\Object($p['id']); $obj->load(); $template = $obj->getTemplate(); $linearData = $obj->getLinearData(); foreach ($linearData as $f) { $tf = $template->getField($f['name']); if ($tf['type'] == '_objects') { $a = Util\toIntArray(@$f['value']); $ids = array_merge($ids, $a); } } } else { $template = new Objects\Template($p['template_id']); $template->load(); } if (!empty($p['data']) && is_array($p['data'])) { foreach ($p['data'] as $key => $value) { $a = Util\toIntArray($value); $ids = array_merge($ids, $a); } } if ($template) { $templateData = $template->getData(); foreach ($templateData['fields'] as $field) { if (!empty($field['cfg']['value'])) { $a = Util\toIntArray($field['cfg']['value']); $ids = array_merge($ids, $a); } } } $ids = array_unique($ids); if (empty($ids)) { return array('success' => true, 'data' => array()); } /* end of select distinct case ids from the case */ $data = Search::getObjects($ids, 'id,template_id,name,date,status:task_status'); $data = array_values($data); return array('success' => true, 'data' => $data); }