Ejemplo n.º 1
0
 /**
  * Process $orderby option, This function requires _processSkipAndTopOption
  * function to be already called as this function need to know whether 
  * client has requested for skip, top or paging is enabled for the 
  * requested resource in these cases function generates additional orderby
  * expression using keys.
  * 
  * @return void
  * 
  * @throws ODataException If any error occurs while parsing orderby option.
  */
 private function _processOrderBy()
 {
     $orderBy = $this->service->getHost()->getQueryStringItem(ODataConstants::HTTPQUERY_STRING_ORDERBY);
     if (!is_null($orderBy)) {
         $this->_checkSetQueryApplicable();
     }
     $targetResourceType = $this->request->getTargetResourceType();
     //assert($targetResourceType != null)
     /**
      * We need to do sorting in the folowing cases, irrespective of 
      * $orderby clause is present or not.
      * 1. If $top or $skip is specified
      *     skip and take will be applied on sorted list only. If $skip 
      *     is specified then RequestDescription::getSkipCount will give 
      *     non-null value. If $top is specified then 
      *     RequestDescription::getTopCount will give non-null value.
      * 2. If server side paging is enabled for the requested resource
      *     If server-side paging is enabled for the requested resource then 
      *     RequestDescription::getTopCount will give non-null value.
      *      
      */
     if (!is_null($this->request->getSkipCount()) || !is_null($this->request->getTopCount())) {
         $orderBy = !is_null($orderBy) ? $orderBy . ', ' : null;
         $keys = array_keys($targetResourceType->getKeyProperties());
         //assert(!empty($keys))
         foreach ($keys as $key) {
             $orderBy = $orderBy . $key . ', ';
         }
         $orderBy = rtrim($orderBy, ', ');
     }
     if (!is_null($orderBy)) {
         $internalOrderByInfo = OrderByParser::parseOrderByClause($this->request->getTargetResourceSetWrapper(), $targetResourceType, $orderBy, $this->service->getProvidersWrapper());
         $this->request->setInternalOrderByInfo($internalOrderByInfo);
     }
 }