- Work done on many-to-many relations - code must still be refactored out of the EntityTrait.

- Fixed Entity::field("propertyname") function to look for name into @Field() annotation and returns it if it exists.
- A lot of bug fixes made into SQL fragments.
This commit is contained in:
Dave Mc Nicoll committed 2020-04-09 09:50:09 -04:00
1 parent 6e84fc7195
commit c64c7778bd
20 files changed
+220 -105

No files matched your search

+32 -19
View File
@@ -6,6 +6,8 @@ class QueryBuilder
{
public Query\Where $where;
public Query\Having $having;
/**
* Those are the parameters we are going to bind to PDO.
*/
@@ -17,7 +19,9 @@ class QueryBuilder
*/
public array $values = [];
public string $conditionOperator = Query\Where::CONDITION_AND;
public string $whereConditionOperator = Query\Where::CONDITION_AND;
public string $havingConditionOperator = Query\Having::CONDITION_AND;
protected int $parameterIndex = 0;
@@ -166,12 +170,29 @@ class QueryBuilder
$this->push($where);
}
$this->conditionOperator = $operator;
$this->whereConditionOperator = $operator;
$where->add($field, $value, $operator, $condition, $not);
return $this;
}
public function having($field, $value, string $operator = Query\Having::OPERATOR_EQUAL, string $condition = Query\Having::CONDITION_AND, bool $not = false) : self
{
if ( $this->having ?? false ) {
$having = $this->having;
}
elseif ( null === ( $having = $this->getFragment(Query\Having::class) ) ) {
$this->having = $having = new Query\Having($this);
$this->push($having);
}
$this->havingConditionOperator = $operator;
$having->add($field, $value, $operator, $condition, $not);
return $this;
}
public function notWhere($field, $value, string $operator = Query\Where::CONDITION_AND) : self
{
return $this->where($field, $value, $operator, true);
@@ -179,7 +200,7 @@ class QueryBuilder
public function groupBy() : self
{
//$this->queryBuilder->groupBy();
return $this;
}
@@ -219,28 +240,19 @@ class QueryBuilder
return $this;
}
public function join(string $type, $table, $field, $value, bool $outer = false) : self
public function join(string $type, /*string | QueryBuilder*/ $table, $field, $value, bool $outer = false) : self
{
if ( null === $join = $this->getFragment(Query\Join::class) ) {
$join = new Query\Join();
$this->push($join);
}
#if ( null === $join = $this->getFragment(Query\Join::class) ) {#}
$join->add($type, $table, $field, $value);
$join = new Query\Join($this);
$this->push($join);
$join->set($type, $table, $field, $value);
$join->outer = $outer;
return $this;
}
/*
"LEFT JOIN PAI_DOS ON PAI_DOS.MATR = PAI_DOS_EMPL.MATR"
"LEFT JOIN PAI_DOS_2 ON PAI_DOS_2.MATR = PAI_DOS.MATR"
"LEFT JOIN PAI_CAND ON PAI_CAND.MATR = PAI_DOS.MATR"
"LEFT JOIN PAI_TAB_CORP_EMPL ON PAI_TAB_CORP_EMPL.CORP_EMPL = PAI_DOS_EMPL.CORP_EMPL",
"LEFT JOIN PAI_TAB_LIEU_TRAV ON PAI_TAB_LIEU_TRAV.LIEU_TRAV = PAI_DOS_EMPL.LIEU_TRAV",
"LEFT JOIN PAI_TAB_BAT ON PAI_TAB_BAT.BAT = PAI_TAB_LIEU_TRAV.BAT"
*/
public function push(Query\Fragment $queryFragment) : self
{
$this->queryStack[] = $queryFragment;
@@ -266,7 +278,8 @@ class QueryBuilder
public function reset() : void
{
$this->parameters = $this->values = $this->queryStack = [];
$this->conditionOperator = Query\Where::CONDITION_AND;
$this->whereConditionOperator = Query\Where::CONDITION_AND;
$this->havingConditionOperator = Query\Having::CONDITION_AND;
$this->parameterIndex = 0;
unset($this->where);