source: sipes/modules_contrib/views/handlers/views_handler_field_counter.inc @ 65dadeb

stableversion-3.0
Last change on this file since 65dadeb was 59029b2, checked in by José Gregorio Puentes <jpuentes@…>, 8 años ago

se actualizo la version del modulo views

  • Propiedad mode establecida a 100644
File size: 1.4 KB
Línea 
1<?php
2
3/**
4 * Field handler to show a counter of the current row.
5 *
6 * @ingroup views_field_handlers
7 */
8class views_handler_field_counter extends views_handler_field {
9  function option_definition() {
10    $options = parent::option_definition();
11    $options['counter_start'] = array('default' => 1);
12    return $options;
13  }
14
15  function options_form(&$form, &$form_state) {
16    parent::options_form($form, $form_state);
17
18    $form['counter_start'] = array(
19      '#type' => 'textfield',
20      '#title' => t('Starting value'),
21      '#default_value' => $this->options['counter_start'],
22      '#description' => t('Specify the number the counter should start at.'),
23      //'#process' => array('views_process_dependency'),
24      '#size' => 2,
25    );
26  }
27
28  function query() {
29    // do nothing -- to override the parent query.
30  }
31
32  function render($values) {
33    // Note:  1 is subtracted from the counter start value below because the
34    // counter value is incremented by 1 at the end of this function.
35    $count = is_numeric($this->options['counter_start']) ? $this->options['counter_start'] - 1 : 0;
36    $pager = $this->view->query->pager;
37    // Get the base count of the pager.
38    if ($pager->use_pager()) {
39      $count += ($pager->get_items_per_page() * $pager->get_current_page() + $pager->get_offset());
40    }
41    // Add the counter for the current site.
42    $count += $this->view->row_index + 1;
43
44    return $count;
45  }
46}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.