protected function RestWSBaseFormat::generateQueryURIs in RESTful Web Services 7.2
Generates all navigation links for querying.
Parameters
RestWSResourceControllerInterface $resourceController: The controller used to query the resource.
array $parameters: The HTTP GET parameters for the query.
array $filters: The filters for the query.
Return value
array An array containing all navigation links.
Throws
RestWSException If the page is out of range the function will throw a new RestWSException with HTTP status code 404.
2 calls to RestWSBaseFormat::generateQueryURIs()
- RestWSBaseFormat::queryResource in ./
restws.formats.inc - Implements RestWSFormatInterface::queryResource().
- RestWSFormatXML::queryResource in ./
restws.formats.inc - Overrides RestWSBaseFormat::queryResource().
File
- ./
restws.formats.inc, line 402 - RESTful web services module formats.
Class
- RestWSBaseFormat
- A base for all simple formats that are just serializing/unserializing an array of property values.
Code
protected function generateQueryURIs(RestWSResourceControllerInterface $resourceController, array $parameters, array $filters) {
$rest_controls = restws_meta_controls();
$count = $resourceController
->count($filters);
$limit = isset($parameters[$rest_controls['limit']]) ? $parameters[$rest_controls['limit']] : NULL;
$limit = $resourceController
->limit($limit);
$page = isset($parameters[$rest_controls['page']]) ? $parameters[$rest_controls['page']] : 0;
$last = floor($count / $limit);
if ($page > $last || $page < 0) {
throw new RestWSException('Page doesn\'t exist.', 404);
}
$uris = array();
$options = array(
'query' => &$parameters,
);
$uris['self'] = restws_resource_uri($resourceController
->resource(), NULL, $options);
$parameters['page'] = 0;
$uris['first'] = restws_resource_uri($resourceController
->resource(), NULL, $options);
$parameters['page'] = $last;
$uris['last'] = restws_resource_uri($resourceController
->resource(), NULL, $options);
if ($page != 0) {
$parameters['page'] = $page - 1;
$uris['prev'] = restws_resource_uri($resourceController
->resource(), NULL, $options);
}
if ($page != $last) {
$parameters['page'] = $page + 1;
$uris['next'] = restws_resource_uri($resourceController
->resource(), NULL, $options);
}
return $uris;
}