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 views_handler_area_result extends views_handler_area {
|
14
|
|
15
|
/**
|
16
|
* {@inheritdoc}
|
17
|
*/
|
18
|
public function option_definition() {
|
19
|
$options = parent::option_definition();
|
20
|
|
21
|
$options['content'] = array(
|
22
|
'default' => 'Displaying @start - @end of @total',
|
23
|
'translatable' => TRUE,
|
24
|
);
|
25
|
|
26
|
return $options;
|
27
|
}
|
28
|
|
29
|
/**
|
30
|
* {@inheritdoc}
|
31
|
*/
|
32
|
public function options_form(&$form, &$form_state) {
|
33
|
parent::options_form($form, $form_state);
|
34
|
$variables = array(
|
35
|
'items' => array(
|
36
|
'@start -- the initial record number in the set',
|
37
|
'@end -- the last record number in the set',
|
38
|
'@total -- the total records in the set',
|
39
|
'@name -- the human-readable name of the view',
|
40
|
'@per_page -- the number of items per page',
|
41
|
'@current_page -- the current page number',
|
42
|
'@current_record_count -- the current page record count',
|
43
|
'@page_count -- the total page count',
|
44
|
),
|
45
|
);
|
46
|
$list = theme('item_list', $variables);
|
47
|
$form['content'] = array(
|
48
|
'#title' => t('Display'),
|
49
|
'#type' => 'textarea',
|
50
|
'#rows' => 3,
|
51
|
'#default_value' => $this->options['content'],
|
52
|
'#description' => t('You may use HTML code in this field. The following tokens are supported:') . $list,
|
53
|
);
|
54
|
}
|
55
|
|
56
|
/**
|
57
|
* Find out the information to render.
|
58
|
*/
|
59
|
public function render($empty = FALSE) {
|
60
|
// Must have options and does not work on summaries.
|
61
|
if (!isset($this->options['content']) || $this->view->plugin_name == 'default_summary') {
|
62
|
return;
|
63
|
}
|
64
|
$output = '';
|
65
|
$format = $this->options['content'];
|
66
|
// Calculate the page totals.
|
67
|
$current_page = (int) $this->view->get_current_page() + 1;
|
68
|
$per_page = (int) $this->view->get_items_per_page();
|
69
|
// @todo Maybe use a possible is views empty functionality.
|
70
|
// Not every view has total_rows set, use view->result instead.
|
71
|
$total = isset($this->view->total_rows) ? $this->view->total_rows : count($this->view->result);
|
72
|
$name = check_plain($this->view->human_name);
|
73
|
if ($per_page === 0) {
|
74
|
$page_count = 1;
|
75
|
$start = 1;
|
76
|
$end = $total;
|
77
|
}
|
78
|
else {
|
79
|
$page_count = (int) ceil($total / $per_page);
|
80
|
$total_count = $current_page * $per_page;
|
81
|
if ($total_count > $total) {
|
82
|
$total_count = $total;
|
83
|
}
|
84
|
$start = ($current_page - 1) * $per_page + 1;
|
85
|
$end = $total_count;
|
86
|
}
|
87
|
$current_record_count = ($end - $start) + 1;
|
88
|
// Get the search information.
|
89
|
$items = array(
|
90
|
'start',
|
91
|
'end',
|
92
|
'total',
|
93
|
'name',
|
94
|
'per_page',
|
95
|
'current_page',
|
96
|
'current_record_count',
|
97
|
'page_count',
|
98
|
);
|
99
|
$replacements = array();
|
100
|
foreach ($items as $item) {
|
101
|
$replacements["@$item"] = ${$item};
|
102
|
}
|
103
|
// Send the output.
|
104
|
if (!empty($total) || !empty($this->options['empty'])) {
|
105
|
// We don't want to sanitize with filter_xss_admin() here because Views
|
106
|
// administrators are trusted users and should be allowed to insert
|
107
|
// arbitrary markup.
|
108
|
$output .= str_replace(array_keys($replacements), array_values($replacements), $format);
|
109
|
}
|
110
|
return $output;
|
111
|
}
|
112
|
|
113
|
}
|