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:----qjB+1XGBdOGpYhCbNWu39s8CnW4bePwjOpR6MqMxbIkciUskOy4l8fiwtME/79rJ9KaIRkSrf9EXZjuMCBeASh422AvNnzoPtKFkgG2ThbvlT3dpRSgCjZnGGmcYzPmlhsdEY6R0AbLvkKeiI6pnYaZHokqZNGVZR2b4wskqEglWzIh2C5BDb2xnCMOhiw5tLGe+Kj5JyE8W4XxRaUKYUL0vE/JZDCdBZJrPmw6HuHYhiSzw3+gyUwgKCyTGkKcKBCSNttXlRjlQ2BYy2Ha0LUF0pkqr7ETBxUVi73vc6EP1WuG3ffvy5SDsP52l+Nv7PAlHb8N9ElMPVyM8qYCJuM+Gd11YjM/UXgLaAtBZvZm6d/8qJrmYo2e4Wd+o5viZuT0oHa/53Ify/9ZRYOO/U/TXm0ltiUaR5H01Jeo8DcSb/Z7QPx3dtFqBnR/WtF17UW6RNlHSbR61/0L0mqre2zyXD6f++h4hhQXlIPynBWbHykGPUl2RRsFZTiffFEZYN5iiqrGJ+v/oMmlqRAwYH6JL0JEWSRxdc8+xWG+PU1NHG4DnXPlOyykW0a6L1uaadk4ovWo8uNqvhB1xf0+MP1opyvvzsVMAMhO/Lsm91SlvWQ1yV57oGsEtrhrMD1Xv6nGzGjPWdi1UKML19cTRkZgObembl75VsS3IZNgU7UY=----ATTACHMENT:----Nzc2MDExMDI1ODYzNzI5MSA3MTU4Mjg5NzE2NjExMzkgMjU5NzE3MTM2NDM1OTEwNg==