Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relax joins for child classes and parameter suffix #1438

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions plugins/manager/lib/yform/manager/query.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class rex_yform_manager_query implements IteratorAggregate, Countable
private $select = [];

/** @var list<string> */
private $joins = [];
protected $joins = [];

/** @var 'AND'|'OR' */
private $whereOperator = 'AND';
Expand All @@ -36,6 +36,8 @@ class rex_yform_manager_query implements IteratorAggregate, Countable
private $params = [];
/** @var array<self::PARAM_*, int> */
private $paramCounter = [];
/** @var string $paramSuffix Additional infix between $type prefix and {@see $paramCounter} */
private $paramSuffix = '';

/** @var list<string> */
private $orderBy = [];
Expand Down Expand Up @@ -781,6 +783,22 @@ public function count(): int
return (int) $sql->getValue('count');
}

/**
* Add a suffix to all bound parameters in this query. A suffix is needed if multiple queries are combined in a
* single execute.
*
* @param string $paramSuffix
*
* @return static
* @see addParam()
*/
protected function setParamSuffix(string $paramSuffix): static
{
$this->paramSuffix = $paramSuffix;

return $this;
}

public function exists(): bool
{
$query = clone $this;
Expand Down Expand Up @@ -841,7 +859,7 @@ private function addParam(string $type, $value): string
{
$this->paramCounter[$type] = ($this->paramCounter[$type] ?? 0) + 1;

$param = $type.$this->paramCounter[$type];
$param = $type.$this->paramCounter[$type].$this->paramSuffix;
$this->params[$type][$param] = $this->normalizeValue($value);

return ':'.$param;
Expand Down