mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-29 18:14:59 +00:00
Add attachments to workflow
This commit is contained in:
@@ -11,13 +11,16 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\DocStoreBundle\GenericDoc;
|
||||
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Chill\DocStoreBundle\GenericDoc\Exception\AssociatedStoredObjectNotFound;
|
||||
use Chill\DocStoreBundle\GenericDoc\Exception\NotNormalizableGenericDocException;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\Exception;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
|
||||
final readonly class Manager
|
||||
final readonly class Manager implements ManagerInterface
|
||||
{
|
||||
private FetchQueryToSqlBuilder $builder;
|
||||
|
||||
@@ -31,16 +34,16 @@ final readonly class Manager
|
||||
* @var iterable<GenericDocForPersonProviderInterface>
|
||||
*/
|
||||
private iterable $providersForPerson,
|
||||
|
||||
/**
|
||||
* @var iterable<GenericDocNormalizerInterface>
|
||||
*/
|
||||
private iterable $genericDocNormalizers,
|
||||
private Connection $connection,
|
||||
) {
|
||||
$this->builder = new FetchQueryToSqlBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<string> $places
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function countDocForAccompanyingPeriod(
|
||||
AccompanyingPeriod $accompanyingPeriod,
|
||||
?\DateTimeImmutable $startDate = null,
|
||||
@@ -83,13 +86,6 @@ final readonly class Manager
|
||||
return $this->countDoc($sql, $params, $types);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<string> $places places to search. When empty, search in all places
|
||||
*
|
||||
* @return iterable<GenericDocDTO>
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function findDocForAccompanyingPeriod(
|
||||
AccompanyingPeriod $accompanyingPeriod,
|
||||
int $offset = 0,
|
||||
@@ -129,10 +125,35 @@ final readonly class Manager
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<string> $places places to search. When empty, search in all places
|
||||
* Fetch a generic doc, if it does exists.
|
||||
*
|
||||
* @return iterable<GenericDocDTO>
|
||||
* Currently implemented only on generic docs linked with accompanying period
|
||||
*/
|
||||
public function buildOneGenericDoc(string $key, array $identifiers): ?GenericDocDTO
|
||||
{
|
||||
foreach ($this->providersForAccompanyingPeriod as $provider) {
|
||||
if ($provider->supportsKeyAndIdentifiers($key, $identifiers)) {
|
||||
return $provider->buildOneGenericDoc($key, $identifiers);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws AssociatedStoredObjectNotFound if no stored object can be found
|
||||
*/
|
||||
public function fetchStoredObject(GenericDocDTO $genericDocDTO): StoredObject
|
||||
{
|
||||
foreach ($this->providersForAccompanyingPeriod as $provider) {
|
||||
if ($provider->supportsGenericDoc($genericDocDTO)) {
|
||||
return $provider->fetchAssociatedStoredObject($genericDocDTO);
|
||||
}
|
||||
}
|
||||
|
||||
throw new AssociatedStoredObjectNotFound($genericDocDTO->key, $genericDocDTO->identifiers);
|
||||
}
|
||||
|
||||
public function findDocForPerson(
|
||||
Person $person,
|
||||
int $offset = 0,
|
||||
@@ -161,6 +182,28 @@ final readonly class Manager
|
||||
return $this->places($sql, $params, $types);
|
||||
}
|
||||
|
||||
public function isGenericDocNormalizable(GenericDocDTO $genericDocDTO, string $format, array $context = []): bool
|
||||
{
|
||||
foreach ($this->genericDocNormalizers as $genericDocNormalizer) {
|
||||
if ($genericDocNormalizer->supportsNormalization($genericDocDTO, $format, $context)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function normalizeGenericDoc(GenericDocDTO $genericDocDTO, string $format, array $context = []): array
|
||||
{
|
||||
foreach ($this->genericDocNormalizers as $genericDocNormalizer) {
|
||||
if ($genericDocNormalizer->supportsNormalization($genericDocDTO, $format, $context)) {
|
||||
return $genericDocNormalizer->normalize($genericDocDTO, $format, $context);
|
||||
}
|
||||
}
|
||||
|
||||
throw new NotNormalizableGenericDocException();
|
||||
}
|
||||
|
||||
private function places(string $sql, array $params, array $types): array
|
||||
{
|
||||
if ('' === $sql) {
|
||||
|
Reference in New Issue
Block a user