Example #1
0
 /**
  * @param null|string $prefix
  * @return string
  */
 public function getSql($prefix = null)
 {
     $operatorSQL = array('equalTo' => '=', 'lessThanOrEqualTo' => '<=', 'greaterThanOrEqualTo' => '>=', 'notEqualTo' => '!=', 'isNull' => 'IS NULL', 'notIsNull' => 'IS NOT NULL', 'greaterThan' => '>', 'lessThan' => '<', 'in' => 'IN');
     $sql = array();
     foreach ($this->getCritereLst() as $critere) {
         if ($this->critereIsActive($critere)) {
             if (preg_match('/_date/', $critere->getKey())) {
                 $date = new DateTime($critere->getValue());
                 $value = "convert(datetime, '{$date->format('d/m/Y')}')";
             } elseif (is_array($critere->getValue())) {
                 $value = "('" . implode("', '", $critere->getValue()) . "')";
             } else {
                 $value = "'" . $critere->getValue() . "'";
             }
             $sql[] = $prefix . $critere->getKey() . ' ' . $operatorSQL[$critere->getOperator()] . ' ' . $value;
         }
     }
     return implode(' AND ', $sql);
 }
Example #2
0
 public function filter($value)
 {
     $value = new DateTime($value);
     return new Expression('convert(datetime, ?)', $value->format('d/m/Y'));
 }