Yii Advanced Filters Extension
  • Package
  • Class

Packages

  • advancedfilters
    • components
    • dbhelpers
    • filters

Classes

  • AfBaseFilter
  • AfDefaultFilter
  • AfExactFilter
  • AfRangeFilter
  • AfRegexFilter
  • AfSubstringFilter
 1 <?php
 2 
 3 /**
 4  * AfExactFilter class file.
 5  * 
 6  * @author Keith Burton <kburton@kappasoft.net>
 7  * @package advancedfilters.filters
 8  */
 9 
10 /**
11  * This filter handles exact matches.
12  */
13 class AfExactFilter extends AfBaseFilter
14 {
15     /**
16      * @var string the prefix string to identify exact match expressions.
17      */
18     public $prefix = '"';
19     
20     /**
21      * @var string the suffix string to identify exact match 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         if ($this->invertLogic)
50             $criteria->addNotInCondition($this->columnExpression,
51                     array($this->searchString));
52         else
53             $criteria->addInCondition($this->columnExpression,
54                     array($this->searchString));
55         
56         return $criteria;
57     }
58     
59     private $_expressionAccepted;
60     private function parseExpression()
61     {
62         // Only need to parse the expression once
63         if ($this->_expressionAccepted !== null)
64             return $this->_expressionAccepted;
65         
66         $this->_expressionAccepted = false;
67         
68         $result = self::stripPrefixSuffixString($this->filterExpression,
69                 $this->prefix, $this->suffix);
70         
71         if ($result !== false)
72         {
73             $this->_expressionAccepted = true;
74             $this->searchString = $result;
75         }
76         
77         return $this->_expressionAccepted;
78     }
79 }
80 
Yii Advanced Filters Extension API documentation generated by ApiGen