You are here

public function views_handler_field_counter::render in Views (for Drupal 7) 7.3

Same name and namespace in other branches
  1. 6.3 handlers/views_handler_field_counter.inc \views_handler_field_counter::render()
  2. 6.2 handlers/views_handler_field_counter.inc \views_handler_field_counter::render()

Render the field.

Parameters

array $values: The values retrieved from the database.

Overrides views_handler_field::render

File

handlers/views_handler_field_counter.inc, line 57
Definition of views_handler_field_counter.

Class

views_handler_field_counter
Field handler to show a counter of the current row.

Code

public function render($values) {
  $reverse = empty($this->options['reverse']) ? 1 : -1;

  // Note: 1 is subtracted from the counter start value below because the
  // counter value is incremented by 1 at the end of this function.
  $counter_start = is_numeric($this->options['counter_start']) ? $this->options['counter_start'] : 0;
  $count = $reverse == -1 ? count($this->view->result) + $counter_start : $counter_start - 1;
  $pager = $this->view->query->pager;

  // Get the base count of the pager.
  if ($pager
    ->use_pager()) {
    if ($reverse == -1) {
      $count = $pager->total_items + $counter_start - $pager
        ->get_current_page() * $pager
        ->get_items_per_page() + $pager
        ->get_offset();
    }
    else {
      $count += ($pager
        ->get_items_per_page() * $pager
        ->get_current_page() + $pager
        ->get_offset()) * $reverse;
    }
  }

  // Add the counter for the current site.
  $count += ($this->view->row_index + 1) * $reverse;
  return $count;
}