Révision 13c3c9b4
Ajouté par Assos Assos il y a environ 9 ans
drupal7/sites/all/modules/views/handlers/views_handler_field_counter.inc | ||
---|---|---|
14 | 14 |
function option_definition() { |
15 | 15 |
$options = parent::option_definition(); |
16 | 16 |
$options['counter_start'] = array('default' => 1); |
17 |
$options['reverse'] = array('default' => FALSE); |
|
17 | 18 |
return $options; |
18 | 19 |
} |
19 | 20 |
|
... | ... | |
26 | 27 |
'#size' => 2, |
27 | 28 |
); |
28 | 29 |
|
30 |
$form['reverse'] = array( |
|
31 |
'#type' => 'checkbox', |
|
32 |
'#title' => t('Reverse'), |
|
33 |
'#default_value' => $this->options['reverse'], |
|
34 |
'#description' => t('Reverse the counter.'), |
|
35 |
); |
|
36 |
|
|
29 | 37 |
parent::options_form($form, $form_state); |
30 | 38 |
} |
31 | 39 |
|
... | ... | |
34 | 42 |
} |
35 | 43 |
|
36 | 44 |
function render($values) { |
45 |
$reverse = empty($this->options['reverse']) ? 1 : -1; |
|
46 |
|
|
37 | 47 |
// Note: 1 is subtracted from the counter start value below because the |
38 | 48 |
// counter value is incremented by 1 at the end of this function. |
39 |
$count = is_numeric($this->options['counter_start']) ? $this->options['counter_start'] - 1 : 0; |
|
49 |
$counter_start = is_numeric($this->options['counter_start']) ? $this->options['counter_start'] : 0; |
|
50 |
$count = ($reverse == -1) ? count($this->view->result) + $counter_start : $counter_start -1; |
|
40 | 51 |
$pager = $this->view->query->pager; |
52 |
|
|
41 | 53 |
// Get the base count of the pager. |
42 | 54 |
if ($pager->use_pager()) { |
43 |
$count += ($pager->get_items_per_page() * $pager->get_current_page() + $pager->get_offset()); |
|
55 |
if ($reverse == -1) { |
|
56 |
$count = ($pager->total_items + $counter_start - ($pager->get_current_page() * $pager->get_items_per_page()) + $pager->get_offset()); |
|
57 |
} else { |
|
58 |
$count += (($pager->get_items_per_page() * $pager->get_current_page() + $pager->get_offset())) * $reverse; |
|
59 |
} |
|
44 | 60 |
} |
45 | 61 |
// Add the counter for the current site. |
46 |
$count += $this->view->row_index + 1;
|
|
62 |
$count += ($this->view->row_index + 1) * $reverse;
|
|
47 | 63 |
|
48 | 64 |
return $count; |
49 | 65 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules