Commit 1ed69a1e authored by merlinofchaos's avatar merlinofchaos

Pager settings in and working.

parent 999b2e53
......@@ -20,6 +20,7 @@ function views_views_plugins() {
'no ui' => TRUE,
'no remove' => TRUE,
'js' => array('misc/collapse.js', 'misc/textarea.js', 'misc/tabledrag.js'),
'use pager' => TRUE,
),
'page' => array(
'title' => t('Page'),
......@@ -27,6 +28,7 @@ function views_views_plugins() {
'handler' => 'views_display_plugin_page',
'uses hook menu' => TRUE,
'has path' => TRUE,
'use pager' => TRUE,
),
'block' => array(
'title' => t('Block'),
......@@ -164,8 +166,10 @@ class views_display_plugin extends views_object {
'header' => array('header', 'header_format', 'header_empty'),
'footer' => array('footer', 'footer_format', 'footer_empty'),
'empty' => array('empty', 'empty_format'),
// @todo
'items_per_page' => array('items_per_page', 'offset', 'use_pager', 'pager_element'),
'use_pager' => array('items_per_page', 'offset', 'use_pager', 'pager_element'),
// @todo
'php_arg_code' => array('php_arg_code'),
'link_display' => array('link_display'),
'exposed_options' => array('exposed_options'),
......@@ -362,6 +366,19 @@ class views_display_plugin extends views_object {
break;
}
if (!empty($this->definition['use pager'])) {
$options['use_pager'] = array(
'category' => 'basic',
'title' => t('Use pager'),
'value' => $this->get_option('use_pager') ? t('Yes') : t('No'),
);
}
$options['items_per_page'] = array(
'category' => 'basic',
'title' => $this->get_option('use_pager') ? t('Items per page') : t('Items to display'),
'value' => intval($this->get_option('items_per_page')),
);
$options['access'] = array(
'category' => 'basic',
'title' => t('Access'),
......@@ -428,6 +445,33 @@ class views_display_plugin extends views_object {
'#default_value' => $this->get_option('title'),
);
break;
case 'use_pager':
$form['#title'] .= t('Use a pager for this view');
$form['use_pager'] = array(
'#type' => 'radios',
'#options' => array(1 => t('Yes'), 0 => t('No')),
'#default_value' => $this->get_option('use_pager'),
);
$form['pager_element'] = array(
'#type' => 'textfield',
'#title' => t('Pager element'),
'#description' => t('Which element of the ?page= array to use, if the pager is enabled. 0 is recommended, but if there are other pagers on the page, you may use a higher number so as not to conflict. Large values are bad here as they will add a lot of commas to the URLs.'),
'#default_value' => intval($this->get_option('pager_element')),
);
break;
case 'items_per_page':
$form['items_per_page'] = array(
'#type' => 'textfield',
'#description' => t('The number of items to display per page. Enter 0 for no limit.'),
'#default_value' => intval($this->get_option('items_per_page')),
);
$form['offset'] = array(
'#type' => 'textfield',
'#title' => t('Offset'),
'#description' => t('The number of items to skip. For example, if this field is 3, the first 3 items will be skipped and not displayed.'),
'#default_value' => intval($this->get_option('offset')),
);
break;
case 'access':
$form['#title'] .= t('Access restrictions');
$form['access'] = array(
......@@ -441,7 +485,7 @@ class views_display_plugin extends views_object {
$access = array('type' => 'none', 'role' => array(), 'perm' => '');
}
$form['access']['type'] = array(
'#prefix' => '<div class="views-left-20">',
'#prefix' => '<div class="views-left-25">',
'#suffix' => '</div>',
'#title' => t('Type'),
'#type' => 'radios',
......@@ -594,6 +638,14 @@ class views_display_plugin extends views_object {
case 'access':
$this->set_option($section, $form_state['values'][$section]);
break;
case 'use_pager':
$this->set_option($section, $form_state['values'][$section]);
$this->set_option('pager_element', intval($form_state['values']['pager_element']));
break;
case 'items_per_page':
$this->set_option($section, intval($form_state['values'][$section]));
$this->set_option('offset', intval($form_state['values']['offset']));
break;
case 'row_plugin':
// This if prevents resetting options to default if they don't change
// the plugin.
......@@ -723,8 +775,10 @@ class views_display_plugin extends views_object {
function render_title() { }
function render_textarea($area) {
$format_string = $area . '_format';
return check_markup($this->get_option($area), $this->get_option($format_string));
$value = $this->get_option($area);
if ($value) {
return check_markup($value, $this->get_option($area . '_format'));
}
}
/**
......@@ -800,6 +854,8 @@ class views_display_plugin_default extends views_display_plugin {
$display->display_options['sorts'] = array();
$display->display_options['arguments'] = array();
$display->display_options['filters'] = array();
$display->display_options['items_per_page'] = 10;
}
/**
......
......@@ -28,11 +28,14 @@ class view extends views_db_object {
var $build_info = array();
// pager variables
var $use_pager = FALSE;
var $page_size = 25;
var $pager_element = 0;
var $offset = 0;
var $current_page = 0;
var $pager = array(
'use_pager' => FALSE,
'items_per_page' => 10,
'element' => 0,
'offset' => 0,
'current_page' => 0,
);
/**
* Constructor
*/
......@@ -76,22 +79,22 @@ class view extends views_db_object {
*
* @todo move all pager properties into a pager object
*/
function set_page_size($page_size) {
$this->page_size = $page_size;
function set_items_per_page($items_per_page) {
$this->pager['items_per_page'] = $items_per_page;
}
/**
* Whether or not the pager should be used.
*/
function set_use_pager($use_pager) {
$this->use_pager = $use_pager;
$this->pager['use_pager'] = $use_pager;
}
/**
* The pager element id to use if use_apger is on
*/
function set_pager_element($pager_element) {
$this->pager_element = $pager_element;
$this->pager['element'] = $pager_element;
}
/**
......@@ -99,7 +102,7 @@ class view extends views_db_object {
* set.
*/
function set_offset($offset) {
$this->offset = $offset;
$this->pager['offset'] = $offset;
}
/**
......@@ -376,19 +379,24 @@ class view extends views_db_object {
$query = db_rewrite_sql($this->build_info['query'], $this->base_table, $this->base_field);
$args = $this->build_info['query_args'];
// @todo: Fill in execution defaults if they are not set.
// use_pager, page_size, offset
vpr($query);
$items = array();
if ($query) {
if (!empty($this->use_pager)) {
if (!empty($this->pager['use_pager'])) {
$count_query = db_rewrite_sql($this->build_info['count_query'], $this->base_table, $this->base_field);
$this->result = pager_query($query, $view->page_size, $view->use_pager - 1, $count_query, $args);
$this->total_rows = $GLOBALS['pager_total_items'][$this->use_pager - 1];
$this->result = pager_query($query, $this->pager['items_per_page'], $this->pager['element'], $count_query, $args);
$this->total_rows = $GLOBALS['pager_total_items'][$this->pager['element']];
}
else if (!empty($this->page_size)) {
$offset = $this->current_page * $this->page_size + $this->offset;
$this->result = db_query_range($query, $args, $offset, $this->page_size);
else if (!empty($this->pager['items_per_page'])) {
$offset = $this->pager['current_page'] * $this->pager['items_per_page'] + $this->pager['offset'];
$this->result = db_query_range($query, $args, $offset, $this->pager['items_per_page']);
// Rewrite and run the count query so we can store how many items this would have
// matched.
$count_query = db_rewrite_sql($this->build_info['count_query'], $this->base_table, $this->base_field);
$this->total_rows = db_result(db_query($count_query));
}
else {
$this->result = db_query($query, $args);
......@@ -423,12 +431,18 @@ class view extends views_db_object {
* the given arguments.
*/
function execute_display($display_id = NULL, $args = array()) {
// Prepare the view with the information we have.
$this->set_arguments($args);
if (!$this->set_display($display_id)) {
return FALSE;
}
// Prepare the view with the information we have.
$this->set_arguments($args);
$this->set_use_pager($this->display_handler->get_option('use_pager'));
$this->set_items_per_page($this->display_handler->get_option('items_per_page'));
$this->set_pager_element($this->display_handler->get_option('pager_element'));
$this->set_offset($this->display_handler->get_option('offset'));
// Execute the view
return $this->display_handler->execute();
}
......
......@@ -24,8 +24,8 @@ function template_preprocess_views_view(&$vars) {
$vars['feed_icon'] = $view->display_handler->render_feed_icon();
$vars['pager'] = '';
if (!empty($view->use_pager)) {
$vars['pager'] = theme('pager', array(), $view->page_size, $view->page_element);
if (!empty($view->pager['use_pager'])) {
$vars['pager'] = theme('pager', array(), $view->pager['items_per_page'], $view->pager['element']);
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment