Fixes to SqlSelectStatement
This commit is contained in:
parent
0b10221fed
commit
ec16073539
2 changed files with 24 additions and 8 deletions
|
@ -8,7 +8,7 @@ class TagSearchParser extends AbstractSearchParser
|
|||
->addInnerJoin('post_tag', new SqlEqualsOperator('tag.id', 'post_tag.tag_id'))
|
||||
->addInnerJoin('post', new SqlEqualsOperator('post.id', 'post_tag.post_id'))
|
||||
->setCriterion((new SqlConjunction)->add(SqlInOperator::fromArray('safety', SqlBinding::fromArray($allowedSafety))))
|
||||
->groupBy('tag.id');
|
||||
->setGroupBy('tag.id');
|
||||
}
|
||||
|
||||
protected function processSimpleToken($value, $neg)
|
||||
|
|
|
@ -7,7 +7,7 @@ class SqlSelectStatement extends SqlStatement
|
|||
protected $columns = null;
|
||||
protected $source = null;
|
||||
protected $innerJoins = [];
|
||||
protected $outerJoins = [];
|
||||
protected $leftOuterJoins = [];
|
||||
protected $criterion = null;
|
||||
protected $orderBy = [];
|
||||
protected $limit = null;
|
||||
|
@ -68,12 +68,28 @@ class SqlSelectStatement extends SqlStatement
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function addOuterJoin($table, $expression)
|
||||
public function addLeftOuterJoin($table, $expression)
|
||||
{
|
||||
$this->innerJoins []= [$table, $this->attachExpression($expression)];
|
||||
$this->leftOuterJoins []= [$table, $this->attachExpression($expression)];
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getJoinedTables()
|
||||
{
|
||||
$tables = [];
|
||||
foreach (array_merge($this->innerJoins, $this->leftOuterJoins) as $join)
|
||||
{
|
||||
list ($table, $joinExpression) = $join;
|
||||
$tables []= $table;
|
||||
}
|
||||
return array_unique($tables);
|
||||
}
|
||||
|
||||
public function isTableJoined($table)
|
||||
{
|
||||
return in_array($table, $this->getJoinedTables());
|
||||
}
|
||||
|
||||
public function getCriterion()
|
||||
{
|
||||
return $this->criterion;
|
||||
|
@ -123,7 +139,7 @@ class SqlSelectStatement extends SqlStatement
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function groupBy($groupBy)
|
||||
public function setGroupBy($groupBy)
|
||||
{
|
||||
$this->groupBy = $this->attachExpression($groupBy);
|
||||
}
|
||||
|
@ -146,10 +162,10 @@ class SqlSelectStatement extends SqlStatement
|
|||
$sql .= ' INNER JOIN ' . $table . ' ON ' . $criterion->getAsString();
|
||||
}
|
||||
|
||||
foreach ($this->outerJoins as $outerJoin)
|
||||
foreach ($this->leftOuterJoins as $outerJoin)
|
||||
{
|
||||
list ($table, $criterion) = $join;
|
||||
$sql .= ' OUTER JOIN ' . $table . ' ON ' . $criterion->getAsString();
|
||||
list ($table, $criterion) = $outerJoin;
|
||||
$sql .= ' LEFT OUTER JOIN ' . $table . ' ON ' . $criterion->getAsString();
|
||||
}
|
||||
|
||||
if (!empty($this->criterion) and !empty($this->criterion->getAsString()))
|
||||
|
|
Loading…
Reference in a new issue