예제 #1
0
 /**
  * Process the $expand and $select option and update the request description.
  * 
  * @return void
  * 
  * @throws ODataException Throws bad request error in the following cases
  *                          (1) If $expand or select cannot be applied to the
  *                              requested resource.
  *                          (2) If projection is disabled by the developer
  *                          (3) If some error occurs while parsing the options
  */
 private function _processExpandAndSelect()
 {
     $expand = $this->service->getHost()->getQueryStringItem(ODataConstants::HTTPQUERY_STRING_EXPAND);
     if (!is_null($expand)) {
         $this->_checkExpandOrSelectApplicable(ODataConstants::HTTPQUERY_STRING_EXPAND);
     }
     $select = $this->service->getHost()->getQueryStringItem(ODataConstants::HTTPQUERY_STRING_SELECT);
     if (!is_null($select)) {
         if (!$this->service->getConfiguration()->getAcceptProjectionRequests()) {
             throw ODataException::createBadRequestError(Messages::configurationProjectionsNotAccepted());
         }
         $this->_checkExpandOrSelectApplicable(ODataConstants::HTTPQUERY_STRING_SELECT);
     }
     // We will generate RootProjectionNode in case of $link request also, but
     // expand and select in this case must be null (we are ensuring this above)
     // 'RootProjectionNode' is required while generating next page Link
     if ($this->_expandSelectApplicable || $this->request->isLinkUri()) {
         $rootProjectionNode = ExpandProjectionParser::parseExpandAndSelectClause($this->request->getTargetResourceSetWrapper(), $this->request->getTargetResourceType(), $this->request->getInternalOrderByInfo(), $this->request->getSkipCount(), $this->request->getTopCount(), $expand, $select, $this->service->getProvidersWrapper());
         if ($rootProjectionNode->isSelectionSpecified()) {
             $this->request->raiseMinVersionRequirement(2, 0);
         }
         if ($rootProjectionNode->hasPagedExpandedResult()) {
             $this->request->raiseResponseVersion(2, 0);
         }
         $this->request->setRootProjectionNode($rootProjectionNode);
     }
 }
예제 #2
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;
 }
예제 #3
0
 /**
  * Builds the string corresponding to query parameters for top level results 
  * (result set identified by the resource path) to be put in next page link.
  * 
  * @return string|null string representing the query parameters in the URI 
  *                     query parameter format, NULL if there 
  *                     is no query parameters
  *                     required for the next link of top level result set.
  */
 protected function getNextPageLinkQueryParametersForRootResourceSet()
 {
     $queryParameterString = null;
     foreach (array(ODataConstants::HTTPQUERY_STRING_FILTER, ODataConstants::HTTPQUERY_STRING_EXPAND, ODataConstants::HTTPQUERY_STRING_ORDERBY, ODataConstants::HTTPQUERY_STRING_INLINECOUNT, ODataConstants::HTTPQUERY_STRING_SELECT) as $queryOption) {
         $value = $this->service->getHost()->getQueryStringItem($queryOption);
         if (!is_null($value)) {
             if (!is_null($queryParameterString)) {
                 $queryParameterString = $queryParameterString . '&';
             }
             $queryParameterString .= $queryOption . '=' . $value;
         }
     }
     $topCountValue = $this->request->getTopOptionCount();
     if (!is_null($topCountValue)) {
         $remainingCount = $topCountValue - $this->request->getTopCount();
         if (!is_null($queryParameterString)) {
             $queryParameterString .= '&';
         }
         $queryParameterString .= ODataConstants::HTTPQUERY_STRING_TOP . '=' . $remainingCount;
     }
     if (!is_null($queryParameterString)) {
         $queryParameterString .= '&';
     }
     return $queryParameterString;
 }