Yii Advanced Filters Extension
  • Package
  • Class

Packages

  • advancedfilters
    • components
    • dbhelpers
    • filters

Classes

  • AfBaseFilter
  • AfDefaultFilter
  • AfExactFilter
  • AfRangeFilter
  • AfRegexFilter
  • AfSubstringFilter
 1 <?php
 2 
 3 /**
 4  * AfSubstringFilter class file.
 5  * 
 6  * @author Keith Burton <kburton@kappasoft.net>
 7  * @package advancedfilters.filters
 8  */
 9 
10 /**
11  * This filter handles matches of an exact substring.
12  */
13 class AfSubstringFilter extends AfBaseFilter
14 {
15     /**
16      * @var string the prefix string to identify substring expressions.
17      */
18     public $prefix = '#';
19     
20     /**
21      * @var string the suffix string to identify substring expressions.
22      */
23     public $suffix = '#';
24     
25     private $searchString;
26     
27     /**
28      * Determines whether the provided expression can be processed by this
29      * filter class.
30      * 
31      * @return boolean whether this class can process the expression.
32      */
33     public function acceptsFilterExpression()
34     {
35         return $this->parseExpression();
36     }
37     
38     /**
39      * Builds a new CDbCriteria object based on the expression provided.
40      * 
41      * @return CDbCriteria the new criteria object.
42      */
43     public function getCriteria()
44     {
45         $this->parseExpression();
46         
47         $criteria = new CDbCriteria;
48         
49         $criteria->addSearchCondition($this->columnExpression,
50                 $this->searchString, true, 'AND',
51                 $this->invertLogic ? 'NOT LIKE' : 'LIKE');
52         
53         return $criteria;
54     }
55     
56     private $_expressionAccepted;
57     private function parseExpression()
58     {
59         // Only need to parse the expression once
60         if ($this->_expressionAccepted !== null)
61             return $this->_expressionAccepted;
62         
63         $this->_expressionAccepted = false;
64         
65         $result = self::stripPrefixSuffixString($this->filterExpression,
66                 $this->prefix, $this->suffix);
67         
68         if ($result !== false)
69         {
70             $this->_expressionAccepted = true;
71             $this->searchString = $result;
72         }
73         
74         return $this->_expressionAccepted;
75     }
76 }
77 
Yii Advanced Filters Extension API documentation generated by ApiGen