Exemplo n.º 1
0
 /**
  * Applies the query options to the resource(s) retrieved from the data source.
  * 
  * @param SegmentDescriptor $segment The descriptor which holds resource(s) on which query options to be applied.
  *
  */
 private function applyQueryOptions(SegmentDescriptor $segment)
 {
     //TODO: I'm not really happy with this..i think i'd rather keep the result the QueryResult
     //not even bother with the setCountValue stuff (shouldn't counts be on segments?)
     //and just work with the QueryResult in the object model serializer
     $result = $segment->getResult();
     if (!$result instanceof QueryResult) {
         //If the segment isn't a query result, then there's no paging or counting to be done
         return;
     }
     // Note $inlinecount=allpages means include the total count regardless of paging..so we set the counts first
     // regardless if POData does the paging or not.
     if ($this->request->queryType == QueryType::ENTITIES_WITH_COUNT()) {
         if ($this->providers->handlesOrderedPaging()) {
             $this->request->setCountValue($result->count);
         } else {
             $this->request->setCountValue(count($result->results));
         }
     }
     //Have POData perform paging if necessary
     if (!$this->providers->handlesOrderedPaging() && !empty($result->results)) {
         $result->results = $this->performPaging($result->results);
     }
     //a bit surprising, but $skip and $top affects $count so update it here, not above
     //IE  data.svc/Collection/$count?$top=10 returns 10 even if Collection has 11+ entries
     if ($this->request->queryType == QueryType::COUNT()) {
         if ($this->providers->handlesOrderedPaging()) {
             $this->request->setCountValue($result->count);
         } else {
             $this->request->setCountValue(count($result->results));
         }
     }
     $segment->setResult($result->results);
 }