mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-01 12:33:49 +00:00
Add attachments to workflow
This commit is contained in:
@@ -12,10 +12,13 @@ declare(strict_types=1);
|
||||
namespace Chill\DocStoreBundle\GenericDoc\Providers;
|
||||
|
||||
use Chill\DocStoreBundle\Entity\AccompanyingCourseDocument;
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Chill\DocStoreBundle\GenericDoc\FetchQuery;
|
||||
use Chill\DocStoreBundle\GenericDoc\FetchQueryInterface;
|
||||
use Chill\DocStoreBundle\GenericDoc\GenericDocDTO;
|
||||
use Chill\DocStoreBundle\GenericDoc\GenericDocForAccompanyingPeriodProviderInterface;
|
||||
use Chill\DocStoreBundle\GenericDoc\GenericDocForPersonProviderInterface;
|
||||
use Chill\DocStoreBundle\Repository\AccompanyingCourseDocumentRepository;
|
||||
use Chill\DocStoreBundle\Security\Authorization\AccompanyingCourseDocumentVoter;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
@@ -31,17 +34,47 @@ final readonly class AccompanyingCourseDocumentGenericDocProvider implements Gen
|
||||
public function __construct(
|
||||
private Security $security,
|
||||
private EntityManagerInterface $entityManager,
|
||||
private AccompanyingCourseDocumentRepository $accompanyingCourseDocumentRepository,
|
||||
) {}
|
||||
|
||||
public function fetchAssociatedStoredObject(GenericDocDTO $genericDocDTO): ?StoredObject
|
||||
{
|
||||
return $this->accompanyingCourseDocumentRepository->find($genericDocDTO->identifiers['id'])?->getObject();
|
||||
}
|
||||
|
||||
public function supportsGenericDoc(GenericDocDTO $genericDocDTO): bool
|
||||
{
|
||||
return $this->supportsKeyAndIdentifiers($genericDocDTO->key, $genericDocDTO->identifiers);
|
||||
}
|
||||
|
||||
public function supportsKeyAndIdentifiers(string $key, array $identifiers): bool
|
||||
{
|
||||
return self::KEY === $key;
|
||||
}
|
||||
|
||||
public function buildOneGenericDoc(string $key, array $identifiers): ?GenericDocDTO
|
||||
{
|
||||
if (null === $accompanyingCourseDocument = $this->accompanyingCourseDocumentRepository->find($identifiers['id'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new GenericDocDTO(
|
||||
self::KEY,
|
||||
$identifiers,
|
||||
\DateTimeImmutable::createFromInterface($accompanyingCourseDocument->getDate()),
|
||||
$accompanyingCourseDocument->getCourse(),
|
||||
);
|
||||
}
|
||||
|
||||
public function buildFetchQueryForAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod, ?\DateTimeImmutable $startDate = null, ?\DateTimeImmutable $endDate = null, ?string $content = null, ?string $origin = null): FetchQueryInterface
|
||||
{
|
||||
$classMetadata = $this->entityManager->getClassMetadata(AccompanyingCourseDocument::class);
|
||||
|
||||
$query = new FetchQuery(
|
||||
self::KEY,
|
||||
sprintf('jsonb_build_object(\'id\', %s)', $classMetadata->getIdentifierColumnNames()[0]),
|
||||
sprintf('jsonb_build_object(\'id\', acc_course_document.%s)', $classMetadata->getIdentifierColumnNames()[0]),
|
||||
$classMetadata->getColumnName('date'),
|
||||
$classMetadata->getSchemaName().'.'.$classMetadata->getTableName()
|
||||
$classMetadata->getSchemaName().'.'.$classMetadata->getTableName().' AS acc_course_document'
|
||||
);
|
||||
|
||||
$query->addWhereClause(
|
||||
@@ -64,7 +97,7 @@ final readonly class AccompanyingCourseDocumentGenericDocProvider implements Gen
|
||||
|
||||
$query = new FetchQuery(
|
||||
self::KEY,
|
||||
sprintf('jsonb_build_object(\'id\', %s)', $classMetadata->getIdentifierColumnNames()[0]),
|
||||
sprintf('jsonb_build_object(\'id\', acc_course_document.%s)', $classMetadata->getIdentifierColumnNames()[0]),
|
||||
$classMetadata->getColumnName('date'),
|
||||
$classMetadata->getSchemaName().'.'.$classMetadata->getTableName().' AS acc_course_document'
|
||||
);
|
||||
@@ -110,6 +143,7 @@ final readonly class AccompanyingCourseDocumentGenericDocProvider implements Gen
|
||||
private function addWhereClause(FetchQuery $query, ?\DateTimeImmutable $startDate = null, ?\DateTimeImmutable $endDate = null, ?string $content = null): FetchQuery
|
||||
{
|
||||
$classMetadata = $this->entityManager->getClassMetadata(AccompanyingCourseDocument::class);
|
||||
$storedObjectMetadata = $this->entityManager->getClassMetadata(StoredObject::class);
|
||||
|
||||
if (null !== $startDate) {
|
||||
$query->addWhereClause(
|
||||
@@ -128,9 +162,19 @@ final readonly class AccompanyingCourseDocumentGenericDocProvider implements Gen
|
||||
}
|
||||
|
||||
if (null !== $content and '' !== $content) {
|
||||
// add join clause to stored_object table
|
||||
$query->addJoinClause(
|
||||
sprintf(
|
||||
'JOIN %s AS doc_store ON doc_store.%s = acc_course_document.%s',
|
||||
$storedObjectMetadata->getSchemaName().'.'.$storedObjectMetadata->getTableName(),
|
||||
$storedObjectMetadata->getSingleIdentifierColumnName(),
|
||||
$classMetadata->getSingleAssociationJoinColumnName('object')
|
||||
)
|
||||
);
|
||||
|
||||
$query->addWhereClause(
|
||||
sprintf(
|
||||
'(%s ilike ? OR %s ilike ?)',
|
||||
'(doc_store.%s ilike ? OR acc_course_document.%s ilike ?)',
|
||||
$classMetadata->getColumnName('title'),
|
||||
$classMetadata->getColumnName('description')
|
||||
),
|
||||
|
@@ -11,10 +11,13 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\DocStoreBundle\GenericDoc\Providers;
|
||||
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Chill\DocStoreBundle\GenericDoc\FetchQueryInterface;
|
||||
use Chill\DocStoreBundle\GenericDoc\GenericDocDTO;
|
||||
use Chill\DocStoreBundle\GenericDoc\GenericDocForAccompanyingPeriodProviderInterface;
|
||||
use Chill\DocStoreBundle\GenericDoc\GenericDocForPersonProviderInterface;
|
||||
use Chill\DocStoreBundle\Repository\PersonDocumentACLAwareRepositoryInterface;
|
||||
use Chill\DocStoreBundle\Repository\PersonDocumentRepository;
|
||||
use Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
@@ -27,8 +30,38 @@ final readonly class PersonDocumentGenericDocProvider implements GenericDocForPe
|
||||
public function __construct(
|
||||
private Security $security,
|
||||
private PersonDocumentACLAwareRepositoryInterface $personDocumentACLAwareRepository,
|
||||
private PersonDocumentRepository $personDocumentRepository,
|
||||
) {}
|
||||
|
||||
public function fetchAssociatedStoredObject(GenericDocDTO $genericDocDTO): ?StoredObject
|
||||
{
|
||||
return $this->personDocumentRepository->find($genericDocDTO->identifiers['id'])?->getObject();
|
||||
}
|
||||
|
||||
public function supportsGenericDoc(GenericDocDTO $genericDocDTO): bool
|
||||
{
|
||||
return $this->supportsKeyAndIdentifiers($genericDocDTO->key, $genericDocDTO->identifiers);
|
||||
}
|
||||
|
||||
public function supportsKeyAndIdentifiers(string $key, array $identifiers): bool
|
||||
{
|
||||
return self::KEY === $key && array_key_exists('id', $identifiers);
|
||||
}
|
||||
|
||||
public function buildOneGenericDoc(string $key, array $identifiers): ?GenericDocDTO
|
||||
{
|
||||
if (null === $document = $this->personDocumentRepository->find($identifiers['id'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new GenericDocDTO(
|
||||
self::KEY,
|
||||
$identifiers,
|
||||
\DateTimeImmutable::createFromInterface($document->getDate()),
|
||||
$document->getPerson()
|
||||
);
|
||||
}
|
||||
|
||||
public function buildFetchQueryForPerson(
|
||||
Person $person,
|
||||
?\DateTimeImmutable $startDate = null,
|
||||
|
Reference in New Issue
Block a user