function views_service_get in Services 7
Same name and namespace in other branches
- 6 services/views_service/views_service.inc \views_service_get()
- 6.2 services/views_service/views_service.inc \views_service_get()
Get a view from the database.
Parameters
$view_name: String. The views name.
$fields: Array (optional). Array of fields to return.
$args: Array (optional). Array of args to pass to the view.
$offset: Array (optional). Offset record to start from.
$limit: Array (optional). Max number of records to return.
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 24 - @author Services Dev Team
Code
function views_service_get($view_name, $fields = array(), $args = array(), $offset = 0, $limit = 0) {
$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);
$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);
}
}
else {
foreach ($view->result as $node) {
$nodes[] = services_node_load($node, $fields);
}
}
return $nodes;
}