protected function RestWSEntityResourceController::propertyQueryOperation in RESTful Web Services 7.2
Helper function which takes care of distinguishing between fields and entity properties and executes the right EntityFieldQuery function for it.
Parameters
EntityFieldQuery $query: The EntityFieldQuery pointer which should be used.
string $operation: The general function name, without the words 'property' or 'field'.
string $property: The property or field which should be used.
string|array $value: The value for the function.
3 calls to RestWSEntityResourceController::propertyQueryOperation()
- RestWSEntityResourceController::count in ./
restws.entity.inc - Implements RestWSQueryResourceControllerInterface::count().
- RestWSEntityResourceController::nodeAccess in ./
restws.entity.inc - Helper function to respect node permissions while querying.
- RestWSEntityResourceController::query in ./
restws.entity.inc - Implements RestWSQueryResourceControllerInterface::query().
File
- ./
restws.entity.inc, line 362 - RESTful web services module integration for entities.
Class
- RestWSEntityResourceController
- Controller for entity-bases resources.
Code
protected function propertyQueryOperation(EntityFieldQuery $query, $operation, $property, $value) {
$properties = $this
->propertyInfo();
// Check property access.
if (!empty($properties[$property]['access callback'])) {
if (!call_user_func($properties[$property]['access callback'], 'view', $property, NULL, NULL, $this
->resource())) {
throw new RestWSException(t('Not authorized to query property @p', array(
'@p' => $property,
)), 403);
}
}
// If field is not set, then the filter is a property and we can extract
// the schema field from the property array.
if (empty($properties[$property]['field'])) {
$column = $properties[$property]['schema field'];
$operation = 'property' . $operation;
$query
->{$operation}($column, $value);
}
else {
// For fields we need the field info to get the right column for the
// query.
$field_info = field_info_field($property);
$operation = 'field' . $operation;
if (is_array($value)) {
// Specific column filters are given, so add a query condition for each
// one of them.
foreach ($value as $column => $val) {
$query
->{$operation}($field_info, $column, $val);
}
}
else {
// Just pick the first field column for the operation.
$columns = array_keys($field_info['columns']);
$column = $columns[0];
$query
->{$operation}($field_info, $column, $value);
}
}
}