public function ServicesClientUUIDResourceController::index in Services Client 7.2
Implements ServicesResourceControllerInterface::index().
Overrides ServicesEntityResourceController::index
File
- services_client_services/
includes/ ServicesClientUUIDResourceController.inc, line 89 - Custom controller to allow handling requests with UUIDs.
Class
- ServicesClientUUIDResourceController
- @file Custom controller to allow handling requests with UUIDs.
Code
public function index($entity_type, $fields, $parameters, $page, $pagesize, $sort, $direction) {
// Make sure the pagesize is not too large.
$max_pagesize = variable_get('services_entity_max_pagesize', 100);
$pagesize = $max_pagesize < $pagesize ? $max_pagesize : $pagesize;
// Build an EFQ based on the arguments.
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', $entity_type)
->range($page * $pagesize, $pagesize);
if (!empty($parameters)) {
foreach ($parameters as $field => $value) {
$this
->propertyQueryOperation($entity_type, $query, 'Condition', $field, $value);
}
}
if ($sort != '') {
$direction = $direction == 'DESC' ? 'DESC' : 'ASC';
// Ensure a valid direction
$this
->propertyQueryOperation($entity_type, $query, 'OrderBy', $sort, $direction);
}
$result = $query
->execute();
if (empty($result)) {
return services_error(t('No entities found.'), 404);
}
// Convert to actual entities.
$entities = entity_load($entity_type, array_keys($result[$entity_type]));
foreach ($entities as $id => $entity) {
$access = entity_access('view', $entity_type, $entity);
if ($access !== FALSE) {
// Users get special treatment to remove sensitive data.
if ($entity_type == 'user') {
// Use the helper that Services module already has.
services_remove_user_data($entity);
}
$return[] = $this
->limit_fields($entity, $fields);
}
}
// The access check may have resulted in there being no entities left.
if (empty($return)) {
return services_error(t('No entities found.'), 404);
}
return $return;
}