mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
86 lines
2.2 KiB
PHP
86 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace Chill\MainBundle\Search;
|
|
|
|
class SearchApiQuery
|
|
{
|
|
private ?string $selectKey;
|
|
private array $selectKeyParams = [];
|
|
private ?string $jsonbMetadata;
|
|
private array $jsonbMetadataParams = [];
|
|
private ?string $pertinence;
|
|
private array $pertinenceParams = [];
|
|
private ?string $fromClause;
|
|
private array $fromClauseParams = [];
|
|
private ?string $whereClause;
|
|
private array $whereClauseParams = [];
|
|
|
|
public function setSelectKey(string $selectKey, array $params = []): self
|
|
{
|
|
$this->selectKey = $selectKey;
|
|
$this->selectKeyParams = $params;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setSelectJsonbMetadata(string $jsonbMetadata, array $params = []): self
|
|
{
|
|
$this->jsonbMetadata = $jsonbMetadata;
|
|
$this->jsonbMetadataParams = $params;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setSelectPertinence(string $pertinence, array $params = []): self
|
|
{
|
|
$this->pertinence = $pertinence;
|
|
$this->pertinenceParams = $params;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setFromClause(string $fromClause, array $params = []): self
|
|
{
|
|
$this->fromClause = $fromClause;
|
|
$this->fromClauseParams = $params;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setWhereClause(string $whereClause, array $params = []): self
|
|
{
|
|
$this->whereClause = $whereClause;
|
|
$this->whereClauseParams = $params;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function buildQuery(): string
|
|
{
|
|
return \strtr("SELECT
|
|
'{key}' AS key,
|
|
{metadata} AS metadata,
|
|
{pertinence} AS pertinence
|
|
FROM {from}
|
|
WHERE {where}
|
|
", [
|
|
'{key}' => $this->selectKey,
|
|
'{metadata}' => $this->jsonbMetadata,
|
|
'{pertinence}' => $this->pertinence,
|
|
'{from}' => $this->fromClause,
|
|
'{where}' => $this->whereClause
|
|
]);
|
|
}
|
|
|
|
public function buildParameters(): array
|
|
{
|
|
return \array_merge(
|
|
$this->selectKeyParams,
|
|
$this->jsonbMetadataParams,
|
|
$this->pertinenceParams,
|
|
$this->fromClauseParams,
|
|
$this->whereClauseParams
|
|
);
|
|
}
|
|
}
|