You are here

function flag_clear_handler_field_clear::pre_render in Flag clear 7

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/views/flag_clear_handler_field_clear.inc, line 128
Contains the flag clearing field handler.

Class

flag_clear_handler_field_clear
Views field handler for the Flag clearing links.

Code

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

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