mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 05:44:24 +00:00
118 lines
3.9 KiB
PHP
118 lines
3.9 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\AccompanyingPeriodWorkEvaluation;
|
|
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocument;
|
|
use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationRepository;
|
|
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodWorkEvaluationVoter;
|
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
|
|
|
class AccompanyingPeriodWorkEvaluationWorkflowHandler implements EntityWorkflowHandlerInterface
|
|
{
|
|
private AccompanyingPeriodWorkEvaluationRepository $repository;
|
|
|
|
private TranslatableStringHelperInterface $translatableStringHelper;
|
|
|
|
private TranslatorInterface $translator;
|
|
|
|
public function __construct(
|
|
AccompanyingPeriodWorkEvaluationRepository $repository,
|
|
TranslatableStringHelperInterface $translatableStringHelper,
|
|
TranslatorInterface $translator
|
|
) {
|
|
$this->repository = $repository;
|
|
$this->translatableStringHelper = $translatableStringHelper;
|
|
$this->translator = $translator;
|
|
}
|
|
|
|
public function getDeletionRoles(): array
|
|
{
|
|
return ['_'];
|
|
}
|
|
|
|
public function getEntityData(EntityWorkflow $entityWorkflow, array $options = []): array
|
|
{
|
|
$evaluation = $this->getRelatedEntity($entityWorkflow);
|
|
|
|
return [
|
|
'persons' => $evaluation->getAccompanyingPeriodWork()->getPersons(),
|
|
];
|
|
}
|
|
|
|
public function getEntityTitle(EntityWorkflow $entityWorkflow, array $options = []): string
|
|
{
|
|
$evaluation = $this->getRelatedEntity($entityWorkflow);
|
|
|
|
return $this->translator->trans(
|
|
'workflow.Evaluation (n°%eval%)',
|
|
['%eval%' => $entityWorkflow->getRelatedEntityId()]
|
|
) . ' - ' . $this->translatableStringHelper->localize($evaluation->getEvaluation()->getTitle());
|
|
}
|
|
|
|
public function getRelatedEntity(EntityWorkflow $entityWorkflow): ?AccompanyingPeriodWorkEvaluation
|
|
{
|
|
return $this->repository->find($entityWorkflow->getRelatedEntityId());
|
|
}
|
|
|
|
/**
|
|
* @param AccompanyingPeriodWorkEvaluation $object
|
|
*/
|
|
public function getRelatedObjects(object $object): array
|
|
{
|
|
$relateds = [];
|
|
$relateds[] = ['entityClass' => AccompanyingPeriodWorkEvaluation::class, 'entityId' => $object->getId()];
|
|
|
|
foreach ($object->getDocuments() as $doc) {
|
|
$relateds[] = ['entityClass' => AccompanyingPeriodWorkEvaluationDocument::class, 'entityId' => $doc->getId()];
|
|
}
|
|
|
|
return $relateds;
|
|
}
|
|
|
|
public function getRoleShow(EntityWorkflow $entityWorkflow): ?string
|
|
{
|
|
return AccompanyingPeriodWorkEvaluationVoter::SEE;
|
|
}
|
|
|
|
public function getTemplate(EntityWorkflow $entityWorkflow, array $options = []): string
|
|
{
|
|
return '@ChillPerson/Workflow/_evaluation.html.twig';
|
|
}
|
|
|
|
public function getTemplateData(EntityWorkflow $entityWorkflow, array $options = []): array
|
|
{
|
|
return [
|
|
'entity_workflow' => $entityWorkflow,
|
|
'evaluation' => $this->getRelatedEntity($entityWorkflow),
|
|
];
|
|
}
|
|
|
|
public function isObjectSupported(object $object): bool
|
|
{
|
|
return $object instanceof AccompanyingPeriodWorkEvaluation;
|
|
}
|
|
|
|
public function supports(EntityWorkflow $entityWorkflow, array $options = []): bool
|
|
{
|
|
return $entityWorkflow->getRelatedEntityClass() === AccompanyingPeriodWorkEvaluation::class;
|
|
}
|
|
|
|
public function supportsFreeze(EntityWorkflow $entityWorkflow, array $options = []): bool
|
|
{
|
|
return false;
|
|
}
|
|
}
|