Version: current

     1 <?php
     2 /**
     3  * @package sapphire
     4  * @subpackage search
     5  */
     6
     7 /**
     8  * Checks if a value is in a given set.
     9  * SQL syntax used: Column IN ('val1','val2')
    10  *
    11  * @todo Add negation (NOT IN)6
    12  * @package sapphire
    13  * @subpackage search
    14  */
    15 class ExactMatchMultiFilter extends SearchFilter {
    16
    17     public function apply(SQLQuery $query) {
    18         $query = $this->applyRelation($query);
    19
    20         // hack
    21         // PREVIOUS $values = explode(',',$this->getValue());
    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                 // @todo Fix string replacement to only replace leading and tailing quotes
    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. -