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