/[drupal]/contributions/modules/views/handlers/views_handler_field_counter.inc
ViewVC logotype

Contents of /contributions/modules/views/handlers/views_handler_field_counter.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Mon Sep 21 21:36:32 2009 UTC (2 months ago) by merlinofchaos
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--2, DRUPAL-7--3
Changes since 1.2: +2 -2 lines
File MIME type: text/x-php
#551752 by dereine: Clean up row counter code.
1 <?php
2 // $Id: views_handler_field_counter.inc,v 1.2 2009/06/25 22:09:42 merlinofchaos Exp $
3
4 class views_handler_field_counter extends views_handler_field {
5 function option_definition() {
6 $options = parent::option_definition();
7 $options['counter_start'] = array('default' => 1);
8 return $options;
9 }
10
11 function options_form(&$form, &$form_state) {
12 parent::options_form($form, $form_state);
13
14 $form['counter_start'] = array(
15 '#type' => 'textfield',
16 '#title' => t('Starting value'),
17 '#default_value' => $this->options['counter_start'],
18 '#description' => t('Specify the number the counter should start at.'),
19 //'#process' => array('views_process_dependency'),
20 '#size' => 2,
21 );
22 }
23
24 function query() {
25 // do nothing -- to override the parent query.
26 }
27
28 function render($values) {
29 // Note: 1 is subtracted from the counter start value below because the
30 // counter value is incremented by 1 at the end of this function.
31 $count = is_numeric($this->options['counter_start']) ? $this->options['counter_start'] - 1 : 0;
32 $pager = $this->view->pager;
33 // Get the base count of the pager.
34 if ($pager['use_pager']) {
35 $count += ($pager['items_per_page'] * $pager['current_page']) + $pager['offset'];
36 }
37 // Add the counter for the current site.
38 $count += $this->view->row_index + 1;
39
40 return $count;
41 }
42 }

  ViewVC Help
Powered by ViewVC 1.1.2