mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-29 02:53:50 +00:00
Add attachments to workflow
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?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\PersonBundle\Service\GenericDoc\Normalizer;
|
||||
|
||||
use Chill\DocStoreBundle\GenericDoc\GenericDocDTO;
|
||||
use Chill\DocStoreBundle\GenericDoc\GenericDocNormalizerInterface;
|
||||
use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocumentRepository;
|
||||
use Chill\PersonBundle\Service\GenericDoc\Providers\AccompanyingPeriodWorkEvaluationGenericDocProvider;
|
||||
use Chill\PersonBundle\Service\GenericDoc\Renderer\AccompanyingPeriodWorkEvaluationGenericDocRenderer;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Twig\Environment;
|
||||
|
||||
final readonly class AccompanyingPeriodWorkEvaluationGenericDocNormalizer implements GenericDocNormalizerInterface
|
||||
{
|
||||
public function __construct(
|
||||
private AccompanyingPeriodWorkEvaluationDocumentRepository $accompanyingPeriodWorkEvaluationDocumentRepository,
|
||||
private Environment $twig,
|
||||
private AccompanyingPeriodWorkEvaluationGenericDocRenderer $renderer,
|
||||
private TranslatorInterface $translator,
|
||||
) {}
|
||||
|
||||
public function supportsNormalization(GenericDocDTO $genericDocDTO, string $format, array $context = []): bool
|
||||
{
|
||||
return AccompanyingPeriodWorkEvaluationGenericDocProvider::KEY === $genericDocDTO->key;
|
||||
}
|
||||
|
||||
public function normalize(GenericDocDTO $genericDocDTO, string $format, array $context = []): array
|
||||
{
|
||||
if (null === $evaluationDoc = $this->accompanyingPeriodWorkEvaluationDocumentRepository->find($genericDocDTO->identifiers['id'])) {
|
||||
return ['title' => $this->translator->trans('generic_doc.document removed'), 'isPresent' => false];
|
||||
}
|
||||
|
||||
return [
|
||||
'title' => $evaluationDoc->getTitle(),
|
||||
'html' => $this->twig->render(
|
||||
$this->renderer->getTemplate($genericDocDTO, ['show-actions' => false, 'row-only' => true]),
|
||||
$this->renderer->getTemplateData($genericDocDTO, ['show-actions' => false, 'row-only' => true])
|
||||
),
|
||||
'isPresent' => true,
|
||||
];
|
||||
}
|
||||
}
|
@@ -14,10 +14,12 @@ namespace Chill\PersonBundle\Service\GenericDoc\Providers;
|
||||
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\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocumentRepository;
|
||||
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodWorkVoter;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
@@ -30,8 +32,38 @@ final readonly class AccompanyingPeriodWorkEvaluationGenericDocProvider implemen
|
||||
public function __construct(
|
||||
private Security $security,
|
||||
private EntityManagerInterface $entityManager,
|
||||
private AccompanyingPeriodWorkEvaluationDocumentRepository $accompanyingPeriodWorkEvaluationDocumentRepository,
|
||||
) {}
|
||||
|
||||
public function fetchAssociatedStoredObject(GenericDocDTO $genericDocDTO): ?StoredObject
|
||||
{
|
||||
return $this->accompanyingPeriodWorkEvaluationDocumentRepository->find($genericDocDTO->identifiers['id'])?->getStoredObject();
|
||||
}
|
||||
|
||||
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 === $document = $this->accompanyingPeriodWorkEvaluationDocumentRepository->find($identifiers['id'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new GenericDocDTO(
|
||||
$key,
|
||||
$identifiers,
|
||||
$document->getAccompanyingPeriodWorkEvaluation()->getCreatedAt(),
|
||||
$document->getAccompanyingPeriodWorkEvaluation()->getAccompanyingPeriodWork()->getAccompanyingPeriod()
|
||||
);
|
||||
}
|
||||
|
||||
public function buildFetchQueryForAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod, ?\DateTimeImmutable $startDate = null, ?\DateTimeImmutable $endDate = null, ?string $content = null, ?string $origin = null): FetchQueryInterface
|
||||
{
|
||||
$accompanyingPeriodWorkMetadata = $this->entityManager->getClassMetadata(AccompanyingPeriod\AccompanyingPeriodWork::class);
|
||||
@@ -53,7 +85,6 @@ final readonly class AccompanyingPeriodWorkEvaluationGenericDocProvider implemen
|
||||
|
||||
private function addWhereClausesToQuery(FetchQuery $query, ?\DateTimeImmutable $startDate = null, ?\DateTimeImmutable $endDate = null, ?string $content = null): FetchQuery
|
||||
{
|
||||
$classMetadata = $this->entityManager->getClassMetadata(AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocument::class);
|
||||
$storedObjectMetadata = $this->entityManager->getClassMetadata(StoredObject::class);
|
||||
|
||||
if (null !== $startDate) {
|
||||
@@ -74,7 +105,7 @@ final readonly class AccompanyingPeriodWorkEvaluationGenericDocProvider implemen
|
||||
|
||||
if (null !== $content) {
|
||||
$query->addWhereClause(
|
||||
sprintf('apwed.%s ilike ?', $classMetadata->getColumnName('title')),
|
||||
sprintf('doc_store.%s ilike ?', $storedObjectMetadata->getColumnName('title')),
|
||||
['%'.$content.'%'],
|
||||
[Types::STRING]
|
||||
);
|
||||
|
@@ -16,6 +16,9 @@ use Chill\DocStoreBundle\GenericDoc\Twig\GenericDocRendererInterface;
|
||||
use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocumentRepository;
|
||||
use Chill\PersonBundle\Service\GenericDoc\Providers\AccompanyingPeriodWorkEvaluationGenericDocProvider;
|
||||
|
||||
/**
|
||||
* @implements GenericDocRendererInterface<array{row-only?: bool, show-actions?: bool}>
|
||||
*/
|
||||
final readonly class AccompanyingPeriodWorkEvaluationGenericDocRenderer implements GenericDocRendererInterface
|
||||
{
|
||||
public function __construct(
|
||||
@@ -29,7 +32,8 @@ final readonly class AccompanyingPeriodWorkEvaluationGenericDocRenderer implemen
|
||||
|
||||
public function getTemplate(GenericDocDTO $genericDocDTO, $options = []): string
|
||||
{
|
||||
return '@ChillPerson/GenericDoc/evaluation_document.html.twig';
|
||||
return ($options['row-only'] ?? false) ? '@ChillPerson/GenericDoc/evaluation_document_row.html.twig'
|
||||
: '@ChillPerson/GenericDoc/evaluation_document.html.twig';
|
||||
}
|
||||
|
||||
public function getTemplateData(GenericDocDTO $genericDocDTO, $options = []): array
|
||||
@@ -37,6 +41,7 @@ final readonly class AccompanyingPeriodWorkEvaluationGenericDocRenderer implemen
|
||||
return [
|
||||
'document' => $this->accompanyingPeriodWorkEvaluationDocumentRepository->find($genericDocDTO->identifiers['id']),
|
||||
'context' => $genericDocDTO->getContext(),
|
||||
'show_actions' => $options['show-actions'] ?? true,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user