field = $field; if($this->field == 'start_date'){ $value = intval($value); } $this->value = $value; $this->same_field_op = $same_field_op; } /** * @param mixed $value * @return $this */ public function setValue($value) { $this->value = $value; return $this; } /** * @return string */ public function getField() { return $this->field; } /** * @return mixed */ public function getValue() { switch($this->operator) { case 'like': if(is_array($this->value)){ $res = []; foreach ($this->value as $val){ $res[]= empty($val) ? '' : "%".$val."%"; } return $res; } return empty($this->value) ? '' : "%".$this->value."%"; break; default: return $this->value; break; } } public function getSameFieldOp():?string { return $this->same_field_op; } public static function makeEqual($field, $value, $same_field_op = null) { return new self($field, $value, '=', $same_field_op); } public static function makeGreather($field, $value, $same_field_op = null) { return new self($field, $value, '>', $same_field_op); } public static function makeGreatherOrEqual($field, $value, $same_field_op = null) { return new self($field, $value, '>=', $same_field_op); } public static function makeLower($field, $value, $same_field_op = null) { return new self($field, $value, '<', $same_field_op); } public static function makeLowerOrEqual($field, $value, $same_field_op = null) { return new self($field, $value, '<=', $same_field_op); } public static function makeNotEqual($field, $value, $same_field_op = null) { return new self($field, $value, '<>', $same_field_op); } public static function makeLike($field, $value, $same_field_op = null) { return new self($field, $value, 'like', $same_field_op); } public function __toString():string { return sprintf("%s%s%s", $this->field, $this->operator, is_array($this->value)? json_encode($this->value):$this->value); } }