mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
fix activity timeline using TimelineSingleQuery
This commit is contained in:
@@ -201,10 +201,13 @@ class TimelineBuilder implements ContainerAwareInterface
|
||||
/**
|
||||
* return the SQL SELECT query as a string,
|
||||
*
|
||||
* @return string
|
||||
* @return array: first parameter is the sql string, second an array with parameters
|
||||
*/
|
||||
private function buildSelectQuery(array $data): array
|
||||
private function buildSelectQuery($data): array
|
||||
{
|
||||
return [$data->buildSql(), $data->getParameters()];
|
||||
|
||||
// dead code
|
||||
$parameters = [];
|
||||
|
||||
$sql = sprintf(
|
||||
|
155
src/Bundle/ChillMainBundle/Timeline/TimelineSingleQuery.php
Normal file
155
src/Bundle/ChillMainBundle/Timeline/TimelineSingleQuery.php
Normal file
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\MainBundle\Timeline;
|
||||
|
||||
|
||||
class TimelineSingleQuery
|
||||
{
|
||||
private ?string $id;
|
||||
|
||||
private ?string $date;
|
||||
|
||||
private ?string $key;
|
||||
|
||||
private ?string $from;
|
||||
|
||||
private ?string $where;
|
||||
|
||||
private array $parameters = [];
|
||||
|
||||
private bool $distinct = false;
|
||||
|
||||
public function __construct(
|
||||
string $id = null,
|
||||
string $date = null,
|
||||
string $key = null,
|
||||
string $from = null,
|
||||
string $where = null,
|
||||
array $parameters = []
|
||||
) {
|
||||
$this->id = $id;
|
||||
$this->date = $date;
|
||||
$this->key = $key;
|
||||
$this->from = $from;
|
||||
$this->where = $where;
|
||||
$this->parameters = $parameters;
|
||||
}
|
||||
|
||||
public static function fromArray(array $a)
|
||||
{
|
||||
return new TimelineSingleQuery(
|
||||
$a['id'],
|
||||
$a['date'],
|
||||
$a['type'] ?? $a['key'],
|
||||
$a['FROM'] ?? $a['from'],
|
||||
$a['WHERE'] ?? $a['where'],
|
||||
$a['parameters']);
|
||||
}
|
||||
|
||||
public function getId(): string
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function setId(string $id): self
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDate(): string
|
||||
{
|
||||
return $this->date;
|
||||
}
|
||||
|
||||
public function setDate(string $date): self
|
||||
{
|
||||
$this->date = $date;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getKey(): string
|
||||
{
|
||||
return $this->key;
|
||||
}
|
||||
|
||||
public function setKey(string $key): self
|
||||
{
|
||||
$this->key = $key;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFrom(): string
|
||||
{
|
||||
return $this->from;
|
||||
}
|
||||
|
||||
public function setFrom(string $from): self
|
||||
{
|
||||
$this->from = $from;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getWhere(): string
|
||||
{
|
||||
return $this->where;
|
||||
}
|
||||
|
||||
public function setWhere(string $where): self
|
||||
{
|
||||
$this->where = $where;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getParameters(): array
|
||||
{
|
||||
return $this->parameters;
|
||||
}
|
||||
|
||||
public function setParameters(array $parameters): self
|
||||
{
|
||||
$this->parameters = $parameters;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setDistinct(bool $distinct): self
|
||||
{
|
||||
$this->distinct = $distinct;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isDistinct(): bool
|
||||
{
|
||||
return $this->distinct;
|
||||
}
|
||||
|
||||
public function buildSql(): string
|
||||
{
|
||||
$parameters = [];
|
||||
|
||||
$sql = \strtr(
|
||||
'SELECT {distinct} {id} AS id, '
|
||||
. '{date} AS "date", '
|
||||
. "'{key}' AS type "
|
||||
. 'FROM {from} '
|
||||
. 'WHERE {where}',
|
||||
[
|
||||
'{distinct}' => $this->distinct ? 'DISTINCT' : '',
|
||||
'{id}' => $this->getId(),
|
||||
'{date}' => $this->getDate(),
|
||||
'{key}' => $this->getKey(),
|
||||
'{from}' => $this->getFrom(),
|
||||
'{where}' => $this->getWhere(),
|
||||
]
|
||||
);
|
||||
|
||||
return $sql;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user