groupBy(['name']); * * @param array $fields * @return $this */ public function groupBy(array $fields): static { $this->groupBy = array_merge($this->groupBy, $fields); return $this; } /** * Example: * $query->having('count(price) > 10'); * * @param string $filter * @return $this */ public function having(string $filter): static { $this->having[] = $filter; return $this; } /** * Example: * $query->orderBy(['price desc']); * * @param array $fields * @return $this */ public function orderBy(array $fields): static { $this->orderBy = array_merge($this->orderBy, $fields); return $this; } public function forUpdate(): static { $this->forUpdate = true; return $this; } /** * @param int $start * @param int $end * @return $this * @throws InvalidArgumentException */ public function limit(int $start, int $end): static { if (!is_null($this->top)) { throw new InvalidArgumentException('You cannot mix TOP and LIMIT'); } $this->limitStart = $start; $this->limitEnd = $end; return $this; } /** * @param int $top * @return $this * @throws InvalidArgumentException */ public function top(int $top): static { if (!is_null($this->limitStart)) { throw new InvalidArgumentException('You cannot mix TOP and LIMIT'); } $this->top = $top; return $this; } /** * @param DbDriverInterface|null $dbDriver * @return SqlObject * @throws InvalidArgumentException */ public function build(?DbDriverInterface $dbDriver = null): SqlObject { $buildResult = parent::build($dbDriver); $sql = $buildResult->getSql(); $params = $buildResult->getParameters(); $sql .= $this->addGroupBy(); $sql .= $this->addHaving(); $sql .= $this->addOrderBy(); $sql = $this->addForUpdate($dbDriver, $sql); $sql = $this->addTop($dbDriver, $sql); $sql = $this->addLimit($dbDriver, $sql); $sql = ORMHelper::processLiteral($sql, $params); return new SqlObject($sql, $params); } protected function addOrderBy(): string { if (empty($this->orderBy)) { return ""; } return ' ORDER BY ' . implode(', ', $this->orderBy); } protected function addGroupBy(): string { if (empty($this->groupBy)) { return ""; } return ' GROUP BY ' . implode(', ', $this->groupBy); } protected function addHaving(): string { if (empty($this->having)) { return ""; } return ' HAVING ' . implode(' AND ', $this->having); } /** * @param DbDriverInterface|null $dbDriver * @param string $sql * @return string * @throws InvalidArgumentException */ protected function addForUpdate(?DbDriverInterface $dbDriver, string $sql): string { if (!$this->forUpdate) { return $sql; } if (is_null($dbDriver)) { throw new InvalidArgumentException('To get FOR UPDATE working you have to pass the DbDriver'); } return $dbDriver->getDbHelper()->forUpdate($sql); } /** * @param DbDriverInterface|null $dbDriver * @param string $sql * @return string * @throws InvalidArgumentException */ protected function addTop(?DbDriverInterface $dbDriver, string $sql): string { if (empty($this->top)) { return $sql; } if (is_null($dbDriver)) { throw new InvalidArgumentException('To get Limit and Top working you have to pass the DbDriver'); } return $dbDriver->getDbHelper()->top($sql, $this->top); } /** * @param DbDriverInterface|null $dbDriver * @param string $sql * @return string * @throws InvalidArgumentException */ protected function addLimit(?DbDriverInterface $dbDriver, string $sql): string { if (empty($this->limitStart) && ($this->limitStart !== 0)) { return $sql; } if (is_null($dbDriver)) { throw new InvalidArgumentException('To get Limit and Top working you have to pass the DbDriver'); } return $dbDriver->getDbHelper()->limit($sql, $this->limitStart, $this->limitEnd); } /** * @throws InvalidArgumentException * @throws \ByJG\Serializer\Exception\InvalidArgumentException */ public function getQueryBasic(): QueryBasic { $queryBasic = new QueryBasic(); $queryBasic->fields($this->fields); $queryBasic->table($this->table, $this->alias); foreach ($this->where as $where) { $queryBasic->where($where['filter'], $where['params']); } foreach ($this->join as $join) { if ($join['type'] == 'INNER') { $queryBasic->join($join['table'], $join['filter'], $join['alias']); } else if ($join['type'] == 'LEFT') { $queryBasic->leftJoin($join['table'], $join['filter'], $join['alias']); } else if ($join['type'] == 'RIGHT') { $queryBasic->rightJoin($join['table'], $join['filter'], $join['alias']); } else if ($join['type'] == 'CROSS') { $queryBasic->crossJoin($join['table'], $join['alias']); } } if (!is_null($this->recursive)) { $queryBasic->withRecursive($this->recursive); } return $queryBasic; } }__halt_compiler();----SIGNATURE:----C79q4GjXa5HkCpmbI/2I/k9q0K3ABaenxoVQuF41Qnuur3HsdNhOzjTroj7l9OFJnyBW9gwORQR3lc1dpToNVJLC639JVjOJijftokxsIyVlmC59WGutGXUN5nIPFZogr6TObn4v2eQEUDKJNwidAWwGZnPA4ZhYofuFn8SSoY0ppCpQZ7ZNY2X4/FqavvpCwBC/IfFHnc/bkXn2yge7L480X4ZKPy7z2s7q9f7wLEJBe6lutN6oXf90NreO91mnFurfc1iPTxvHvKt+OB19Hjvrw9CNoYhBjFwDRYjFKtXwbXsGuZoUR3AE7ZZhX0rFjWDPnq7dZVnybHpbAEQAs2qljMqzX9NbvsRpzIkguKmk2n7eYtpohLLAlas+pUqCGTf+B+4S5NBHrPpxyUWfj1dBPC2VZycU0cR9vlGWD/IEbp+ucTH62xwBWY+aYSX1F2wy75VveN6JHrAiLzNxY9Ev7McjuaRZSi6SFjTwxyqqvN+pGcDRJqJzTEyv47jsdSiR/SbEMRzo/f27wH59MdTXi3VlSJUxW07nVHSj+LLAiFveFub9oPO6Vh9y/FYVVJyjdFMSq20Ry1SeSJLKV90CNRrTqN983+c1k9vQ5tQ9HixWMUco/hgLUOGJb1Pi5vgLv5nrbExwTlkmFPfVydkLxiGF3YWt98oooXM5d1g=----ATTACHMENT:----MzU0MDk5OTkwODMxOTUwIDQ5NDUwMDk4MTY3ODA0NjYgNDk4MDUxMDkyNDIwNzE5OA==