Version: current

     1 <?php
     2 /**
     3  * @package sapphire
     4  * @subpackage search
     5  */
     6
     7 /**
     8  * Checks if a value starts with one of the items of 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 StartsWithMultiFilter extends SearchFilter {
    16
    17     public function apply(SQLQuery $query) {
    18         $query = $this->applyRelation($query);
    19         $values = explode(',', $this->getValue());
    20
    21         foreach($values as $value) {
    22             $matches[] = sprintf("%s LIKE '%s%%'",
    23                 $this->getDbName(),
    24                 Convert::raw2sql(str_replace("'", '', $value))
    25             );
    26         }
    27
    28         return $query->where(implode(" OR ", $matches));
    29     }
    30
    31     public function isEmpty() {
    32         return $this->getValue() == null || $this->getValue() == '';
    33     }
    34 }
    35 ?>

[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. -