/** * 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->_dataService->getHost()->getQueryStringItem(ODataConstants::HTTPQUERY_STRING_ORDERBY); if (!is_null($orderBy)) { $this->_checkSetQueryApplicable(); } $targetResourceType = $this->_requestDescription->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->_requestDescription->getSkipCount()) || !is_null($this->_requestDescription->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)) { try { $internalOrderByInfo = OrderByParser::parseOrderByClause($this->_requestDescription->getTargetResourceSetWrapper(), $targetResourceType, $orderBy, $this->_dataService->getMetadataQueryProviderWrapper()); $this->_requestDescription->setInternalOrderByInfo($internalOrderByInfo); } catch (ODataException $odataException) { throw $odataException; } } }