You are here

function services_resource_build_index_query in Services 7.3

Same name and namespace in other branches
  1. 6.3 services.module \services_resource_build_index_query()

Helper function to build index queries.

Parameters

$query: Object database query object.

$page: Integer page number we are requesting.

$fields: Array fields to return.

$parameter: Array parameters to add to the index query.

$page_size: Integer number of items to be returned.

$resource: String name of the resource building the index query

$options: Additional query options.

6 calls to services_resource_build_index_query()
_comment_resource_index in resources/comment_resource.inc
Return an array of optionally paged cids based on a set of criteria.
_file_resource_index in resources/file_resource.inc
Return an array of optionally paged fids based on a set of criteria.
_node_resource_index in resources/node_resource.inc
Return an array of optionally paged nids based on a set of criteria.
_taxonomy_term_resource_index in resources/taxonomy_resource.inc
Return an array of optionally paged tids based on a set of criteria.
_taxonomy_vocabulary_resource_index in resources/taxonomy_resource.inc
Return an array of optionally paged vids based on a set of criteria.

... See full list

File

./services.module, line 930
Provides a generic but powerful API for web services.

Code

function services_resource_build_index_query($query, $page, $fields, $parameters, $page_size, $resource, $options = array()) {
  $default_limit = variable_get("services_{$resource}_index_page_size", 20);
  if (!user_access('perform unlimited index queries') && $page_size > $default_limit) {
    $page_size = $default_limit;
  }
  $query
    ->range($page * $page_size, $page_size);
  if ($fields == '*') {
    $query
      ->fields('t');
  }
  else {
    $query
      ->fields('t', explode(',', $fields));
  }
  if (isset($parameters) && is_array($parameters)) {
    foreach ($parameters as $parameter => $parameter_value) {
      $op = 'IN';
      if (isset($options['parameters_op']) && isset($options['parameters_op'][$parameter])) {
        if (_services_is_valid_query_op($options['parameters_op'][$parameter])) {
          $op = strtoupper($options['parameters_op'][$parameter]);
        }
      }
      $query
        ->condition($parameter, services_str_getcsv($parameter_value), $op);
    }
  }
  if (isset($options['orderby'])) {
    foreach ($options['orderby'] as $column => $sort) {
      $query
        ->orderBy(db_escape_field($column), $sort);
    }
  }
}