views_handler_field_counter.inc

  1. 3.x handlers/views_handler_field_counter.inc
  2. 2.x handlers/views_handler_field_counter.inc

File

handlers/views_handler_field_counter.inc
View source
  1. <?php
  2. class views_handler_field_counter extends views_handler_field {
  3. function option_definition() {
  4. $options = parent::option_definition();
  5. $options['counter_start'] = array('default' => 1);
  6. return $options;
  7. }
  8. function options_form(&$form, &$form_state) {
  9. parent::options_form($form, $form_state);
  10. $form['counter_start'] = array(
  11. '#type' => 'textfield',
  12. '#title' => t('Starting value'),
  13. '#default_value' => $this->options['counter_start'],
  14. '#description' => t('Specify the number the counter should start at.'),
  15. //'#process' => array('views_process_dependency'),
  16. '#size' => 2,
  17. );
  18. }
  19. function query() {
  20. // do nothing -- to override the parent query.
  21. }
  22. function render($values) {
  23. // Note: 1 is subtracted from the counter start value below because the
  24. // counter value is incremented by 1 at the end of this function.
  25. $count = is_numeric($this->options['counter_start']) ? $this->options['counter_start'] - 1 : 0;
  26. $pager = $this->view->pager;
  27. // Get the base count of the pager.
  28. if ($pager['use_pager']) {
  29. $count += ($pager['items_per_page'] * $pager['current_page']) + $pager['offset'];
  30. }
  31. // Add the counter for the current site.
  32. $count += $this->view->row_index + 1;
  33. return $count;
  34. }
  35. }