function makeCriteriaCompany($value) { $sql = array(); $projects = Project::getMany(array('company_id' => $value)); if ($projects) { $project_ids = array(); $sql[] = $this->makeCriteriaProject(array_map(function ($item) { return $item->id; }, $projects)); } $support_contracts = SupportContract::getMany(array('company_id' => $value)); if ($support_contracts) { $sql[] = $this->makeCriteriaSupportContract(array_map(function ($item) { return $item->id; }, $support_contracts)); } return '(' . implode(' or ', $sql) . ') '; }