/** * {@inheritdoc} */ protected function visitComparison(ComparisonNode $node) { if (!$this->model->hasField($node->left)) { return new ConditionBuilder('false'); } $type = $this->model->getType($node->left); $right = $type->convert($node->right); switch ($node->comparison) { case '=': case '!=': case '<=': case '>=': case '>': case '<': if ($type->isDate() or $type->isDateTime()) { $interval = I18n::stringToInterval($node->right); if (isset($interval)) { list($start, $end) = $interval; switch ($node->comparison) { case '=': $cond = new ConditionBuilder('%m.%c >= %_', $this->model, $node->left, $type, $start); $cond->and('%m.%c <= %_', $this->model, $node->left, $type, $end); return $cond; case '!=': $cond = new ConditionBuilder('%m.%c < %_', $this->model, $node->left, $type, $start); $cond->or('%m.%c > %_', $this->model, $node->left, $type, $end); return $cond; case '<': case '>=': $right = $start; break; default: $right = $end; break; } } } return new ConditionBuilder('%m.%c ' . $node->comparison . ' %_', $this->model, $node->left, $type, $right); case 'contains': return new ConditionBuilder('%m.%c LIKE %s', $this->model, $node->left, '%' . ConditionBuilder::escapeLike($right) . '%'); } return new ConditionBuilder('false'); }
/** * {@inheritdoc} */ protected function visitComparison(ComparisonNode $node) { $field = $node->left; if (!$this->model->hasField($field)) { return false; } $type = $this->model->getType($field); $right = $type->convert($node->right); if ($type->isDate() or $type->isDateTime()) { $interval = I18n::stringToInterval($node->right); if (isset($interval)) { list($start, $end) = $interval; switch ($node->comparison) { case '=': return $this->record->{$field} >= $start and $this->record->{$field} <= $end; case '!=': return $this->record->{$field} < $start or $this->record->{$field} > $end; case '<': case '>=': $right = $start; break; default: $right = $end; break; } } } switch ($node->comparison) { case '=': return $this->record->{$field} == $right; case '!=': return $this->record->{$field} != $right; case '<=': return $this->record->{$field} <= $right; case '>=': return $this->record->{$field} >= $right; case '>': return $this->record->{$field} > $right; case '<': return $this->record->{$field} < $right; case 'contains': return stripos($this->record->{$field}, $node->right) !== false; } }