You are here

class apachesolr_views_handler_argument in Apache Solr Views 6

Same name and namespace in other branches
  1. 7 handlers/apachesolr_views_handler_argument.inc \apachesolr_views_handler_argument

Class that allows searching the site with Apache Solr through a view.

Hierarchy

Expanded class hierarchy of apachesolr_views_handler_argument

2 string references to 'apachesolr_views_handler_argument'
apachesolr_views_views_data in ./apachesolr_views.views.inc
Implementation of hook_views_data().
apachesolr_views_views_handlers in ./apachesolr_views.views.inc
Implementation of hook_views_handlers().

File

handlers/apachesolr_views_handler_argument.inc, line 7

View source
class apachesolr_views_handler_argument extends views_handler_argument {

  /**
   * Add argument to query.
   */
  public function query() {
    if (!empty($this->options['break_phrase'])) {
      $this->value = explode(',', $this->argument);
    }
    else {
      $this->value = array(
        $this->argument,
      );
    }
    foreach ($this->value as $facet_value) {
      $this->query
        ->add_filter($this->real_field, apachesolr_views_query::escape_term($facet_value), $this->options['not']);
    }
  }
  function option_definition() {
    $options = parent::option_definition();
    $options['break_phrase'] = array(
      'default' => FALSE,
    );
    $options['not'] = array(
      'default' => FALSE,
    );
    return $options;
  }
  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);

    // allow for , delimited values
    $form['break_phrase'] = array(
      '#type' => 'checkbox',
      '#title' => t('Allow multiple terms per argument.'),
      '#description' => t('If selected, users can enter multiple arguments in the form of 1,2,3.'),
      '#default_value' => !empty($this->options['break_phrase']),
    );
    $form['not'] = array(
      '#type' => 'checkbox',
      '#title' => t('Exclude the argument'),
      '#description' => t('If selected, the numbers entered in the argument will be excluded rather than limiting the view.'),
      '#default_value' => !empty($this->options['not']),
    );
  }

  /**
   * Provide a list of default behaviors for this argument if the argument
   * is not present.
   *
   * Provide fewer methods that the standard. Remove summary views
   */
  function default_actions($which = NULL) {
    $defaults = array(
      'ignore' => array(
        'title' => t('Display all values'),
        'method' => 'default_ignore',
        'breadcrumb' => TRUE,
      ),
      'not found' => array(
        'title' => t('Hide view / Page not found (404)'),
        'method' => 'default_not_found',
        'hard fail' => TRUE,
      ),
      'empty' => array(
        'title' => t('Display empty text'),
        'method' => 'default_empty',
        'breadcrumb' => TRUE,
      ),
      'default' => array(
        'title' => t('Provide default argument'),
        'method' => 'default_default',
        'form method' => 'default_argument_form',
        'has default argument' => TRUE,
        'default only' => TRUE,
      ),
    );
    if ($which) {
      if (!empty($defaults[$which])) {
        return $defaults[$which];
      }
    }
    else {
      return $defaults;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
apachesolr_views_handler_argument::default_actions function Provide a list of default behaviors for this argument if the argument is not present.
apachesolr_views_handler_argument::options_form function
apachesolr_views_handler_argument::option_definition function
apachesolr_views_handler_argument::query public function Add argument to query. 2