GenericDoc: add provider for AccompanyingCourseDocument, without filtering

This commit is contained in:
2023-05-24 11:42:30 +02:00
parent afcd6e0605
commit 8dbe2d6ec2
12 changed files with 414 additions and 46 deletions

View File

@@ -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];
}
}