You are here

class flag_handler_relationship_counts in Flag 6

Same name and namespace in other branches
  1. 6.2 includes/flag_handler_relationships.inc \flag_handler_relationship_counts
  2. 7.3 includes/views/flag_handler_relationships.inc \flag_handler_relationship_counts
  3. 7.2 includes/flag_handler_relationships.inc \flag_handler_relationship_counts

Specialized relationship handler associating flag counts and content.

Hierarchy

Expanded class hierarchy of flag_handler_relationship_counts

1 string reference to 'flag_handler_relationship_counts'
flag_views_data_alter in includes/flag.views.inc
Implementation of hook_views_data_alter().

File

includes/flag_handler_relationships.inc, line 93
Contains various relationship handlers.

View source
class flag_handler_relationship_counts extends views_handler_relationship {
  function option_definition() {
    $options = parent::option_definition();
    $content_type = $this->definition['flag type'];
    $options['flag'] = array(
      'default' => flag_views_flag_default($content_type),
    );
    $options['required'] = array(
      'default' => 1,
    );
    return $options;
  }
  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);
    $content_type = $this->definition['flag type'];
    $form['flag'] = flag_views_flag_config_form('radios', $content_type, $this->options['flag']);
    $form['required']['#title'] = t('Include only flagged content');
    $form['required']['#description'] = t('If checked, only content that is flagged will be included.');
  }
  function admin_summary() {

    // Nothing to show.
  }
  function ui_name() {

    // We put the bookmark name in the UI string to save space.
    return t('!group: !title counter', array(
      '!group' => $this->definition['group'],
      '!title' => $this->options['flag'],
    ));
  }

  /**
   * Called to implement a relationship in a query.
   */
  function query() {
    $flag = flag_get_flag($this->options['flag']);
    $this->definition['extra'][] = array(
      'field' => 'fid',
      'value' => $flag->fid,
      'numeric' => TRUE,
    );
    if (!empty($this->options['required'])) {

      // Unfortunately, we may have zeros in our table, so having
      // parent::query() do INNER JOIN doesn't suffice. We need to filter these
      // zeros out.
      // @todo Make sure zero records aren't written in the first place, and
      // remove this code.
      $this->definition['extra'][] = array(
        'field' => 'count',
        'operator' => '>',
        'value' => '0',
        'numeric' => TRUE,
      );
    }
    parent::query();
  }

}

Members