1 <?php
2 3 4 5 6 7
8 class ExactMatchFilterWithEmpty extends SearchFilter {
9
10 private $need_empty = false;
11
12 function setEmpty($val=true) {
13 $this->need_empty = $val;
14 }
15
16 function setValue($val) {
17 if(is_array($val) && isset($val['IsEmpty']) && ((int)$val['IsEmpty'])) {
18 $this->setEmpty();
19 } else {
20 $this->value = $val;
21 }
22 }
23
24 25 26 27 28
29 public function apply(SQLQuery $query) {
30 $query = $this->applyRelation($query);
31 if ($this->need_empty) {
32 return $query->where(sprintf(
33 "(%s = '' OR %s IS NULL)",
34 $this->getDbName(),
35 $this->getDbName()
36 ));
37 } else {
38 return $query->where(sprintf(
39 "%s = '%s'",
40 $this->getDbName(),
41 Convert::raw2sql($this->getValue())
42 ));
43
44 }
45 }
46
47 public function isEmpty() {
48 return ($this->getValue() == null || $this->getValue() == '') && !$this->need_empty;
49 }
50 }
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the
Silverstripe Forums to ask development related questions.
-