You are here

views_handler_filter_heartbeat_module.inc in Heartbeat 6.3

File

views/handlers/views_handler_filter_heartbeat_module.inc
View source
<?php

/**
 * Filter by module
 */
class views_handler_filter_heartbeat_module extends views_handler_filter_numeric {
  function construct() {
    parent::construct();
    $this->value_value = t('Is module');
    $this->value['module'] = '';
  }

  /**
   * Implementation override option_definition
   * Information about options for all kinds of purposes will be held here.
   *
   * @return array options definition
   */
  function option_definition() {
    $options = parent::option_definition();
    return $options;
  }

  /**
   * Set default values for the heartbeat access filter.
   */
  function options(&$options) {
    parent::options($options);
    $options['value']['module'] = '';
  }

  /**
   * Definition of available operators
   * Override the parent method
   *
   * @return array of operators
   */
  function operators() {
    $operators = array(
      '=' => array(
        'title' => t('Is equal to'),
        'method' => 'op_simple',
        'short' => t('='),
        'values' => 1,
      ),
      '!=' => array(
        'title' => t('Is not equal to'),
        'method' => 'op_simple',
        'short' => t('!='),
        'values' => 1,
      ),
    );
    return $operators;
  }

  /**
   * Display the filter on the administrative summary.
   * After selecting, let the builder of the view
   * know what he selected
   *
   * @return human title for the module
   */
  function admin_summary() {
    $options = module_list();
    $key = (int) (isset($this->value['module']) ? $this->value['module'] : '');
    $return = $options[$key];
    return $return;
  }

  /**
   * Add a type selector to the value form
   */
  function value_form(&$form, &$form_state) {
    if (empty($form_state['exposed'])) {
      $form['value']['module'] = array(
        '#type' => 'select',
        '#title' => t('Module'),
        '#options' => module_list(),
        '#default_value' => !empty($this->value['module']) ? $this->value['module'] : '',
      );
    }
    parent::value_form($form, $form_state);
  }
  function query() {
    $this
      ->ensure_my_table();
    $field = "{$this->table_alias}.{$this->real_field}";
    $op = empty($this->value) ? '!=' : '=';
    $value = $this->value['module'];
    $this->query
      ->add_where($this->options['group'], $field . $op . " '%s'", $value);
  }

}

Classes

Namesort descending Description
views_handler_filter_heartbeat_module Filter by module