public function alter_query_with_value(Query $query, $value) { if (!$value) { return $query; } $field = $this->id; list($year, $month, $day) = explode('-', $value) + [0, 0, 0]; if ($day) { $query->and("DATE(`{$field}`) = ?", "{$year}-{$month}-{$day}"); } else { if ($month) { $query->and("YEAR(`{$field}`) = ? AND MONTH(`{$field}`) = ?", (int) $year, (int) $month); } else { if ($year) { $query->and("YEAR(`{$field}`) = ?", (int) $year); } } } return $query; }
public function alter_query_with_filter(Query $query, $filter_value) { if ($filter_value) { list($type, $name) = explode(':', $filter_value); if ($type == 'operation') { $query->and('class LIKE ?', '%\\' . $name . 'Operation'); } } return $query; }
/** * Alters the query according to the specified value. * * The method handles {@link IntervalCriterionValue} and {@link SetCriterionValue} instances as well * as plain values, for which a simple `{$this->id} = {$value}` is done. * * Subclasses might want to override the method according to the kind of value they provide. * * @param Query $query * @param mixed $value The criterion value. Special care is taken if the param is an * instance of {@link IntervalCriterionValue} or {@link SetCriterionValue}. * * @return Query */ public function alter_query_with_value(Query $query, $value) { if ($value instanceof IntervalCriterionValue) { if ($value->min === null) { return $query->and("`{$this->column_name}` <= ?", $value->max); } if ($value->max === null) { return $query->and("`{$this->column_name}` >= ?", $value->min); } return $query->and("`{$this->column_name}` BETWEEN ? AND ?", $value->min, $value->max); } if ($value instanceof SetCriterionValue) { $value = $value->to_array(); } return $query->and([$this->column_name => $value]); }