BooleanOperatorString.php 988 Bytes
Newer Older
merlinofchaos's avatar
merlinofchaos committed
1 2 3 4
<?php

/**
 * @file
5
 * Definition of Drupal\views\Plugin\views\filter\BooleanOperatorString.
merlinofchaos's avatar
merlinofchaos committed
6 7
 */

8
namespace Drupal\views\Plugin\views\filter;
9

10
use Drupal\Component\Annotation\PluginID;
dawehner's avatar
dawehner committed
11

merlinofchaos's avatar
merlinofchaos committed
12 13 14 15 16 17 18 19 20 21
/**
 * Simple filter to handle matching of boolean values.
 *
 * This handler checks to see if a string field is empty (equal to '') or not.
 * It is otherwise identical to the parent operator.
 *
 * Definition items:
 * - label: (REQUIRED) The label for the checkbox.
 *
 * @ingroup views_filter_handlers
22
 *
23
 * @PluginID("boolean_string")
dawehner's avatar
dawehner committed
24
 */
25
class BooleanOperatorString extends BooleanOperator {
26

27
  public function query() {
28
    $this->ensureMyTable();
29
    $where = "$this->tableAlias.$this->realField ";
merlinofchaos's avatar
merlinofchaos committed
30 31 32 33

    if (empty($this->value)) {
      $where .= "= ''";
      if ($this->accept_null) {
34
        $where = '(' . $where . " OR $this->tableAlias.$this->realField IS NULL)";
merlinofchaos's avatar
merlinofchaos committed
35 36 37 38 39
      }
    }
    else {
      $where .= "<> ''";
    }
40
    $this->query->addWhere($this->options['group'], $where);
merlinofchaos's avatar
merlinofchaos committed
41
  }
42

merlinofchaos's avatar
merlinofchaos committed
43
}