• Main Page
  • Related Pages
  • Modules
  • Classes
  • Files
  • File List
  • File Members

handlers/views_handler_field_counter.inc

00001 <?php
00002 
00008 class views_handler_field_counter extends views_handler_field {
00009   function option_definition() {
00010     $options = parent::option_definition();
00011     $options['counter_start'] = array('default' => 1);
00012     return $options;
00013   }
00014 
00015   function options_form(&$form, &$form_state) {
00016     $form['counter_start'] = array(
00017       '#type' => 'textfield',
00018       '#title' => t('Starting value'),
00019       '#default_value' => $this->options['counter_start'],
00020       '#description' => t('Specify the number the counter should start at.'),
00021       '#size' => 2,
00022     );
00023 
00024     parent::options_form($form, $form_state);
00025   }
00026 
00027   function query() {
00028     // do nothing -- to override the parent query.
00029   }
00030 
00031   function render($values) {
00032     // Note:  1 is subtracted from the counter start value below because the
00033     // counter value is incremented by 1 at the end of this function.
00034     $count = is_numeric($this->options['counter_start']) ? $this->options['counter_start'] - 1 : 0;
00035     $pager = $this->view->query->pager;
00036     // Get the base count of the pager.
00037     if ($pager->use_pager()) {
00038       $count += ($pager->get_items_per_page() * $pager->get_current_page() + $pager->get_offset());
00039     }
00040     // Add the counter for the current site.
00041     $count += $this->view->row_index + 1;
00042 
00043     return $count;
00044   }
00045 }

Generated on Sun Feb 26 2012 12:52:51 for Views by  doxygen 1.7.1