You are here

function views_service_get in Services 6.2

Same name and namespace in other branches
  1. 6 services/views_service/views_service.inc \views_service_get()
  2. 7 services/views_service/views_service.inc \views_service_get()

Get a view from the database.

Parameters

$view_name: String. The views name.

$display_id: String (optional). The display name.

$offset: Integer (optional). An offset integer for paging.

$limit: Integer (optional). A limit integer for paging.

$args: Array (optional). A list of arguments.

format_output: Boolean (optional). TRUE if view should be formatted using the defined style plugin.

Return value

Array. The views return.

1 string reference to 'views_service_get'
views_service_service in services/views_service/views_service.module
Implementation of hook_service().

File

services/views_service/views_service.inc, line 26
Link general views functionalities to services module.

Code

function views_service_get($view_name, $display_id = 'default', $args = array(), $offset = 0, $limit = 0, $format_output = FALSE) {
  $result = array();
  $view = views_get_view($view_name);

  // Put all arguments and then execute.
  $view
    ->set_arguments($args, FALSE);
  $view
    ->set_offset($offset);
  $view
    ->set_items_per_page($limit);
  if (!empty($limit)) {
    $view
      ->set_use_pager(TRUE);
  }
  else {

    // Disable the user pager.
    $view
      ->set_use_pager(FALSE);
  }
  if (!$format_output) {
    $view
      ->set_display($display_id);
    $view
      ->execute();
    $result = $view->result;
    $row_plugin = $view->display_handler
      ->get_option('row_plugin');

    // If row plugin is node, then we should load each node
    if ($row_plugin == 'node') {
      $nodes = array();
      foreach ($view->result as $row) {
        $nodes[] = services_node_load(node_load($row->nid));
      }
      $result = $nodes;
    }
  }
  else {

    // We want to keep the result an array.
    $result[] = $view
      ->preview($display_id);
  }
  return $result;
}