You are here

function _node_resource_index in Services 6.3

Same name and namespace in other branches
  1. 6.2 services/node_service/node_resource.inc \_node_resource_index()
  2. 7.3 resources/node_resource.inc \_node_resource_index()
  3. 7 services/node_service/node_resource.inc \_node_resource_index()

Return an array of optionally paged nids baed on a set of criteria.

An example request might look like

http://domain/endpoint/node?fields=nid,vid&parameters[nid]=7&parameters[...

This would return an array of objects with only nid and vid defined, where nid = 7 and uid = 1.

@todo Evaluate the functionality here in general. Particularly around

  • Do we need fields at all? Should this just return full nodes?
  • Is there an easier syntax we can define which can make the urls for index requests more straightforward?

Parameters

$page: Page number of results to return (in pages of 20).

$fields: The fields you want returned. An array containing fields and values used to build a sql WHERE clause indicating items to retrieve.

$page_size: Integer number of items to be returned. An array of node objects.

2 string references to '_node_resource_index'
hook_services_resources in ./services.services.api.php
Implementation of hook_services_resources(). Defines function signatures for resources available to services.
_node_resource_definition in resources/node_resource.inc
@file This file will define the resources for dealing directly with nodes

File

resources/node_resource.inc, line 432
This file will define the resources for dealing directly with nodes

Code

function _node_resource_index($page, $fields, $parameters, $page_size) {

  // Limit to published nodes if user doesn't have 'administer nodes'
  // permissions.
  if (!user_access('administer nodes')) {
    $parameters['status'] = 1;
  }
  $query = services_resource_build_index_query('node', 'n.sticky DESC, n.created DESC', $page, $fields, $parameters, 'n', 'nid', $page_size, 'node');

  // Put together array of matching nodes to return.
  $results = array();
  while ($node = db_fetch_object($query)) {
    $results[] = $node;
  }
  return services_resource_build_index_list($results, 'node', 'nid');
}