mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 23:23:51 +00:00
GenericDoc: add provider for AccompanyingCourseDocument, without filtering
This commit is contained in:
@@ -15,6 +15,7 @@ use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\Exception;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
|
||||
class Manager
|
||||
{
|
||||
@@ -41,7 +42,12 @@ class Manager
|
||||
?string $origin = null
|
||||
): int {
|
||||
['sql' => $sql, 'params' => $params] = $this->buildUnionQuery($accompanyingPeriod, $startDate, $endDate, $content, $origin);
|
||||
$countSql = "SELECT count(*) AS c FROM {$sql} AS sq";
|
||||
|
||||
if ($sql === '') {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$countSql = "SELECT count(*) AS c FROM ({$sql}) AS sq";
|
||||
$result = $this->connection->executeQuery($countSql, $params);
|
||||
|
||||
$number = $result->fetchOne();
|
||||
@@ -50,7 +56,7 @@ class Manager
|
||||
throw new \UnexpectedValueException("number of documents failed to load");
|
||||
}
|
||||
|
||||
return $number['c'];
|
||||
return $number;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,13 +71,18 @@ class Manager
|
||||
?string $content = null,
|
||||
?string $origin = null
|
||||
): iterable {
|
||||
['sql' => $sql, 'params' => $params] = $this->buildUnionQuery($accompanyingPeriod, $startDate, $endDate, $content, $origin);
|
||||
['sql' => $sql, 'params' => $params, 'types' => $types] = $this->buildUnionQuery($accompanyingPeriod, $startDate, $endDate, $content, $origin);
|
||||
|
||||
$runSql = "{$sql} LIMIT ? OFFSET ?";
|
||||
$runParams = [...$params, ...[$limit, $offset]];
|
||||
$runTypes = [...$types, ...[Types::INTEGER, Types::INTEGER]];
|
||||
|
||||
foreach($this->connection->iterateAssociative($runSql, $runParams) as $row) {
|
||||
yield new GenericDocDTO($row['key'], $row['identifiers'], $row['date_doc']);
|
||||
foreach($this->connection->iterateAssociative($runSql, $runParams, $runTypes) as $row) {
|
||||
yield new GenericDocDTO(
|
||||
$row['key'],
|
||||
json_decode($row['identifiers'], true, JSON_THROW_ON_ERROR),
|
||||
new \DateTimeImmutable($row['doc_date'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,17 +97,24 @@ class Manager
|
||||
): array {
|
||||
$sql = [];
|
||||
$params = [];
|
||||
$types = [];
|
||||
|
||||
if ($linked instanceof AccompanyingPeriod) {
|
||||
foreach ($this->providersForAccompanyingPeriod as $provider) {
|
||||
['sql' => $q, 'params' => $p ] = $this->builder
|
||||
if (!$provider->isAllowedForAccompanyingPeriod($linked)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
['sql' => $q, 'params' => $p, 'types' => $t ] = $this->builder
|
||||
->toSql($provider->buildFetchQueryForAccompanyingPeriod($linked, $startDate, $endDate, $content, $origin));
|
||||
$params = [...$params, ...$p];
|
||||
$types = [...$types, ...$t];
|
||||
|
||||
$sql[] = $q;
|
||||
}
|
||||
}
|
||||
|
||||
return ['sql' => implode(' UNION ', $sql), 'params' => $params];
|
||||
return ['sql' => implode(' UNION ', $sql), 'params' => $params, 'types' => $types];
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user