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