1 <?php
2 3 4 5
6
7 8 9 10 11 12 13 14
15 class ExactMatchMultiFilter extends SearchFilter {
16
17 public function apply(SQLQuery $query) {
18 $query = $this->applyRelation($query);
19
20
21
22 $values = array();
23 if (is_string($this->getValue())) {
24 $values = explode(',',$this->getValue());
25 }
26 else {
27 foreach($this->getValue() as $v) {
28 $values[] = $v;
29 }
30 }
31
32
33 if(! $values) return false;
34 for($i = 0; $i < count($values); $i++) {
35 if(! is_numeric($values[$i])) {
36
37 $values[$i] = str_replace("'", '', $values[$i]);
38 $values[$i] = Convert::raw2sql($values[$i]);
39 }
40 }
41 $SQL_valueStr = "'" . implode("','", $values) . "'";
42
43 return $query->where(sprintf(
44 "%s IN (%s)",
45 $this->getDbName(),
46 $SQL_valueStr
47 ));
48 }
49
50 public function isEmpty() {
51 return $this->getValue() == null || $this->getValue() == '';
52 }
53 }
54 ?>
[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.
-