*/ private array $joins = []; /** * @var list> */ private array $joinParams = []; /** * @var array> */ private array $joinTypes = []; /** * @var array */ private array $wheres = []; /** * @var array> */ private array $whereParams = []; /** * @var array> */ private array $whereTypes = []; public function __construct( private readonly string $selectKeyString, private readonly string $selectIdentifierJsonB, private readonly string $selectDate, private string $from = '', private array $selectIdentifierParams = [], private array $selectIdentifierTypes = [], private array $selectDateParams = [], private array $selectDateTypes = [], ) { } public function addJoinClause(string $sql, array $params = [], array $types = []): int { $this->joins[] = $sql; $this->joinParams[] = $params; $this->joinTypes[] = $types; return count($this->joins) - 1; } public function addWhereClause(string $sql, array $params = [], array $types = []): int { $this->wheres[] = $sql; $this->whereParams[] = $params; $this->whereTypes[] = $types; return count($this->wheres) - 1; } public function removeWhereClause(int $index): void { if (!array_key_exists($index, $this->wheres)) { throw new \UnexpectedValueException("this index does not exists"); } unset($this->wheres[$index], $this->whereParams[$index], $this->whereTypes[$index]); } public function removeJoinClause(int $index): void { if (!array_key_exists($index, $this->joins)) { throw new \UnexpectedValueException("this index does not exists"); } unset($this->joins[$index], $this->joinParams[$index], $this->joinTypes[$index]); } public function getSelectKeyString(): string { return $this->selectKeyString; } public function getSelectIdentifierJsonB(): string { return $this->selectIdentifierJsonB; } /** * @inheritDoc */ public function getSelectIdentifierParams(): array { return $this->selectIdentifierParams; } public function getSelectIdentifiersTypes(): array { return $this->selectIdentifierTypes; } public function getSelectDate(): string { return $this->selectDate; } public function getSelectDateTypes(): array { return $this->selectDateTypes; } /** * @inheritDoc */ public function getSelectDateParams(): array { return $this->selectDateParams; } public function getFromQuery(): string { return $this->from . " " . implode(' ', $this->joins); } /** * @inheritDoc */ public function getFromQueryParams(): array { $result = []; foreach ($this->joinParams as $params) { $result = [...$result, ...$params]; } return $result; } public function getFromQueryTypes(): array { $result = []; foreach ($this->joinTypes as $types) { $result = [...$result, ...$types]; } return $result; } public function getWhereQuery(): string { return implode(' AND ', $this->wheres); } /** * @inheritDoc */ public function getWhereQueryParams(): array { $result = []; foreach ($this->whereParams as $params) { $result = [...$result, ...$params]; } return $result; } public function getWhereQueryTypes(): array { $result = []; foreach ($this->whereTypes as $types) { $result = [...$result, ...$types]; } return $result; } public function setSelectIdentifierParams(array $selectIdentifierParams): self { $this->selectIdentifierParams = $selectIdentifierParams; return $this; } public function setSelectDateParams(array $selectDateParams): self { $this->selectDateParams = $selectDateParams; return $this; } public function setFrom(string $from): self { $this->from = $from; return $this; } public function setSelectIdentifierTypes(array $selectIdentifierTypes): self { $this->selectIdentifierTypes = $selectIdentifierTypes; return $this; } public function setSelectDateTypes(array $selectDateTypes): self { $this->selectDateTypes = $selectDateTypes; return $this; } }