You are here

function services_views_services_resources in Services Views 7

Same name and namespace in other branches
  1. 6 services_views.module \services_views_services_resources()

Implements hook_services_resources().

File

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

Code

function services_views_services_resources() {
  $resources['views'] = array();
  $resources['views']['retrieve'] = array(
    'help' => 'Retrieves a view.',
    'file' => array(
      'type' => 'inc',
      'module' => 'services_views',
      'name' => 'services_views.resource',
    ),
    'callback' => 'services_views_retrieve',
    'access callback' => 'services_views_access',
    'access arguments' => array(
      'view',
    ),
    'access arguments append' => TRUE,
    'args' => array(
      array(
        'name' => 'view_name',
        'type' => 'string',
        'description' => 'The name of the view to get.',
        'source' => array(
          'path' => '0',
        ),
        'optional' => FALSE,
      ),
      array(
        'name' => 'display_id',
        'type' => 'string',
        'description' => 'The display ID of the view to get.',
        'source' => array(
          'param' => 'display_id',
        ),
        'optional' => TRUE,
        'default value' => 'default',
      ),
      array(
        'name' => 'args',
        'type' => 'array',
        'description' => 'A list of arguments to pass to the view.',
        'source' => array(
          'param' => 'args',
        ),
        'optional' => TRUE,
        'default value' => array(),
      ),
      array(
        'name' => 'offset',
        'type' => 'int',
        'description' => 'The number of the entry for the page begin with.',
        'source' => array(
          'param' => 'offset',
        ),
        'optional' => TRUE,
        'default value' => 0,
      ),
      array(
        'name' => 'limit',
        'type' => 'int',
        'description' => 'The total number of entries to list.',
        'source' => array(
          'param' => 'limit',
        ),
        'optional' => TRUE,
        'default value' => -1,
      ),
      array(
        'name' => 'format_output',
        'type' => 'bool',
        'description' => 'Whether to return the raw data results or style the results.',
        'source' => array(
          'param' => 'format_output',
        ),
        'optional' => TRUE,
        'default value' => FALSE,
      ),
      array(
        'name' => 'filters',
        'type' => 'array',
        'description' => 'A list of filters to pass to the view.  These are defined by the exposed filters on your view.  Example call: <code>/views/your_view?nid=12345</code>',
        'source' => array(
          'param' => 'filters',
        ),
        'optional' => TRUE,
        'default value' => array(),
      ),
    ),
  );

  // Retrieve all views that have "services" display.
  $views = views_get_enabled_views();
  foreach ($views as $view_name => $view) {
    foreach ($view->display as $view_display => $display) {
      if ($display->display_plugin !== 'services') {
        continue;
      }
      $path = $display->display_options['path'];
      $resources[$path] = array();
      $resources[$path]['index'] = array(
        'view info' => array(
          'view_name' => $view_name,
          'display_id' => $view_display,
        ),
        'help' => filter_xss('View: ' . $view->human_name),
        'file' => array(
          'type' => 'inc',
          'module' => 'services_views',
          'name' => 'services_views.resource',
        ),
        'callback' => 'services_views_execute_view',
        // Reuse services_views_access access callback.
        'access callback' => 'services_views_access',
        'access arguments' => array(
          'view',
          array(
            'view_name' => $view_name,
            'display_id' => $view_display,
          ),
        ),
      );
    }
  }
  return $resources;
}