protected function RestfulBase::parseRequestForListSort in RESTful 7
Parses the request to get the sorting options.
Return value
array With the different sorting options.
Throws
5 calls to RestfulBase::parseRequestForListSort()
- RestfulDataProviderCToolsPlugins::getPluginsSortedAndFiltered in plugins/
restful/ RestfulDataProviderCToolsPlugins.php - Gets the plugins filtered and sorted by the request.
- RestfulDataProviderCToolsPlugins::sortMultiCompare in plugins/
restful/ RestfulDataProviderCToolsPlugins.php - Sort plugins by multiple criteria.
- RestfulDataProviderDbQuery::queryForListSort in plugins/
restful/ RestfulDataProviderDbQuery.php - Sort the query for list.
- RestfulDataProviderEFQ::queryForListSort in plugins/
restful/ RestfulDataProviderEFQ.php - Sort the query for list.
- RestfulDataProviderVariable::applyListSort in plugins/
restful/ RestfulDataProviderVariable.php - Sort the list of variables.
File
- plugins/
restful/ RestfulBase.php, line 916 - Contains RestfulBase.
Class
- RestfulBase
- Class \RestfulBase
Code
protected function parseRequestForListSort() {
$request = $this
->getRequest();
$public_fields = $this
->getPublicFields();
if (empty($request['sort'])) {
return array();
}
$url_params = $this
->getPluginKey('url_params');
if (!$url_params['sort']) {
throw new \RestfulBadRequestException('Sort parameters have been disabled in server configuration.');
}
$sorts = array();
foreach (explode(',', $request['sort']) as $sort) {
$direction = $sort[0] == '-' ? 'DESC' : 'ASC';
$sort = str_replace('-', '', $sort);
// Check the sort is on a legal key.
if (empty($public_fields[$sort])) {
throw new RestfulBadRequestException(format_string('The sort @sort is not allowed for this path.', array(
'@sort' => $sort,
)));
}
$sorts[$sort] = $direction;
}
return $sorts;
}