162 lines
4.8 KiB
PHP
162 lines
4.8 KiB
PHP
<?php
|
|
|
|
namespace Ulmus\Repository;
|
|
|
|
use Ulmus\Query;
|
|
|
|
trait ConditionTrait
|
|
{
|
|
public function open(string $condition = Query\Where::CONDITION_AND) : self
|
|
{
|
|
$this->queryBuilder->open($condition);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function orOpen() : self
|
|
{
|
|
return $this->open(Query\Where::CONDITION_OR);
|
|
}
|
|
|
|
public function close() : self
|
|
{
|
|
$this->queryBuilder->close();
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function where(string|\Stringable $field, $value, string $operator = Query\Where::OPERATOR_EQUAL, $condition = Query\Where::CONDITION_AND) : self
|
|
{
|
|
$this->queryBuilder->where($field, $value, $operator, $condition);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function wheres(array $fieldValues, string $operator = Query\Where::OPERATOR_EQUAL) : self
|
|
{
|
|
foreach($fieldValues as $field => $value) {
|
|
$this->where($field, $value, $operator);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function and(string|\Stringable $field, $value, string $operator = Query\Where::OPERATOR_EQUAL) : self
|
|
{
|
|
return $this->where($field, $value, $operator);
|
|
}
|
|
|
|
public function or(string|\Stringable $field, $value, string $operator = Query\Where::OPERATOR_EQUAL) : self
|
|
{
|
|
$this->queryBuilder->where($field, $value, $operator, Query\Where::CONDITION_OR);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function notWhere(string|\Stringable $field, $value, string $operator = Query\Where::OPERATOR_EQUAL) : self
|
|
{
|
|
$this->queryBuilder->where($field, $value, $operator, Query\Where::CONDITION_AND, true);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function orNot(string|\Stringable $field, $value, string $operator = Query\Where::OPERATOR_NOT_EQUAL) : self
|
|
{
|
|
$this->queryBuilder->notWhere($field, $value, $operator, Query\Where::CONDITION_OR, true);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function having(string|\Stringable $field, $value, string $operator = Query\Where::OPERATOR_EQUAL, $condition = Query\Where::CONDITION_AND) : self
|
|
{
|
|
$this->queryBuilder->having($field, $value, $operator, $condition);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function orHaving(string|\Stringable $field, $value, string $operator = Query\Where::OPERATOR_EQUAL) : self
|
|
{
|
|
$this->queryBuilder->having($field, $value, $operator, Query\Where::CONDITION_OR);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function notHaving(string|\Stringable $field, $value, string $operator = Query\Where::OPERATOR_NOT_EQUAL) : self
|
|
{
|
|
$this->queryBuilder->having($field, $value, $operator, Query\Where::CONDITION_AND, true);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function orNotHaving(string|\Stringable $field, $value) : self
|
|
{
|
|
$this->queryBuilder->having($field, $value, Query\Where::OPERATOR_NOT_EQUAL, Query\Where::CONDITION_OR, true);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function in(string|\Stringable $field, $value, string $operator = Query\Where::COMPARISON_IN) : self
|
|
{
|
|
$this->queryBuilder->where($field, $value, $operator);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function orIn(string|\Stringable $field, $value, string $operator = Query\Where::COMPARISON_IN) : self
|
|
{
|
|
$this->queryBuilder->where($field, $value, $operator, Query\Where::CONDITION_OR);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function notIn(string|\Stringable $field, $value) : self
|
|
{
|
|
$this->queryBuilder->where($field, $value, Query\Where::COMPARISON_IN, Query\Where::CONDITION_AND, true);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function orNotIn(string|\Stringable $field, $value) : self
|
|
{
|
|
return $this->orNot($field, $value, Query\Where::COMPARISON_IN, Query\Where::CONDITION_OR, true);
|
|
}
|
|
|
|
public function like(string|\Stringable $field, $value) : self
|
|
{
|
|
$this->where($field, $value, Query\Where::OPERATOR_LIKE);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function orLike(string|\Stringable $field, $value) : self
|
|
{
|
|
$this->or($field, $value, Query\Where::OPERATOR_LIKE);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function notLike(string|\Stringable $field, $value) : self
|
|
{
|
|
$this->notWhere($field, $value, Query\Where::OPERATOR_LIKE);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function likes(array $fieldValues, string $condition = Query\Where::CONDITION_AND) : self
|
|
{
|
|
foreach($fieldValues as $field => $value) {
|
|
$this->like($field, $value);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeQueryFragment(/* Query\Fragment | stringable | array */ $fragment) : self
|
|
{
|
|
foreach((array) $fragment as $item) {
|
|
$this->queryBuilder->removeFragment($item);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
} |