Beispiel #1
0
 /**
  * API Method queries for Evento records and render as JSON
  */
 public function Query()
 {
     try {
         $criteria = new EventoCriteria();
         // TODO: this will limit results based on all properties included in the filter list
         $filter = RequestUtil::Get('filter');
         if ($filter) {
             $criteria->AddFilter(new CriteriaFilter('IdEvento,Nome,Local,Data,Duracao', '%' . $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();
             $eventos = $this->Phreezer->Query('Evento', $criteria)->GetDataPage($page, $pagesize);
             $output->rows = $eventos->ToObjectArray(true, $this->SimpleObjectParams());
             $output->totalResults = $eventos->TotalResults;
             $output->totalPages = $eventos->TotalPages;
             $output->pageSize = $eventos->PageSize;
             $output->currentPage = $eventos->CurrentPage;
         } else {
             // return all results
             $eventos = $this->Phreezer->Query('Evento', $criteria);
             $output->rows = $eventos->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);
     }
 }