public function dosearch($type, $max, $q, $basic) { //search in oim $model = new OIMSearch(); $recs = array(); if ($type == "all" || $type == "resource") { foreach ($model->search_resource($q) as $rec) { $rec->type = "resource"; if (!$basic) { //pull resource for each resource (and group by contact type) $rcmodel = new ResourceContact(); $contacts = $rcmodel->get(array("resource_id" => $rec->id)); $rec->contacts = array(); foreach ($contacts as $contact) { if (!isset($rec->contacts[$contact->contact_type])) { $rec->contacts[$contact->contact_type] = array(); } $rec->contacts[$contact->contact_type][] = $contact; } } $recs[] = $rec; } } if (count($recs) > $max) { return $recs; } if ($type == "all" || $type == "resource_group") { foreach ($model->search_resourcegroup($q) as $rec) { $rec->type = "resource_group"; $recs[] = $rec; } } if (count($recs) > $max) { return $recs; } if ($type == "all" || $type == "site") { foreach ($model->search_site($q) as $rec) { $rec->type = "site"; $recs[] = $rec; } } if (count($recs) > $max) { return $recs; } if ($type == "all" || $type == "facility") { foreach ($model->search_facility($q) as $rec) { $rec->type = "facility"; $recs[] = $rec; } } if (count($recs) > $max) { return $recs; } if ($type == "all" || $type == "vo") { foreach ($model->search_vo($q) as $rec) { $rec->type = "vo"; if (!$basic) { $vomodel = new VOContact(); $contacts = $vomodel->get(array("vo_id" => $rec->id)); $rec->contacts = array(); foreach ($contacts as $contact) { if (!isset($rec->contacts[$contact->contact_type])) { $rec->contacts[$contact->contact_type] = array(); } $rec->contacts[$contact->contact_type][] = $contact; } } $recs[] = $rec; } } if (count($recs) > $max) { return $recs; } if ($type == "all" || $type == "sc") { foreach ($model->search_sc($q) as $rec) { $rec->type = "sc"; if (!$basic) { $scmodel = new SupportCenterContact(); $contacts = $scmodel->get(array("sc_id" => $rec->id)); $rec->contacts = array(); foreach ($contacts as $contact) { if (!isset($rec->contacts[$contact->contact_type])) { $rec->contacts[$contact->contact_type] = array(); } $rec->contacts[$contact->contact_type][] = $contact; } } $recs[] = $rec; } } if (count($recs) > $max) { return $recs; } if ($type == "all" || $type == "project") { foreach ($model->search_project($q) as $rec) { $rec->type = "project"; $recs[] = $rec; } } if (count($recs) > $max) { return $recs; } //contact information is only for non-guest if (!user()->isGuest()) { if ($type == "all" || $type == "contact") { foreach ($model->search_contact($q) as $rec) { $rec->type = "contact"; $recs[] = $rec; } } } //search goc ticket if (!$basic) { if ($type == "all" || $type == "gocticket") { $xml = new SimpleXMLElement(file_get_contents(config()->gocticket_url . "/rest/search?q=" . urlencode($q))); $sorted = array(); foreach ($xml->Tickets->Ticket as $ticket) { $ticket->type = "gocticket"; $ticket_id = (int) $ticket->ID; $sorted[$ticket_id] = $ticket; } krsort($sorted); foreach ($sorted as $ticket) { $recs[] = $ticket; } } } return $recs; }