예제 #1
0
 public static function getCondition(FilterParameter $parameter, $dateColumn = 'date')
 {
     $condition = new Condition();
     if ($parameter->getFilterBy() && $parameter->getFilterValue()) {
         switch ($parameter->getFilterOp()) {
             case 'contains':
                 $condition->add($parameter->getFilterBy(), 'LIKE', '%' . $parameter->getFilterValue() . '%');
                 break;
             case 'equals':
                 $condition->add($parameter->getFilterBy(), '=', $parameter->getFilterValue());
                 break;
             case 'startsWith':
                 $condition->add($parameter->getFilterBy(), 'LIKE', $parameter->getFilterValue() . '%');
                 break;
             case 'present':
                 $condition->add($parameter->getFilterBy(), 'IS NOT', 'NULL', 'AND');
                 $condition->add($parameter->getFilterBy(), 'NOT LIKE', '');
                 break;
         }
     }
     if ($parameter->getUpdatedSince() instanceof \DateTime) {
         $condition->add($dateColumn, '>', $parameter->getUpdatedSince()->format(DateTime::SQL));
     }
     return $condition;
 }