chill-bundles/src/Bundle/ChillMainBundle/Timeline/TimelineSingleQuery.php

165 lines
3.2 KiB
PHP

<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Timeline;
use function strtr;
class TimelineSingleQuery
{
private ?string $date;
private bool $distinct = false;
private ?string $from;
private ?string $id;
private ?string $key;
private array $parameters = [];
private ?string $where;
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 function buildSql(): string
{
$parameters = [];
return 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(),
]
);
}
public static function fromArray(array $a)
{
return new TimelineSingleQuery(
$a['id'] ?? null,
$a['date'] ?? null,
$a['type'] ?? $a['key'] ?? null,
$a['FROM'] ?? $a['from'] ?? null,
$a['WHERE'] ?? $a['where'] ?? null,
$a['parameters'] ?? null
);
}
public function getDate(): string
{
return $this->date;
}
public function getFrom(): string
{
return $this->from;
}
public function getId(): string
{
return $this->id;
}
public function getKey(): string
{
return $this->key;
}
public function getParameters(): array
{
return $this->parameters;
}
public function getWhere(): string
{
return $this->where;
}
public function isDistinct(): bool
{
return $this->distinct;
}
public function setDate(string $date): self
{
$this->date = $date;
return $this;
}
public function setDistinct(bool $distinct): self
{
$this->distinct = $distinct;
return $this;
}
public function setFrom(string $from): self
{
$this->from = $from;
return $this;
}
public function setId(string $id): self
{
$this->id = $id;
return $this;
}
public function setKey(string $key): self
{
$this->key = $key;
return $this;
}
public function setParameters(array $parameters): self
{
$this->parameters = $parameters;
return $this;
}
public function setWhere(string $where): self
{
$this->where = $where;
return $this;
}
}