mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-19 08:44:24 +00:00
121 lines
4.1 KiB
PHP
121 lines
4.1 KiB
PHP
<?php
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Chill\PersonBundle\Workflow;
|
|
|
|
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
|
|
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
|
use Chill\MainBundle\Workflow\EntityWorkflowHandlerInterface;
|
|
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork;
|
|
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluation;
|
|
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocument;
|
|
use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository;
|
|
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodWorkVoter;
|
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
|
|
|
class AccompanyingPeriodWorkWorkflowHandler implements EntityWorkflowHandlerInterface
|
|
{
|
|
private AccompanyingPeriodWorkRepository $repository;
|
|
|
|
private TranslatableStringHelperInterface $translatableStringHelper;
|
|
|
|
private TranslatorInterface $translator;
|
|
|
|
public function __construct(
|
|
AccompanyingPeriodWorkRepository $repository,
|
|
TranslatableStringHelperInterface $translatableStringHelper,
|
|
TranslatorInterface $translator
|
|
) {
|
|
$this->repository = $repository;
|
|
$this->translatableStringHelper = $translatableStringHelper;
|
|
$this->translator = $translator;
|
|
}
|
|
|
|
public function getDeletionRoles(): array
|
|
{
|
|
return [AccompanyingPeriodWorkVoter::DELETE];
|
|
}
|
|
|
|
public function getEntityData(EntityWorkflow $entityWorkflow, array $options = []): array
|
|
{
|
|
return [
|
|
'persons' => $this->getRelatedEntity($entityWorkflow)
|
|
->getPersons(),
|
|
];
|
|
}
|
|
|
|
public function getEntityTitle(EntityWorkflow $entityWorkflow, array $options = []): string
|
|
{
|
|
$work = $this->getRelatedEntity($entityWorkflow);
|
|
|
|
return
|
|
$this->translator->trans('workflow.Work (n°%w%)', ['%w%' => $entityWorkflow->getRelatedEntityId()])
|
|
. ' - ' . $this->translatableStringHelper->localize($work->getSocialAction()->getTitle());
|
|
}
|
|
|
|
public function getRelatedEntity(EntityWorkflow $entityWorkflow): ?AccompanyingPeriodWork
|
|
{
|
|
return $this->repository->find($entityWorkflow->getRelatedEntityId());
|
|
}
|
|
|
|
/**
|
|
* @param AccompanyingPeriodWork $object
|
|
*/
|
|
public function getRelatedObjects(object $object): array
|
|
{
|
|
$relateds = [];
|
|
$relateds[] = ['entityClass' => AccompanyingPeriodWork::class, 'entityId' => $object->getId()];
|
|
|
|
foreach ($object->getAccompanyingPeriodWorkEvaluations() as $evaluation) {
|
|
$relateds[] = ['entityClass' => AccompanyingPeriodWorkEvaluation::class, 'entityId' => $evaluation->getId()];
|
|
|
|
foreach ($evaluation->getDocuments() as $doc) {
|
|
$relateds[] = ['entityClass' => AccompanyingPeriodWorkEvaluationDocument::class, 'entityId' => $doc->getId()];
|
|
}
|
|
}
|
|
|
|
return $relateds;
|
|
}
|
|
|
|
public function getRoleShow(EntityWorkflow $entityWorkflow): ?string
|
|
{
|
|
return null;
|
|
}
|
|
|
|
public function getTemplate(EntityWorkflow $entityWorkflow, array $options = []): string
|
|
{
|
|
return '@ChillPerson/Workflow/_accompanying_period_work.html.twig';
|
|
}
|
|
|
|
public function getTemplateData(EntityWorkflow $entityWorkflow, array $options = []): array
|
|
{
|
|
return [
|
|
'entity_workflow' => $entityWorkflow,
|
|
'work' => $this->getRelatedEntity($entityWorkflow),
|
|
];
|
|
}
|
|
|
|
public function isObjectSupported(object $object): bool
|
|
{
|
|
return $object instanceof AccompanyingPeriodWork;
|
|
}
|
|
|
|
public function supports(EntityWorkflow $entityWorkflow, array $options = []): bool
|
|
{
|
|
return $entityWorkflow->getRelatedEntityClass() === AccompanyingPeriodWork::class;
|
|
}
|
|
|
|
public function supportsFreeze(EntityWorkflow $entityWorkflow, array $options = []): bool
|
|
{
|
|
return false;
|
|
}
|
|
}
|