? 329048-services-views-2-57.patch
Index: services/views_service/views_service.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/services/services/views_service/Attic/views_service.inc,v
retrieving revision 1.1.2.12
diff -u -p -r1.1.2.12 views_service.inc
--- services/views_service/views_service.inc	29 May 2009 23:42:39 -0000	1.1.2.12
+++ services/views_service/views_service.inc	28 Jun 2009 15:47:02 -0000
@@ -11,44 +11,48 @@
  *
  * @param $view_name
  *   String. The views name.
+ * @param $display_id
+ *   String (optional). The display name.
  * @param $fields
- *   Array (optional). Array of fields to return.
- * @param $args
- *   Array (optional). Array of args to pass to the view.
+ *   Array (optional). A list of fields in the view.
  * @param $offset
- *   Array (optional). Offset record to start from.
+ *   Integer (optional). An offset integer for paging.
  * @param $limit
- *   Array (optional). Max number of records to return.
+ *   Integer (optional). A limit integer for paging.
+ * @param $args
+ *   Array (optional). A list of arguments.
+ * @param format_output
+ *   Boolean (optional). TRUE if view should be formatted using the defined 
+ *   style plugin.
  * @return
  *   Array. The views return.
  */
-function views_service_get($view_name, $fields = array(), $args = array(), $offset = 0, $limit = 0) {
+function views_service_get($view_name, $display_id = 'default', $fields = array(), $args = array(), $offset = 0, $limit = 0, $format_output = FALSE) {
+  $result = array();
   $view = views_get_view($view_name);
 
-  // Put all arguments and then execute
+  // Put all arguments and then execute.
   $view->set_arguments($args, FALSE);
   $view->set_offset($offset);
-  $view->set_items_per_page($limit);
-  $view->execute();
-  
-  // Get row plugin setting
-  $row_plugin = $view->display[$view->current_display]->display_options['row_plugin'];
-  
-  $nodes = array();
-  // If row plugin is node, then we must do a node_load
-  if ($row_plugin == 'node') {
-    foreach ($view->result as $node) {
-      $nodes[] = services_node_load(node_load($node->nid), $fields);
-    }
+  // If offset is set we can't have a user pager.
+  if (empty($offset)) {
+    $view->set_use_pager(TRUE);
+    $view->set_items_per_page($limit);
   }
-  // Otherwise, pass through the fields filter, just in case
   else {
-    foreach ($view->result as $node) {
-      $nodes[] = services_node_load($node, $fields);
-    }
+    // Disable the user pager.
+    $view->set_use_pager(FALSE);
+  }   
+  if (!$format_output) {
+    $view->set_display($display_id);
+    $view->execute();
+    $result = $view->result;
   }
-
-  return $nodes;
+  else {
+    // We want to keep the result an array.
+    $result[] = $view->preview($display_id);
+  }
+  return $result;
 }
 
 /**
Index: services/views_service/views_service.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/services/services/views_service/Attic/views_service.module,v
retrieving revision 1.4.2.20
diff -u -p -r1.4.2.20 views_service.module
--- services/views_service/views_service.module	18 May 2009 20:55:22 -0000	1.4.2.20
+++ services/views_service/views_service.module	28 Jun 2009 15:47:02 -0000
@@ -36,6 +36,12 @@ function views_service_service() {
           '#description'    => t('View name.')
         ),
         array(
+          '#name'           => 'display_id',
+          '#type'           => 'string',
+          '#optional'       => TRUE,
+          '#description'    => t('A display provided by the selected view.')
+        ),
+        array(
           '#name'           => 'fields',
           '#type'           => 'array',
           '#optional'       => TRUE,
@@ -51,14 +57,20 @@ function views_service_service() {
           '#name'           => 'offset',
           '#type'           => 'int',
           '#optional'       => TRUE,
-          '#description'    => t('An offset integer for paging.')
+          '#description'    => t('An offset integer for paging. If this is set limit will be ignored.')
         ),
         array(
           '#name'           => 'limit',
           '#type'           => 'int',
           '#optional'       => TRUE,
-          '#description'    => t('A limit integer for paging.')
+          '#description'    => t('A limit integer for paging. If offset is set, this will be ignored.')
         ),
+        array(
+          '#name'           => 'format_output',
+          '#type'           => 'boolean',
+          '#optional'       => TRUE,
+          '#description'    => t('TRUE if view should be formatted, or only the view result returned (FALSE by default).')
+        ),        
       ),
       '#return'           => 'array',
       '#help'             => t('Retrieves a view defined in views.module.')),
