function views_build_view in Views (for Drupal 7) 5
This builds the basic view.
Parameters
$type: 'page' -- Produce output as a page, sent through theme. The only real difference between this and block is that a page uses drupal_set_title to change the page title. 'block' -- Produce output as a block, sent through theme. 'embed' -- Use this if you want to embed a view onto another page, and don't want any block or page specific things to happen to it. 'result' -- return an $info array. The array contains: query: The actual query ran. countquery: The count query that would be run if limiting was required. summary: True if an argument was missing and a summary was generated. level: What level the missing argument was at. result: Database object you can use db_fetch_object on. 'items' -- return info array as above, except instead of result, items: An array of objects containing the results of the query. 'queries' -- returns an array, summarizing the queries, but does not run them.
$view: The actual view object. Use views_get_view() if you only have the name or vid.
$args: args taken from the URL. Not relevant for many views. Can be null.
$use_pager: If set, use a pager. Set this to the pager id you want it to use if you plan on using multiple pagers on a page. To go with the default setting, set to $view->use_pager. Note that the pager element id will be decremented in order to have the IDs start at 0.
$limit: Required if $use_pager is set; if $limit is set and $use_pager is not, this will be the maximum number of records returned. This is ignored if using a view set to return a random result. To go with the default setting set to $view->nodes_per_page or $view->nodes_per_block. If $use_pager is set and this field is not, you'll get a SQL error. Don't do that!
$page: $use_pager is false, and $limit is !0, $page tells it what page to start on, in case for some reason a particular section of view is needed,
$offset: If $use_pager == false, skip the first $offset results. Does not work with pager. without paging on.
$filters: An array of exposed filter ops and values to use with the exposed filter system Array has the form: [0] => array('op' => 'foo', 'value' => 'bar'), [1] => array('value' => 'zoo'), // for a locked operator, e.g. If no array is passed in, views will look in the $_GET array for potential filters
3 calls to views_build_view()
- theme_view in ./
views.module - Returns a themed view.
- views_view_block in ./
views.module - This views a view by block. Can be used as a callback or programmatically.
- views_view_page in ./
views.module - This views a view by page, and should only be used as a callback.
File
- ./
views.module, line 518
Code
function views_build_view($type, &$view, $args = array(), $use_pager = false, $limit = 0, $page = 0, $offset = 0, $filters = NULL) {
views_load_cache();
// Fix a number of annoying whines when NULL is passed in..
if ($args == NULL) {
$args = array();
}
// if no filter values are passed in, get them from the $_GET array
if ($filters == NULL) {
$filters = views_get_filter_values();
}
views_set_current_view($view);
$view->build_type = $type;
$view->type = $type == 'block' ? $view->block_type : $view->page_type;
if ($view->view_args_php) {
ob_start();
$result = eval($view->view_args_php);
if (is_array($result)) {
$args = $result;
}
ob_end_clean();
}
$view->use_pager = $use_pager;
$view->pager_limit = $limit;
$view->current_page = $page;
$view->offset = $offset;
// Call a hook that'll let modules modify the view query before it is created
foreach (module_implements('views_pre_query') as $module) {
$function = $module . '_views_pre_query';
$output .= $function($view);
}
$info = _views_get_query($view, $args, $filters);
if ($info['fail']) {
return FALSE;
}
if ($type == 'queries') {
return $info;
}
$items = array();
if ($info['query']) {
$query = db_rewrite_sql($info['query'], 'node');
if ($view->use_pager) {
$cquery = db_rewrite_sql($info['countquery'], 'node', 'nid', $info['rewrite_args']);
$result = pager_query($query, $view->pager_limit, $view->use_pager - 1, $cquery, $info['args']);
$view->total_rows = $GLOBALS['pager_total_items'][$view->use_pager - 1];
}
else {
$result = $view->pager_limit ? db_query_range($query, $info['args'], $view->current_page * $view->pager_limit + $view->offset, $view->pager_limit) : db_query($query, $info['args']);
}
$view->num_rows = db_num_rows($result);
if ($type == 'result') {
$info['result'] = $result;
return $info;
}
while ($item = db_fetch_object($result)) {
$items[] = $item;
}
}
if ($type == 'items') {
$info['items'] = $items;
return $info;
}
// Call a hook that'll let modules modify the view just before it is displayed.
foreach (module_implements('views_pre_view') as $module) {
$function = $module . '_views_pre_view';
$output .= $function($view, $items);
}
$view->real_url = views_get_url($view, $args);
$output .= views_theme('views_view', $view, $type, $items, $info['level'], $args);
// Call a hook that'll let modules modify the view just after it is displayed.
foreach (module_implements('views_post_view') as $module) {
$function = $module . '_views_post_view';
$output .= $function($view, $items, $output);
}
return $output;
}