/** * API Method queries for Search records and render as JSON */ public function Query() { try { $criteria = new SearchCriteria(); // TODO: this will limit results based on all properties included in the filter list $filter = RequestUtil::Get('filter'); if ($filter) { $criteria->AddFilter(new CriteriaFilter('Idsearch,User,Name,Info,Type,Datecreate', '%' . $filter . '%')); } // TODO: this is generic query filtering based only on criteria properties foreach (array_keys($_REQUEST) as $prop) { $prop_normal = ucfirst($prop); $prop_equals = $prop_normal . '_Equals'; if (property_exists($criteria, $prop_normal)) { $criteria->{$prop_normal} = RequestUtil::Get($prop); } elseif (property_exists($criteria, $prop_equals)) { // this is a convenience so that the _Equals suffix is not needed $criteria->{$prop_equals} = RequestUtil::Get($prop); } } $output = new stdClass(); // if a sort order was specified then specify in the criteria $output->orderBy = RequestUtil::Get('orderBy'); $output->orderDesc = RequestUtil::Get('orderDesc') != ''; if ($output->orderBy) { $criteria->SetOrder($output->orderBy, $output->orderDesc); } $page = RequestUtil::Get('page'); if ($page != '') { // if page is specified, use this instead (at the expense of one extra count query) $pagesize = $this->GetDefaultPageSize(); $searches = $this->Phreezer->Query('Search', $criteria)->GetDataPage($page, $pagesize); $output->rows = $searches->ToObjectArray(true, $this->SimpleObjectParams()); $output->totalResults = $searches->TotalResults; $output->totalPages = $searches->TotalPages; $output->pageSize = $searches->PageSize; $output->currentPage = $searches->CurrentPage; } else { // return all results $searches = $this->Phreezer->Query('Search', $criteria); $output->rows = $searches->ToObjectArray(true, $this->SimpleObjectParams()); $output->totalResults = count($output->rows); $output->totalPages = 1; $output->pageSize = $output->totalResults; $output->currentPage = 1; } $this->RenderJSON($output, $this->JSONPCallback()); } catch (Exception $ex) { $this->RenderExceptionJSON($ex); } }