Exemplo n.º 1
0
 /**
  * If the provider does not perform the paging (ordering, top, skip) then this method does it
  *
  * @param array $result
  * @return array
  */
 private function performPaging(array $result)
 {
     //Apply (implicit and explicit) $orderby option
     $internalOrderByInfo = $this->request->getInternalOrderByInfo();
     if (!is_null($internalOrderByInfo)) {
         $orderByFunction = $internalOrderByInfo->getSorterFunction()->getReference();
         usort($result, $orderByFunction);
     }
     //Apply $skiptoken option
     $internalSkipTokenInfo = $this->request->getInternalSkipTokenInfo();
     if (!is_null($internalSkipTokenInfo)) {
         $matchingIndex = $internalSkipTokenInfo->getIndexOfFirstEntryInTheNextPage($result);
         $result = array_slice($result, $matchingIndex);
     }
     //Apply $top and $skip option
     if (!empty($result)) {
         $top = $this->request->getTopCount();
         $skip = $this->request->getSkipCount();
         if (is_null($skip)) {
             $skip = 0;
         }
         $result = array_slice($result, $skip, $top);
     }
     return $result;
 }