From fa86cf63a7bcdc7b351941da3ca26b7e39ba26ae Mon Sep 17 00:00:00 2001 From: Dominik Grothaus Date: Fri, 7 Jul 2023 13:46:04 +0200 Subject: [PATCH] Relax joins for child classes and parameter suffix Allow child classes to modify the array of join queries. Allow child classes to specify a suffix that's appended to each bound parameter for a query. --- plugins/manager/lib/yform/manager/query.php | 22 +++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/plugins/manager/lib/yform/manager/query.php b/plugins/manager/lib/yform/manager/query.php index 87b63249..5e919f43 100644 --- a/plugins/manager/lib/yform/manager/query.php +++ b/plugins/manager/lib/yform/manager/query.php @@ -20,7 +20,7 @@ class rex_yform_manager_query implements IteratorAggregate, Countable private $select = []; /** @var list */ - private $joins = []; + protected $joins = []; /** @var 'AND'|'OR' */ private $whereOperator = 'AND'; @@ -36,6 +36,8 @@ class rex_yform_manager_query implements IteratorAggregate, Countable private $params = []; /** @var array */ private $paramCounter = []; + /** @var string $paramSuffix Additional infix between $type prefix and {@see $paramCounter} */ + private $paramSuffix = ''; /** @var list */ private $orderBy = []; @@ -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; @@ -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;