You are here

function flag_handler_field_ops::pre_render in Flag 7.2

Same name and namespace in other branches
  1. 6.2 includes/flag_handler_field_ops.inc \flag_handler_field_ops::pre_render()
  2. 6 includes/flag_handler_field_ops.inc \flag_handler_field_ops::pre_render()
  3. 7.3 includes/views/flag_handler_field_ops.inc \flag_handler_field_ops::pre_render()

Find out if the flag applies to each item seen on the page. It's done in a separate DB query to to avoid complexity and to make 'many to one' tests (e.g. checking user roles) possible without causing duplicate rows.

Overrides views_handler_field::pre_render

File

includes/flag_handler_field_ops.inc, line 112
Contains the flag Ops field handler.

Class

flag_handler_field_ops
Views field handler for the Flag operations links (flag/unflag).

Code

function pre_render(&$values) {
  if (!($flag = $this
    ->get_flag())) {
    return;

    // Error message is printed in render().
  }
  $ids = array();
  foreach ($values as $row) {
    $content_id = $row->{$this->aliases['content_id']};
    $is_flagged = $row->{$this->aliases['is_flagged']};
    if (isset($content_id)) {
      $ids[$content_id] = $is_flagged ? 'unflag' : 'flag';
    }
  }
  $this->flag_applies = $ids ? $flag
    ->access_multiple($ids) : array();
}