You are here

function flag_handler_field_ops::query in Flag 6

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

Override base ::query(). The purpose here is to make it possible for the render() method to know two things: what's the content ID, and whether it's flagged.

File

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

Class

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

Code

function query() {
  $parent = $this
    ->get_parent_relationship();
  $flag = $this
    ->get_flag();
  $info = $flag
    ->get_views_info();

  // Find out if the content is flagged. We can't just peek at some field in
  // our loaded table because it doesn't always reflect the user browsing the
  // page. So we explicitly add the flag_content table to find this out.
  $join = new views_join();
  $join
    ->construct('flag_content', $info['views table'], $info['join field'], 'content_id');
  $join->extra[] = array(
    'field' => 'fid',
    'value' => $flag->fid,
    'numeric' => TRUE,
  );
  if (!$flag->global) {
    $join->extra[] = array(
      'field' => 'uid',
      'value' => '***CURRENT_USER***',
      'numeric' => TRUE,
    );
  }
  $flag_table = $this->query
    ->add_table('flag_content', $parent, $join);
  $this->aliases['is_flagged'] = $this->query
    ->add_field($flag_table, 'content_id');

  // Next, find out the content ID. We can't add_field() on this table
  // (flag_content), because its content_id may be NULL (in case no user has
  // flagged this content, and it's a LEFT JOIN). So we reach to the parent
  // relationship and add_field() *its* content ID column.
  $left_table = $this->view->relationship[$this->options['relationship']]->table_alias;
  $this->aliases['content_id'] = $this->query
    ->add_field($left_table, $info['join field']);
}