1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* Definition of views_handler_area_result.
|
5
|
*
|
6
|
* Views area handler to display some configurable result summary.
|
7
|
*
|
8
|
* @ingroup views_area_handlers
|
9
|
*/
|
10
|
class webform_handler_area_result_pager extends views_handler_area_result {
|
11
|
|
12
|
/**
|
13
|
* {@inheritdoc}
|
14
|
*/
|
15
|
public function option_definition() {
|
16
|
$options = parent::option_definition();
|
17
|
$options['content']['default'] = t('Displaying @start - @end of @total. @items_per_page_links');
|
18
|
$options['tokenize'] = array('default' => FALSE, 'bool' => TRUE);
|
19
|
return $options;
|
20
|
}
|
21
|
|
22
|
/**
|
23
|
* {@inheritdoc}
|
24
|
*/
|
25
|
public function options_form(&$form, &$form_state) {
|
26
|
parent::options_form($form, $form_state);
|
27
|
$form['content']['#description'] .= '<br/>' . t('Plus @items_per_page_links -- the list of links to change the items/page, with prompt');
|
28
|
|
29
|
$form['tokenize'] = array(
|
30
|
'#type' => 'checkbox',
|
31
|
'#title' => t('Use replacement tokens from the first row'),
|
32
|
'#default_value' => $this->options['tokenize'],
|
33
|
);
|
34
|
}
|
35
|
|
36
|
/**
|
37
|
* Find out the information to render.
|
38
|
*/
|
39
|
public function render($empty = FALSE) {
|
40
|
$output = parent::render($empty);
|
41
|
if (is_string($output) && isset($this->view->query->pager)) {
|
42
|
$output = str_replace('@items_per_page_links', $this->render_items_per_page($this->view->query->pager), $output);
|
43
|
if ($this->options['tokenize']) {
|
44
|
$output = $this->view->style_plugin->tokenize_value($output, 0);
|
45
|
$output = $this->sanitize_value($output, 'xss_admin');
|
46
|
}
|
47
|
}
|
48
|
return $output;
|
49
|
}
|
50
|
|
51
|
/**
|
52
|
*
|
53
|
*/
|
54
|
public function query() {
|
55
|
$view = $this->view;
|
56
|
if (!empty($_GET['items_per_page']) && $_GET['items_per_page'] > 0) {
|
57
|
$view->set_items_per_page($_GET['items_per_page']);
|
58
|
}
|
59
|
elseif (!empty($_GET['items_per_page']) && $_GET['items_per_page'] == 'All') {
|
60
|
$view->set_items_per_page(0);
|
61
|
}
|
62
|
}
|
63
|
|
64
|
/**
|
65
|
*
|
66
|
*/
|
67
|
public function render_items_per_page($pager) {
|
68
|
$sanitized_options = array();
|
69
|
if (!empty($pager->options['expose']['items_per_page_options'])) {
|
70
|
$options = explode(',', $pager->options['expose']['items_per_page_options']);
|
71
|
foreach ($options as $option) {
|
72
|
if ($pager->total_items <= intval($option)) {
|
73
|
break;
|
74
|
}
|
75
|
$sanitized_options[intval($option)] = intval($option);
|
76
|
}
|
77
|
if (!empty($sanitized_options) && !empty($pager->options['expose']['items_per_page_options_all']) && !empty($pager->options['expose']['items_per_page_options_all_label'])) {
|
78
|
$sanitized_options[0] = $pager->options['expose']['items_per_page_options_all_label'];
|
79
|
}
|
80
|
$url_query = $_GET;
|
81
|
unset($url_query['q']);
|
82
|
foreach ($sanitized_options as $items_per_page => &$label) {
|
83
|
$selected = $pager->options['items_per_page'] == $items_per_page ||
|
84
|
($items_per_page == 0 && $pager->total_items < intval($pager->options['items_per_page']));
|
85
|
$label = l($label, $_GET['q'], array(
|
86
|
'query' => array('items_per_page' => $label) + $url_query,
|
87
|
'attributes' => array(
|
88
|
'class' => $selected ? array('selected') : array(),
|
89
|
),
|
90
|
));
|
91
|
}
|
92
|
// Drop PHP reference.
|
93
|
unset($label);
|
94
|
|
95
|
// Include CSS needed for 'selected' class.
|
96
|
drupal_add_library('webform', 'admin');
|
97
|
}
|
98
|
return $sanitized_options ? t('Show !links results per page.', array('!links' => implode(' | ', $sanitized_options))) : '';
|
99
|
}
|
100
|
|
101
|
}
|