From c8770764298cac00d217da11f8439ff1c60cafe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 22 Oct 2024 23:15:03 +0200 Subject: [PATCH 1/6] Add and update test handlers for suggested users retrieval Introduced new test files for workflow handlers and adjusted existing `getSuggestedUsers` methods to handle related entity checks and duplicates removal. Also, modified repos to align with test dependencies. --- ...nyingCourseDocumentWorkflowHandlerTest.php | 86 +++++++++++++++++++ ...ompanyingCourseDocumentWorkflowHandler.php | 24 +++++- ...PeriodWorkEvaluationDocumentRepository.php | 4 +- .../AccompanyingPeriodWorkRepository.php | 6 +- ...kEvaluationDocumentWorkflowHandlerTest.php | 82 ++++++++++++++++++ ...eriodWorkEvaluationWorkflowHandlerTest.php | 72 ++++++++++++++++ ...ompanyingPeriodWorkWorkflowHandlerTest.php | 73 ++++++++++++++++ ...dWorkEvaluationDocumentWorkflowHandler.php | 31 +++++-- ...ingPeriodWorkEvaluationWorkflowHandler.php | 30 +++++-- .../AccompanyingPeriodWorkWorkflowHandler.php | 31 +++++-- 10 files changed, 410 insertions(+), 29 deletions(-) create mode 100644 src/Bundle/ChillDocStoreBundle/Tests/Workflow/AccompanyingCourseDocumentWorkflowHandlerTest.php create mode 100644 src/Bundle/ChillPersonBundle/Tests/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandlerTest.php create mode 100644 src/Bundle/ChillPersonBundle/Tests/Workflow/AccompanyingPeriodWorkEvaluationWorkflowHandlerTest.php create mode 100644 src/Bundle/ChillPersonBundle/Tests/Workflow/AccompanyingPeriodWorkWorkflowHandlerTest.php diff --git a/src/Bundle/ChillDocStoreBundle/Tests/Workflow/AccompanyingCourseDocumentWorkflowHandlerTest.php b/src/Bundle/ChillDocStoreBundle/Tests/Workflow/AccompanyingCourseDocumentWorkflowHandlerTest.php new file mode 100644 index 000000000..e40b240f4 --- /dev/null +++ b/src/Bundle/ChillDocStoreBundle/Tests/Workflow/AccompanyingCourseDocumentWorkflowHandlerTest.php @@ -0,0 +1,86 @@ +setCourse($accompanyingPeriod)->setUser($user1 = new User()); + $accompanyingPeriod->setUser($user = new User()); + $entityWorkflow = new EntityWorkflow(); + $entityWorkflow->setRelatedEntityId(1); + + $handler = new AccompanyingCourseDocumentWorkflowHandler( + $this->prophesize(TranslatorInterface::class)->reveal(), + $this->prophesize(EntityWorkflowRepository::class)->reveal(), + $this->buildRepository($document, 1), + new WorkflowWithPublicViewDocumentHelper($this->prophesize(Environment::class)->reveal()), + ); + + $users = $handler->getSuggestedUsers($entityWorkflow); + + self::assertCount(2, $users); + self::assertContains($user, $users); + self::assertContains($user1, $users); + } + + public function testGetSuggestedUsersWithDuplicates() + { + $accompanyingPeriod = new AccompanyingPeriod(); + $document = new AccompanyingCourseDocument(); + $document->setCourse($accompanyingPeriod)->setUser($user1 = new User()); + $accompanyingPeriod->setUser($user1); + $entityWorkflow = new EntityWorkflow(); + $entityWorkflow->setRelatedEntityId(1); + + $handler = new AccompanyingCourseDocumentWorkflowHandler( + $this->prophesize(TranslatorInterface::class)->reveal(), + $this->prophesize(EntityWorkflowRepository::class)->reveal(), + $this->buildRepository($document, 1), + new WorkflowWithPublicViewDocumentHelper($this->prophesize(Environment::class)->reveal()), + ); + + $users = $handler->getSuggestedUsers($entityWorkflow); + + self::assertCount(1, $users); + self::assertContains($user1, $users); + } + + private function buildRepository(AccompanyingCourseDocument $document, int $id): AccompanyingCourseDocumentRepository + { + $repository = $this->prophesize(AccompanyingCourseDocumentRepository::class); + $repository->find($id)->willReturn($document); + + return $repository->reveal(); + } +} diff --git a/src/Bundle/ChillDocStoreBundle/Workflow/AccompanyingCourseDocumentWorkflowHandler.php b/src/Bundle/ChillDocStoreBundle/Workflow/AccompanyingCourseDocumentWorkflowHandler.php index 4f4655b94..b98e5d4a9 100644 --- a/src/Bundle/ChillDocStoreBundle/Workflow/AccompanyingCourseDocumentWorkflowHandler.php +++ b/src/Bundle/ChillDocStoreBundle/Workflow/AccompanyingCourseDocumentWorkflowHandler.php @@ -91,12 +91,28 @@ final readonly class AccompanyingCourseDocumentWorkflowHandler implements Entity public function getSuggestedUsers(EntityWorkflow $entityWorkflow): array { - $suggestedUsers = $entityWorkflow->getUsersInvolved(); + $related = $this->getRelatedEntity($entityWorkflow); - $referrer = $this->getRelatedEntity($entityWorkflow)->getCourse()->getUser(); - $suggestedUsers[spl_object_hash($referrer)] = $referrer; + if (null === $related) { + return []; + } - return $suggestedUsers; + $users = []; + if (null !== $user = $related->getUser()) { + $users[] = $user; + } + if (null !== $user = $related->getCourse()->getUser()) { + $users[] = $user; + } + + return array_values( + // filter objects to remove duplicates + array_filter( + $users, + fn ($o, $k) => array_search($o, $users, true) === $k, + ARRAY_FILTER_USE_BOTH + ) + ); } public function getTemplate(EntityWorkflow $entityWorkflow, array $options = []): string diff --git a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkEvaluationDocumentRepository.php b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkEvaluationDocumentRepository.php index e3a484f0b..6baa0d069 100644 --- a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkEvaluationDocumentRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkEvaluationDocumentRepository.php @@ -19,9 +19,9 @@ use Doctrine\ORM\EntityRepository; use Doctrine\ORM\NonUniqueResultException; use Doctrine\Persistence\ObjectRepository; -readonly class AccompanyingPeriodWorkEvaluationDocumentRepository implements ObjectRepository, AssociatedEntityToStoredObjectInterface +class AccompanyingPeriodWorkEvaluationDocumentRepository implements ObjectRepository, AssociatedEntityToStoredObjectInterface { - private EntityRepository $repository; + private readonly EntityRepository $repository; public function __construct(EntityManagerInterface $em) { diff --git a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php index 95b995e74..0d5bf5eee 100644 --- a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php @@ -22,11 +22,11 @@ use Doctrine\ORM\Query\ResultSetMappingBuilder; use Doctrine\ORM\QueryBuilder; use Doctrine\Persistence\ObjectRepository; -final readonly class AccompanyingPeriodWorkRepository implements ObjectRepository +class AccompanyingPeriodWorkRepository implements ObjectRepository { - private EntityRepository $repository; + private readonly EntityRepository $repository; - public function __construct(private EntityManagerInterface $em) + public function __construct(private readonly EntityManagerInterface $em) { $this->repository = $em->getRepository(AccompanyingPeriodWork::class); } diff --git a/src/Bundle/ChillPersonBundle/Tests/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandlerTest.php b/src/Bundle/ChillPersonBundle/Tests/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandlerTest.php new file mode 100644 index 000000000..2e7076a4d --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Tests/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandlerTest.php @@ -0,0 +1,82 @@ +setUser($referrer = new User()); + $accompanyingCourse->addWork($work = new AccompanyingPeriod\AccompanyingPeriodWork()); + $work->addReferrer($workReferrer1 = new User()); + $work->addReferrer($workReferrer2 = new User()); + $work->addReferrer($referrer); + $work->addAccompanyingPeriodWorkEvaluation($eval = new AccompanyingPeriod\AccompanyingPeriodWorkEvaluation()); + $eval->addDocument($doc = new AccompanyingPeriodWorkEvaluationDocument()); + $entityWorkflow = new EntityWorkflow(); + + // Prophesize each dependency + $workflowRepositoryProphecy = $this->prophesize(EntityWorkflowRepository::class); + $translatableStringHelperProphecy = $this->prophesize(TranslatableStringHelperInterface::class); + $translatorProphecy = $this->prophesize(TranslatorInterface::class); + $twig = $this->prophesize(Environment::class); + + // Create an instance of the class under test using revealed prophecies directly + $handler = new AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler( + $this->buildRepository($doc, 1), + $workflowRepositoryProphecy->reveal(), + $translatableStringHelperProphecy->reveal(), + $translatorProphecy->reveal(), + new WorkflowWithPublicViewDocumentHelper($twig->reveal()), + ); + + $entityWorkflow->setRelatedEntityId(1); + $entityWorkflow->setRelatedEntityClass(AccompanyingPeriodWorkEvaluationDocument::class); + + $users = $handler->getSuggestedUsers($entityWorkflow); + + self::assertContains($referrer, $users); + self::assertContains($workReferrer1, $users); + self::assertContains($workReferrer2, $users); + } + + private function buildRepository(AccompanyingPeriodWorkEvaluationDocument $document, int $id): AccompanyingPeriodWorkEvaluationDocumentRepository + { + $repository = $this->prophesize(AccompanyingPeriodWorkEvaluationDocumentRepository::class); + + $repository->find($id)->willReturn($document); + + return $repository->reveal(); + } +} diff --git a/src/Bundle/ChillPersonBundle/Tests/Workflow/AccompanyingPeriodWorkEvaluationWorkflowHandlerTest.php b/src/Bundle/ChillPersonBundle/Tests/Workflow/AccompanyingPeriodWorkEvaluationWorkflowHandlerTest.php new file mode 100644 index 000000000..1f62e5bb3 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Tests/Workflow/AccompanyingPeriodWorkEvaluationWorkflowHandlerTest.php @@ -0,0 +1,72 @@ +setUser($referrer = new User()); + $accompanyingCourse->addWork($work = new AccompanyingPeriod\AccompanyingPeriodWork()); + $work->addReferrer($workReferrer1 = new User()); + $work->addReferrer($workReferrer2 = new User()); + $work->addReferrer($referrer); + $work->addAccompanyingPeriodWorkEvaluation($eval = new AccompanyingPeriod\AccompanyingPeriodWorkEvaluation()); + $entityWorkflow = new EntityWorkflow(); + $entityWorkflow->setRelatedEntityId(1); + + // Prophesize each dependency + $workflowRepositoryProphecy = $this->prophesize(EntityWorkflowRepository::class); + $translatableStringHelperProphecy = $this->prophesize(TranslatableStringHelperInterface::class); + $translatorProphecy = $this->prophesize(TranslatorInterface::class); + + // Create an instance of the class under test using revealed prophecies directly + $handler = new AccompanyingPeriodWorkEvaluationWorkflowHandler( + $this->buildRepository($eval, 1), + $workflowRepositoryProphecy->reveal(), + $translatableStringHelperProphecy->reveal(), + $translatorProphecy->reveal(), + ); + + $users = $handler->getSuggestedUsers($entityWorkflow); + + self::assertContains($referrer, $users); + self::assertContains($workReferrer1, $users); + self::assertContains($workReferrer2, $users); + } + + private function buildRepository(AccompanyingPeriod\AccompanyingPeriodWorkEvaluation $evaluation, int $id): AccompanyingPeriodWorkEvaluationRepository + { + $evaluationRepositoryProphecy = $this->prophesize(AccompanyingPeriodWorkEvaluationRepository::class); + $evaluationRepositoryProphecy->find($id)->willReturn($evaluation); + + return $evaluationRepositoryProphecy->reveal(); + } +} diff --git a/src/Bundle/ChillPersonBundle/Tests/Workflow/AccompanyingPeriodWorkWorkflowHandlerTest.php b/src/Bundle/ChillPersonBundle/Tests/Workflow/AccompanyingPeriodWorkWorkflowHandlerTest.php new file mode 100644 index 000000000..1d3702871 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Tests/Workflow/AccompanyingPeriodWorkWorkflowHandlerTest.php @@ -0,0 +1,73 @@ +setUser($referrer = new User()); + $accompanyingCourse->addWork($work = new AccompanyingPeriod\AccompanyingPeriodWork()); + $work->addReferrer($workReferrer1 = new User()); + $work->addReferrer($workReferrer2 = new User()); + $work->addReferrer($referrer); + $entityWorkflow = new EntityWorkflow(); + $entityWorkflow->setRelatedEntityId(1); + + // Prophesize each dependency + $workflowRepositoryProphecy = $this->prophesize(EntityWorkflowRepository::class); + $translatableStringHelperProphecy = $this->prophesize(TranslatableStringHelperInterface::class); + $translatorProphecy = $this->prophesize(TranslatorInterface::class); + + // Create an instance of the class under test using revealed prophecies directly + $handler = new AccompanyingPeriodWorkWorkflowHandler( + $this->buildRepository($work, 1), + $workflowRepositoryProphecy->reveal(), + $translatableStringHelperProphecy->reveal(), + $translatorProphecy->reveal(), + ); + + $users = $handler->getSuggestedUsers($entityWorkflow); + + self::assertContains($referrer, $users); + self::assertContains($workReferrer1, $users); + self::assertContains($workReferrer2, $users); + } + + private function buildRepository(AccompanyingPeriod\AccompanyingPeriodWork $work, int $int): AccompanyingPeriodWorkRepository + { + $accompanyingPeriodWorkRepositoryProphecy = $this->prophesize(AccompanyingPeriodWorkRepository::class); + $accompanyingPeriodWorkRepositoryProphecy + ->find($int) + ->willReturn($work); + + return $accompanyingPeriodWorkRepositoryProphecy->reveal(); + } +} diff --git a/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler.php b/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler.php index e2f8e7666..1168d8f35 100644 --- a/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler.php +++ b/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler.php @@ -98,17 +98,36 @@ class AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler implements EntityW public function getSuggestedUsers(EntityWorkflow $entityWorkflow): array { - $suggestedUsers = $entityWorkflow->getUsersInvolved(); + $related = $this->getRelatedEntity($entityWorkflow); - $referrer = $this->getRelatedEntity($entityWorkflow) - ->getAccompanyingPeriodWorkEvaluation() + if (null === $related) { + return []; + } + + $users = []; + if (null !== $referrer = $related->getAccompanyingPeriodWorkEvaluation() ->getAccompanyingPeriodWork() ->getAccompanyingPeriod() - ->getUser(); + ->getUser() + ) { + $users[] = $referrer; + } - $suggestedUsers[spl_object_hash($referrer)] = $referrer; + foreach ($related->getAccompanyingPeriodWorkEvaluation() + ->getAccompanyingPeriodWork() + ->getReferrersHistoryCurrent() as $referrerHistory + ) { + $users[] = $referrerHistory->getUser(); + } - return $suggestedUsers; + return array_values( + // filter objects to remove duplicates + array_filter( + $users, + fn ($o, $k) => array_search($o, $users, true) === $k, + ARRAY_FILTER_USE_BOTH + ) + ); } public function getTemplate(EntityWorkflow $entityWorkflow, array $options = []): string diff --git a/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationWorkflowHandler.php b/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationWorkflowHandler.php index e619532ff..302bbb0be 100644 --- a/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationWorkflowHandler.php +++ b/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationWorkflowHandler.php @@ -81,16 +81,34 @@ readonly class AccompanyingPeriodWorkEvaluationWorkflowHandler implements Entity public function getSuggestedUsers(EntityWorkflow $entityWorkflow): array { - $suggestedUsers = $entityWorkflow->getUsersInvolved(); + $related = $this->getRelatedEntity($entityWorkflow); - $referrer = $this->getRelatedEntity($entityWorkflow) - ->getAccompanyingPeriodWork() + if (null === $related) { + return []; + } + + $users = []; + if (null !== $referrer = $related->getAccompanyingPeriodWork() ->getAccompanyingPeriod() - ->getUser(); + ->getUser() + ) { + $users[] = $referrer; + } - $suggestedUsers[spl_object_hash($referrer)] = $referrer; + foreach ($related->getAccompanyingPeriodWork() + ->getReferrersHistoryCurrent() as $referrerHistory + ) { + $users[] = $referrerHistory->getUser(); + } - return $suggestedUsers; + return array_values( + // filter objects to remove duplicates + array_filter( + $users, + fn ($o, $k) => array_search($o, $users, true) === $k, + ARRAY_FILTER_USE_BOTH + ) + ); } public function getTemplate(EntityWorkflow $entityWorkflow, array $options = []): string diff --git a/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkWorkflowHandler.php b/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkWorkflowHandler.php index 772523ad5..8a7b5ef48 100644 --- a/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkWorkflowHandler.php +++ b/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkWorkflowHandler.php @@ -87,17 +87,32 @@ readonly class AccompanyingPeriodWorkWorkflowHandler implements EntityWorkflowHa public function getSuggestedUsers(EntityWorkflow $entityWorkflow): array { - $suggestedUsers = $entityWorkflow->getUsersInvolved(); + $related = $this->getRelatedEntity($entityWorkflow); - $referrer = $this->getRelatedEntity($entityWorkflow) - ->getAccompanyingPeriod() - ->getUser(); - - if (null !== $referrer) { - $suggestedUsers[spl_object_hash($referrer)] = $referrer; + if (null === $related) { + return []; } - return $suggestedUsers; + $users = []; + if (null !== $referrer = $related->getAccompanyingPeriod() + ->getUser() + ) { + $users[] = $referrer; + } + + foreach ($related->getReferrersHistoryCurrent() as $referrerHistory + ) { + $users[] = $referrerHistory->getUser(); + } + + return array_values( + // filter objects to remove duplicates + array_filter( + $users, + fn ($o, $k) => array_search($o, $users, true) === $k, + ARRAY_FILTER_USE_BOTH + ) + ); } public function getTemplate(EntityWorkflow $entityWorkflow, array $options = []): string From 85dc9bdb2fb6a66c5f98ba8f7423bbd2bcb8ffb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 22 Oct 2024 23:35:13 +0200 Subject: [PATCH 2/6] Add `getSuggestedUsers` method in `EntityWorkflowManager` Implemented the method to retrieve a list of suggested users for an entity workflow, filtering out duplicates. Added corresponding unit tests to verify the method's functionality and ensure its correctness in various scenarios. --- .../Workflow/EntityWorkflowManagerTest.php | 49 +++++++++++++++++++ .../Workflow/EntityWorkflowManager.php | 27 ++++++++++ 2 files changed, 76 insertions(+) create mode 100644 src/Bundle/ChillMainBundle/Tests/Workflow/EntityWorkflowManagerTest.php diff --git a/src/Bundle/ChillMainBundle/Tests/Workflow/EntityWorkflowManagerTest.php b/src/Bundle/ChillMainBundle/Tests/Workflow/EntityWorkflowManagerTest.php new file mode 100644 index 000000000..4570d86b8 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Tests/Workflow/EntityWorkflowManagerTest.php @@ -0,0 +1,49 @@ +createMock(EntityWorkflow::class); + $entityWorkflow->method('getUsersInvolved')->willReturn([$user1, $user2]); + + $user3 = new User(); + $handler = $this->createMock(EntityWorkflowHandlerInterface::class); + $handler->method('getSuggestedUsers')->willReturn([$user1, $user3]); + $handler->method('supports')->willReturn(true); + + $manager = new EntityWorkflowManager([$handler], new Registry()); + + $users = $manager->getSuggestedUsers($entityWorkflow); + + self::assertcount(3, $users); + self::assertContains($user1, $users); + self::assertContains($user2, $users); + self::assertContains($user3, $users); + } +} diff --git a/src/Bundle/ChillMainBundle/Workflow/EntityWorkflowManager.php b/src/Bundle/ChillMainBundle/Workflow/EntityWorkflowManager.php index f1c87fd4e..16cfd66b7 100644 --- a/src/Bundle/ChillMainBundle/Workflow/EntityWorkflowManager.php +++ b/src/Bundle/ChillMainBundle/Workflow/EntityWorkflowManager.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Chill\MainBundle\Workflow; use Chill\DocStoreBundle\Entity\StoredObject; +use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\Workflow\EntityWorkflow; use Chill\MainBundle\Entity\Workflow\EntityWorkflowSend; use Chill\MainBundle\Workflow\Exception\HandlerNotFoundException; @@ -93,4 +94,30 @@ class EntityWorkflowManager throw new HandlerWithPublicViewNotFoundException(); } + + /** + * @return list + */ + public function getSuggestedUsers(EntityWorkflow $entityWorkflow, bool $addUsersInvolved = true): array + { + $users = []; + if ($addUsersInvolved) { + foreach ($entityWorkflow->getUsersInvolved() as $user) { + $users[] = $user; + } + } + + foreach ($this->getHandler($entityWorkflow)->getSuggestedUsers($entityWorkflow) as $user) { + $users[] = $user; + } + + return array_values( + // filter objects to remove duplicates + array_filter( + $users, + fn ($o, $k) => array_search($o, $users, true) === $k, + ARRAY_FILTER_USE_BOTH + ) + ); + } } From 968835a2626f3811179c0ec851adc64ac0566e7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 22 Oct 2024 23:51:48 +0200 Subject: [PATCH 3/6] Refactor user suggestion logic in workflow Removed duplicate user suggestion handling from `WorkflowController` and centralized it in `WorkflowStepType`. This change simplifies the controller and makes user suggestion logic more maintainable. --- .../ChillMainBundle/Controller/WorkflowController.php | 7 ------- src/Bundle/ChillMainBundle/Form/WorkflowStepType.php | 11 +++++++---- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Controller/WorkflowController.php b/src/Bundle/ChillMainBundle/Controller/WorkflowController.php index e10cac6a4..1f1372cd2 100644 --- a/src/Bundle/ChillMainBundle/Controller/WorkflowController.php +++ b/src/Bundle/ChillMainBundle/Controller/WorkflowController.php @@ -300,19 +300,12 @@ class WorkflowController extends AbstractController if (\count($workflow->getEnabledTransitions($entityWorkflow)) > 0) { // possible transition $stepDTO = new WorkflowTransitionContextDTO($entityWorkflow); - $usersInvolved = $entityWorkflow->getUsersInvolved(); - $currentUserFound = array_search($this->security->getUser(), $usersInvolved, true); - - if (false !== $currentUserFound) { - unset($usersInvolved[$currentUserFound]); - } $transitionForm = $this->createForm( WorkflowStepType::class, $stepDTO, [ 'entity_workflow' => $entityWorkflow, - 'suggested_users' => $usersInvolved, ] ); diff --git a/src/Bundle/ChillMainBundle/Form/WorkflowStepType.php b/src/Bundle/ChillMainBundle/Form/WorkflowStepType.php index e5769a28e..18afc5c58 100644 --- a/src/Bundle/ChillMainBundle/Form/WorkflowStepType.php +++ b/src/Bundle/ChillMainBundle/Form/WorkflowStepType.php @@ -17,6 +17,7 @@ use Chill\MainBundle\Form\Type\ChillTextareaType; use Chill\MainBundle\Form\Type\PickUserDynamicType; use Chill\MainBundle\Form\Type\PickUserGroupOrUserDynamicType; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; +use Chill\MainBundle\Workflow\EntityWorkflowManager; use Chill\MainBundle\Workflow\WorkflowTransitionContextDTO; use Chill\PersonBundle\Form\Type\PickPersonDynamicType; use Chill\ThirdPartyBundle\Form\Type\PickThirdpartyDynamicType; @@ -34,6 +35,7 @@ class WorkflowStepType extends AbstractType public function __construct( private readonly Registry $registry, private readonly TranslatableStringHelperInterface $translatableStringHelper, + private readonly EntityWorkflowManager $entityWorkflowManager, ) {} public function buildForm(FormBuilderInterface $builder, array $options) @@ -43,6 +45,7 @@ class WorkflowStepType extends AbstractType $workflow = $this->registry->get($entityWorkflow, $entityWorkflow->getWorkflowName()); $place = $workflow->getMarking($entityWorkflow); $placeMetadata = $workflow->getMetadataStore()->getPlaceMetadata(array_keys($place->getPlaces())[0]); + $suggestedUsers = $this->entityWorkflowManager->getSuggestedUsers($entityWorkflow); if (null === $options['entity_workflow']) { throw new \LogicException('if transition is true, entity_workflow should be defined'); @@ -157,19 +160,20 @@ class WorkflowStepType extends AbstractType 'label' => 'workflow.signature_zone.user signature', 'multiple' => false, 'suggest_myself' => true, + 'suggested' => $suggestedUsers, ]) ->add('futureDestUsers', PickUserGroupOrUserDynamicType::class, [ 'label' => 'workflow.dest for next steps', 'multiple' => true, 'empty_data' => '[]', - 'suggested' => $options['suggested_users'], + 'suggested' => $suggestedUsers, 'suggest_myself' => true, ]) ->add('futureCcUsers', PickUserDynamicType::class, [ 'label' => 'workflow.cc for next steps', 'multiple' => true, 'required' => false, - 'suggested' => $options['suggested_users'], + 'suggested' => $suggestedUsers, 'empty_data' => '[]', 'attr' => ['class' => 'future-cc-users'], 'suggest_myself' => true, @@ -207,7 +211,6 @@ class WorkflowStepType extends AbstractType $resolver ->setDefault('data_class', WorkflowTransitionContextDTO::class) ->setRequired('entity_workflow') - ->setAllowedTypes('entity_workflow', EntityWorkflow::class) - ->setDefault('suggested_users', []); + ->setAllowedTypes('entity_workflow', EntityWorkflow::class); } } From 4f18b1d2b2a968086c24a3f0b3008ea340d929a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 23 Oct 2024 00:51:09 +0200 Subject: [PATCH 4/6] Add services and tests for associated entities management Implemented services to provide associated persons and third parties for accompanying periods and their works. Included comprehensive tests to ensure proper functionality and associations. --- .../ProvidePersonsAssociated.php | 34 ++++++++++++ .../ProvideThirdPartiesAssociated.php | 50 ++++++++++++++++++ .../ProvidePersonsAssociated.php | 32 ++++++++++++ .../ProvideThirdPartiesAssociated.php | 49 +++++++++++++++++ .../ProvideThirdPartiesAssociatedTest.php | 45 ++++++++++++++++ .../ProvideThirdPartiesAssociatedTest.php | 52 +++++++++++++++++++ 6 files changed, 262 insertions(+) create mode 100644 src/Bundle/ChillPersonBundle/Service/AccompanyingPeriod/ProvidePersonsAssociated.php create mode 100644 src/Bundle/ChillPersonBundle/Service/AccompanyingPeriod/ProvideThirdPartiesAssociated.php create mode 100644 src/Bundle/ChillPersonBundle/Service/AccompanyingPeriodWork/ProvidePersonsAssociated.php create mode 100644 src/Bundle/ChillPersonBundle/Service/AccompanyingPeriodWork/ProvideThirdPartiesAssociated.php create mode 100644 src/Bundle/ChillPersonBundle/Tests/Service/AccompanyingPeriod/ProvideThirdPartiesAssociatedTest.php create mode 100644 src/Bundle/ChillPersonBundle/Tests/Service/AccompanyingPeriodWork/ProvideThirdPartiesAssociatedTest.php diff --git a/src/Bundle/ChillPersonBundle/Service/AccompanyingPeriod/ProvidePersonsAssociated.php b/src/Bundle/ChillPersonBundle/Service/AccompanyingPeriod/ProvidePersonsAssociated.php new file mode 100644 index 000000000..af1ae6e0f --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Service/AccompanyingPeriod/ProvidePersonsAssociated.php @@ -0,0 +1,34 @@ + + */ + public function getPersonsAssociated(AccompanyingPeriod $period): array + { + return array_values( + $period->getCurrentParticipations() + ->map(fn (AccompanyingPeriodParticipation $participation) => $participation->getPerson()) + ->toArray() + ); + } +} diff --git a/src/Bundle/ChillPersonBundle/Service/AccompanyingPeriod/ProvideThirdPartiesAssociated.php b/src/Bundle/ChillPersonBundle/Service/AccompanyingPeriod/ProvideThirdPartiesAssociated.php new file mode 100644 index 000000000..5aa24bcda --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Service/AccompanyingPeriod/ProvideThirdPartiesAssociated.php @@ -0,0 +1,50 @@ + + */ + public function getThirdPartiesAssociated(AccompanyingPeriod $period): array + { + $thirdParties = []; + + foreach ( + $period + ->getResources()->filter(fn (Resource $resource) => null !== $resource->getThirdParty()) + ->map(fn (Resource $resource) => $resource->getThirdParty()) as $thirdParty) { + $thirdParties[] = $thirdParty; + } + + if (null !== $requestor = $period->getRequestorThirdParty()) { + $thirdParties[] = $requestor; + } + + return array_values( + // filter objects to remove duplicates + array_filter( + $thirdParties, + fn ($o, $k) => array_search($o, $thirdParties, true) === $k, + ARRAY_FILTER_USE_BOTH + ) + ); + } +} diff --git a/src/Bundle/ChillPersonBundle/Service/AccompanyingPeriodWork/ProvidePersonsAssociated.php b/src/Bundle/ChillPersonBundle/Service/AccompanyingPeriodWork/ProvidePersonsAssociated.php new file mode 100644 index 000000000..5fd885948 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Service/AccompanyingPeriodWork/ProvidePersonsAssociated.php @@ -0,0 +1,32 @@ + + */ + public function getPersonsAssociated(AccompanyingPeriod\AccompanyingPeriodWork $work): array + { + return $this->providePersonsAssociated->getPersonsAssociated($work->getAccompanyingPeriod()); + } +} diff --git a/src/Bundle/ChillPersonBundle/Service/AccompanyingPeriodWork/ProvideThirdPartiesAssociated.php b/src/Bundle/ChillPersonBundle/Service/AccompanyingPeriodWork/ProvideThirdPartiesAssociated.php new file mode 100644 index 000000000..2aa73935d --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Service/AccompanyingPeriodWork/ProvideThirdPartiesAssociated.php @@ -0,0 +1,49 @@ + + */ + public function getThirdPartiesAssociated(AccompanyingPeriodWork $accompanyingPeriodWork): array + { + $thirdParties = $this->thirdPartiesAssociated->getThirdPartiesAssociated($accompanyingPeriodWork->getAccompanyingPeriod()); + + if (null !== $tp = $accompanyingPeriodWork->getHandlingThierParty()) { + $thirdParties[] = $tp; + } + + foreach ($accompanyingPeriodWork->getThirdParties() as $thirdParty) { + $thirdParties[] = $thirdParty; + } + + return array_values( + // filter objects to remove duplicates + array_filter( + $thirdParties, + fn ($o, $k) => array_search($o, $thirdParties, true) === $k, + ARRAY_FILTER_USE_BOTH + ) + ); + } +} diff --git a/src/Bundle/ChillPersonBundle/Tests/Service/AccompanyingPeriod/ProvideThirdPartiesAssociatedTest.php b/src/Bundle/ChillPersonBundle/Tests/Service/AccompanyingPeriod/ProvideThirdPartiesAssociatedTest.php new file mode 100644 index 000000000..ccc2a902e --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Tests/Service/AccompanyingPeriod/ProvideThirdPartiesAssociatedTest.php @@ -0,0 +1,45 @@ +setRequestor($tp1 = new ThirdParty()); + $period->addResource((new AccompanyingPeriod\Resource())->setResource($tp1)); + $period->addResource((new AccompanyingPeriod\Resource())->setResource($tp2 = new ThirdParty())); + $period->addResource((new AccompanyingPeriod\Resource())->setResource($p1 = new Person())); + + $provider = new ProvideThirdPartiesAssociated(); + + $thirdParties = $provider->getThirdPartiesAssociated($period); + + self::assertCount(2, $thirdParties); + self::assertContains($tp1, $thirdParties); + self::assertContains($tp2, $thirdParties); + self::assertNotContains($p1, $thirdParties); + self::assertNotContains(null, $thirdParties); + } +} diff --git a/src/Bundle/ChillPersonBundle/Tests/Service/AccompanyingPeriodWork/ProvideThirdPartiesAssociatedTest.php b/src/Bundle/ChillPersonBundle/Tests/Service/AccompanyingPeriodWork/ProvideThirdPartiesAssociatedTest.php new file mode 100644 index 000000000..5ce7b953e --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Tests/Service/AccompanyingPeriodWork/ProvideThirdPartiesAssociatedTest.php @@ -0,0 +1,52 @@ +setRequestor($tp1 = new ThirdParty()); + $period->addResource((new AccompanyingPeriod\Resource())->setResource($tp1)); + $period->addResource((new AccompanyingPeriod\Resource())->setResource($tp2 = new ThirdParty())); + $period->addResource((new AccompanyingPeriod\Resource())->setResource($p1 = new Person())); + $period->addWork($work = new AccompanyingPeriod\AccompanyingPeriodWork()); + $work->addThirdParty($tp3 = new ThirdParty()); + $work->addThirdParty($tp1); + $work->setHandlingThierParty($tp4 = new ThirdParty()); + + $providerAccPeriod = new \Chill\PersonBundle\Service\AccompanyingPeriod\ProvideThirdPartiesAssociated(); + $provider = new ProvideThirdPartiesAssociated($providerAccPeriod); + + + $thirdParties = $provider->getThirdPartiesAssociated($work); + + self::assertContains($tp1, $thirdParties); + self::assertContains($tp2, $thirdParties); + self::assertContains($tp3, $thirdParties); + self::assertContains($tp4, $thirdParties); + self::assertNotContains($p1, $thirdParties); + self::assertCount(4, $thirdParties); + } +} From 261bc88b5ea09b0e9dab30ea11f428d625e5095b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 23 Oct 2024 01:06:15 +0200 Subject: [PATCH 5/6] Add suggested persons and third parties methods Introduced getSuggestedPersons and getSuggestedThirdParties methods across various WorkflowHandlers. These methods integrate with ProvidePersonsAssociated and ProvideThirdPartiesAssociated services to fetch related entities, enhancing the workflow handling capabilities. --- ...nyingCourseDocumentWorkflowHandlerTest.php | 8 ++++++ ...ompanyingCourseDocumentWorkflowHandler.php | 26 +++++++++++++++++++ .../WorkflowViewSendPublicControllerTest.php | 10 +++++++ .../EntityWorkflowHandlerInterface.php | 12 +++++++++ .../Workflow/EntityWorkflowManager.php | 18 +++++++++++++ ...kEvaluationDocumentWorkflowHandlerTest.php | 4 +++ ...eriodWorkEvaluationWorkflowHandlerTest.php | 5 ++++ ...ompanyingPeriodWorkWorkflowHandlerTest.php | 5 ++++ ...dWorkEvaluationDocumentWorkflowHandler.php | 26 +++++++++++++++++++ ...ingPeriodWorkEvaluationWorkflowHandler.php | 26 +++++++++++++++++++ .../AccompanyingPeriodWorkWorkflowHandler.php | 26 +++++++++++++++++++ 11 files changed, 166 insertions(+) diff --git a/src/Bundle/ChillDocStoreBundle/Tests/Workflow/AccompanyingCourseDocumentWorkflowHandlerTest.php b/src/Bundle/ChillDocStoreBundle/Tests/Workflow/AccompanyingCourseDocumentWorkflowHandlerTest.php index e40b240f4..cf8bc9c7c 100644 --- a/src/Bundle/ChillDocStoreBundle/Tests/Workflow/AccompanyingCourseDocumentWorkflowHandlerTest.php +++ b/src/Bundle/ChillDocStoreBundle/Tests/Workflow/AccompanyingCourseDocumentWorkflowHandlerTest.php @@ -13,10 +13,14 @@ namespace Chill\DocStoreBundle\Tests\Workflow; use Chill\DocStoreBundle\Entity\AccompanyingCourseDocument; use Chill\DocStoreBundle\Repository\AccompanyingCourseDocumentRepository; +use Chill\DocStoreBundle\Workflow\AccompanyingCourseDocumentWorkflowHandler; +use Chill\DocStoreBundle\Workflow\WorkflowWithPublicViewDocumentHelper; use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\Workflow\EntityWorkflow; use Chill\MainBundle\Repository\Workflow\EntityWorkflowRepository; use Chill\PersonBundle\Entity\AccompanyingPeriod; +use Chill\PersonBundle\Service\AccompanyingPeriod\ProvidePersonsAssociated; +use Chill\PersonBundle\Service\AccompanyingPeriod\ProvideThirdPartiesAssociated; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; use Symfony\Contracts\Translation\TranslatorInterface; @@ -45,6 +49,8 @@ class AccompanyingCourseDocumentWorkflowHandlerTest extends TestCase $this->prophesize(EntityWorkflowRepository::class)->reveal(), $this->buildRepository($document, 1), new WorkflowWithPublicViewDocumentHelper($this->prophesize(Environment::class)->reveal()), + $this->prophesize(ProvideThirdPartiesAssociated::class)->reveal(), + $this->prophesize(ProvidePersonsAssociated::class)->reveal(), ); $users = $handler->getSuggestedUsers($entityWorkflow); @@ -68,6 +74,8 @@ class AccompanyingCourseDocumentWorkflowHandlerTest extends TestCase $this->prophesize(EntityWorkflowRepository::class)->reveal(), $this->buildRepository($document, 1), new WorkflowWithPublicViewDocumentHelper($this->prophesize(Environment::class)->reveal()), + $this->prophesize(ProvideThirdPartiesAssociated::class)->reveal(), + $this->prophesize(ProvidePersonsAssociated::class)->reveal(), ); $users = $handler->getSuggestedUsers($entityWorkflow); diff --git a/src/Bundle/ChillDocStoreBundle/Workflow/AccompanyingCourseDocumentWorkflowHandler.php b/src/Bundle/ChillDocStoreBundle/Workflow/AccompanyingCourseDocumentWorkflowHandler.php index b98e5d4a9..193568286 100644 --- a/src/Bundle/ChillDocStoreBundle/Workflow/AccompanyingCourseDocumentWorkflowHandler.php +++ b/src/Bundle/ChillDocStoreBundle/Workflow/AccompanyingCourseDocumentWorkflowHandler.php @@ -22,6 +22,8 @@ use Chill\MainBundle\Workflow\EntityWorkflowWithPublicViewInterface; use Chill\MainBundle\Workflow\EntityWorkflowWithStoredObjectHandlerInterface; use Chill\MainBundle\Workflow\Templating\EntityWorkflowViewMetadataDTO; use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation; +use Chill\PersonBundle\Service\AccompanyingPeriod\ProvideThirdPartiesAssociated; +use Chill\PersonBundle\Service\AccompanyingPeriod\ProvidePersonsAssociated; use Symfony\Contracts\Translation\TranslatorInterface; /** @@ -34,6 +36,8 @@ final readonly class AccompanyingCourseDocumentWorkflowHandler implements Entity private EntityWorkflowRepository $workflowRepository, private AccompanyingCourseDocumentRepository $repository, private WorkflowWithPublicViewDocumentHelper $publicViewDocumentHelper, + private ProvideThirdPartiesAssociated $thirdPartiesAssociated, + private ProvidePersonsAssociated $providePersonsAssociated, ) {} public function getDeletionRoles(): array @@ -161,4 +165,26 @@ final readonly class AccompanyingCourseDocumentWorkflowHandler implements Entity { return $this->publicViewDocumentHelper->render($entityWorkflowSend, $metadata, $this); } + + public function getSuggestedPersons(EntityWorkflow $entityWorkflow): array + { + $related = $this->getRelatedEntity($entityWorkflow); + + if (null === $related) { + return []; + } + + return $this->providePersonsAssociated->getPersonsAssociated($related->getCourse()); + } + + public function getSuggestedThirdParties(EntityWorkflow $entityWorkflow): array + { + $related = $this->getRelatedEntity($entityWorkflow); + + if (null === $related) { + return []; + } + + return $this->thirdPartiesAssociated->getThirdPartiesAssociated($related->getCourse()); + } } diff --git a/src/Bundle/ChillMainBundle/Tests/Controller/WorkflowViewSendPublicControllerTest.php b/src/Bundle/ChillMainBundle/Tests/Controller/WorkflowViewSendPublicControllerTest.php index 02bee8f4f..d5a4d6561 100644 --- a/src/Bundle/ChillMainBundle/Tests/Controller/WorkflowViewSendPublicControllerTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Controller/WorkflowViewSendPublicControllerTest.php @@ -238,6 +238,16 @@ class WorkflowViewSendPublicControllerTest extends TestCase { return 'content'; } + + public function getSuggestedPersons(EntityWorkflow $entityWorkflow): array + { + return []; + } + + public function getSuggestedThirdParties(EntityWorkflow $entityWorkflow): array + { + return []; + } }; } diff --git a/src/Bundle/ChillMainBundle/Workflow/EntityWorkflowHandlerInterface.php b/src/Bundle/ChillMainBundle/Workflow/EntityWorkflowHandlerInterface.php index c0d6469f6..0cc03084e 100644 --- a/src/Bundle/ChillMainBundle/Workflow/EntityWorkflowHandlerInterface.php +++ b/src/Bundle/ChillMainBundle/Workflow/EntityWorkflowHandlerInterface.php @@ -13,6 +13,8 @@ namespace Chill\MainBundle\Workflow; use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\Workflow\EntityWorkflow; +use Chill\PersonBundle\Entity\Person; +use Chill\ThirdPartyBundle\Entity\ThirdParty; /** * @template T of object @@ -48,6 +50,16 @@ interface EntityWorkflowHandlerInterface */ public function getSuggestedUsers(EntityWorkflow $entityWorkflow): array; + /** + * @return list + */ + public function getSuggestedPersons(EntityWorkflow $entityWorkflow): array; + + /** + * @return list + */ + public function getSuggestedThirdParties(EntityWorkflow $entityWorkflow): array; + public function getTemplate(EntityWorkflow $entityWorkflow, array $options = []): string; public function getTemplateData(EntityWorkflow $entityWorkflow, array $options = []): array; diff --git a/src/Bundle/ChillMainBundle/Workflow/EntityWorkflowManager.php b/src/Bundle/ChillMainBundle/Workflow/EntityWorkflowManager.php index 16cfd66b7..474370127 100644 --- a/src/Bundle/ChillMainBundle/Workflow/EntityWorkflowManager.php +++ b/src/Bundle/ChillMainBundle/Workflow/EntityWorkflowManager.php @@ -18,6 +18,8 @@ use Chill\MainBundle\Entity\Workflow\EntityWorkflowSend; use Chill\MainBundle\Workflow\Exception\HandlerNotFoundException; use Chill\MainBundle\Workflow\Exception\HandlerWithPublicViewNotFoundException; use Chill\MainBundle\Workflow\Templating\EntityWorkflowViewMetadataDTO; +use Chill\PersonBundle\Entity\Person; +use Chill\ThirdPartyBundle\Entity\ThirdParty; use Symfony\Component\Workflow\Registry; /** @@ -120,4 +122,20 @@ class EntityWorkflowManager ) ); } + + /** + * @return list + */ + public function getSuggestedPersons(EntityWorkflow $entityWorkflow): array + { + return $this->getHandler($entityWorkflow)->getSuggestedPersons($entityWorkflow); + } + + /** + * @return list + */ + public function getSuggestedThirdParties(EntityWorkflow $entityWorkflow): array + { + return $this->getHandler($entityWorkflow)->getSuggestedThirdParties($entityWorkflow); + } } diff --git a/src/Bundle/ChillPersonBundle/Tests/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandlerTest.php b/src/Bundle/ChillPersonBundle/Tests/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandlerTest.php index 2e7076a4d..df701d906 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandlerTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandlerTest.php @@ -19,6 +19,8 @@ use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocument; use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocumentRepository; +use Chill\PersonBundle\Service\AccompanyingPeriodWork\ProvidePersonsAssociated; +use Chill\PersonBundle\Service\AccompanyingPeriodWork\ProvideThirdPartiesAssociated; use Chill\PersonBundle\Workflow\AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; @@ -59,6 +61,8 @@ class AccompanyingPeriodWorkEvaluationDocumentWorkflowHandlerTest extends TestCa $translatableStringHelperProphecy->reveal(), $translatorProphecy->reveal(), new WorkflowWithPublicViewDocumentHelper($twig->reveal()), + $this->prophesize(ProvideThirdPartiesAssociated::class)->reveal(), + $this->prophesize(ProvidePersonsAssociated::class)->reveal(), ); $entityWorkflow->setRelatedEntityId(1); diff --git a/src/Bundle/ChillPersonBundle/Tests/Workflow/AccompanyingPeriodWorkEvaluationWorkflowHandlerTest.php b/src/Bundle/ChillPersonBundle/Tests/Workflow/AccompanyingPeriodWorkEvaluationWorkflowHandlerTest.php index 1f62e5bb3..bcd1e8c8a 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Workflow/AccompanyingPeriodWorkEvaluationWorkflowHandlerTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Workflow/AccompanyingPeriodWorkEvaluationWorkflowHandlerTest.php @@ -17,6 +17,9 @@ use Chill\MainBundle\Repository\Workflow\EntityWorkflowRepository; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationRepository; +use Chill\PersonBundle\Service\AccompanyingPeriodWork\ProvidePersonsAssociated; +use Chill\PersonBundle\Service\AccompanyingPeriodWork\ProvideThirdPartiesAssociated; +use Chill\PersonBundle\Workflow\AccompanyingPeriodWorkEvaluationWorkflowHandler; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; use Symfony\Contracts\Translation\TranslatorInterface; @@ -53,6 +56,8 @@ class AccompanyingPeriodWorkEvaluationWorkflowHandlerTest extends TestCase $workflowRepositoryProphecy->reveal(), $translatableStringHelperProphecy->reveal(), $translatorProphecy->reveal(), + $this->prophesize(ProvideThirdPartiesAssociated::class)->reveal(), + $this->prophesize(ProvidePersonsAssociated::class)->reveal(), ); $users = $handler->getSuggestedUsers($entityWorkflow); diff --git a/src/Bundle/ChillPersonBundle/Tests/Workflow/AccompanyingPeriodWorkWorkflowHandlerTest.php b/src/Bundle/ChillPersonBundle/Tests/Workflow/AccompanyingPeriodWorkWorkflowHandlerTest.php index 1d3702871..5fcaf8eb4 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Workflow/AccompanyingPeriodWorkWorkflowHandlerTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Workflow/AccompanyingPeriodWorkWorkflowHandlerTest.php @@ -17,6 +17,9 @@ use Chill\MainBundle\Repository\Workflow\EntityWorkflowRepository; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository; +use Chill\PersonBundle\Service\AccompanyingPeriodWork\ProvidePersonsAssociated; +use Chill\PersonBundle\Service\AccompanyingPeriodWork\ProvideThirdPartiesAssociated; +use Chill\PersonBundle\Workflow\AccompanyingPeriodWorkWorkflowHandler; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; use Symfony\Contracts\Translation\TranslatorInterface; @@ -52,6 +55,8 @@ class AccompanyingPeriodWorkWorkflowHandlerTest extends TestCase $workflowRepositoryProphecy->reveal(), $translatableStringHelperProphecy->reveal(), $translatorProphecy->reveal(), + $this->prophesize(ProvideThirdPartiesAssociated::class)->reveal(), + $this->prophesize(ProvidePersonsAssociated::class)->reveal(), ); $users = $handler->getSuggestedUsers($entityWorkflow); diff --git a/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler.php b/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler.php index 1168d8f35..780b81c1d 100644 --- a/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler.php +++ b/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler.php @@ -23,6 +23,8 @@ use Chill\MainBundle\Workflow\Templating\EntityWorkflowViewMetadataDTO; use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocument; use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocumentRepository; use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodWorkEvaluationDocumentVoter; +use Chill\PersonBundle\Service\AccompanyingPeriodWork\ProvidePersonsAssociated; +use Chill\PersonBundle\Service\AccompanyingPeriodWork\ProvideThirdPartiesAssociated; use Symfony\Contracts\Translation\TranslatorInterface; /** @@ -36,6 +38,8 @@ class AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler implements EntityW private readonly TranslatableStringHelperInterface $translatableStringHelper, private readonly TranslatorInterface $translator, private readonly WorkflowWithPublicViewDocumentHelper $publicViewDocumentHelper, + private readonly ProvideThirdPartiesAssociated $provideThirdPartiesAssociated, + private readonly ProvidePersonsAssociated $providePersonsAssociated, ) {} public function getDeletionRoles(): array @@ -179,4 +183,26 @@ class AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler implements EntityW { return $this->publicViewDocumentHelper->render($entityWorkflowSend, $metadata, $this); } + + public function getSuggestedPersons(EntityWorkflow $entityWorkflow): array + { + $related = $this->getRelatedEntity($entityWorkflow); + + if (null === $related) { + return []; + } + + return $this->providePersonsAssociated->getPersonsAssociated($related->getAccompanyingPeriodWorkEvaluation()->getAccompanyingPeriodWork()); + } + + public function getSuggestedThirdParties(EntityWorkflow $entityWorkflow): array + { + $related = $this->getRelatedEntity($entityWorkflow); + + if (null === $related) { + return []; + } + + return $this->provideThirdPartiesAssociated->getThirdPartiesAssociated($related->getAccompanyingPeriodWorkEvaluation()->getAccompanyingPeriodWork()); + } } diff --git a/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationWorkflowHandler.php b/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationWorkflowHandler.php index 302bbb0be..3e72e65bd 100644 --- a/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationWorkflowHandler.php +++ b/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationWorkflowHandler.php @@ -19,6 +19,8 @@ use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluatio use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocument; use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationRepository; use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodWorkEvaluationVoter; +use Chill\PersonBundle\Service\AccompanyingPeriodWork\ProvidePersonsAssociated; +use Chill\PersonBundle\Service\AccompanyingPeriodWork\ProvideThirdPartiesAssociated; use Symfony\Contracts\Translation\TranslatorInterface; /** @@ -31,6 +33,8 @@ readonly class AccompanyingPeriodWorkEvaluationWorkflowHandler implements Entity private EntityWorkflowRepository $workflowRepository, private TranslatableStringHelperInterface $translatableStringHelper, private TranslatorInterface $translator, + private ProvideThirdPartiesAssociated $provideThirdPartiesAssociated, + private ProvidePersonsAssociated $providePersonsAssociated, ) {} public function getDeletionRoles(): array @@ -147,4 +151,26 @@ readonly class AccompanyingPeriodWorkEvaluationWorkflowHandler implements Entity return $this->workflowRepository->findByRelatedEntity(AccompanyingPeriodWorkEvaluation::class, $object->getId()); } + + public function getSuggestedPersons(EntityWorkflow $entityWorkflow): array + { + $related = $this->getRelatedEntity($entityWorkflow); + + if (null === $related) { + return []; + } + + return $this->providePersonsAssociated->getPersonsAssociated($related->getAccompanyingPeriodWork()); + } + + public function getSuggestedThirdParties(EntityWorkflow $entityWorkflow): array + { + $related = $this->getRelatedEntity($entityWorkflow); + + if (null === $related) { + return []; + } + + return $this->provideThirdPartiesAssociated->getThirdPartiesAssociated($related->getAccompanyingPeriodWork()); + } } diff --git a/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkWorkflowHandler.php b/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkWorkflowHandler.php index 8a7b5ef48..58d3c9875 100644 --- a/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkWorkflowHandler.php +++ b/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkWorkflowHandler.php @@ -20,6 +20,8 @@ use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluatio use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocument; use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository; use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodWorkVoter; +use Chill\PersonBundle\Service\AccompanyingPeriodWork\ProvidePersonsAssociated; +use Chill\PersonBundle\Service\AccompanyingPeriodWork\ProvideThirdPartiesAssociated; use Symfony\Contracts\Translation\TranslatorInterface; /** @@ -32,6 +34,8 @@ readonly class AccompanyingPeriodWorkWorkflowHandler implements EntityWorkflowHa private EntityWorkflowRepository $workflowRepository, private TranslatableStringHelperInterface $translatableStringHelper, private TranslatorInterface $translator, + private ProvideThirdPartiesAssociated $thirdPartiesAssociated, + private ProvidePersonsAssociated $providePersonsAssociated, ) {} public function getDeletionRoles(): array @@ -151,4 +155,26 @@ readonly class AccompanyingPeriodWorkWorkflowHandler implements EntityWorkflowHa return $this->workflowRepository->findByRelatedEntity(AccompanyingPeriodWork::class, $object->getId()); } + + public function getSuggestedPersons(EntityWorkflow $entityWorkflow): array + { + $related = $this->getRelatedEntity($entityWorkflow); + + if (null === $related) { + return []; + } + + return $this->providePersonsAssociated->getPersonsAssociated($related); + } + + public function getSuggestedThirdParties(EntityWorkflow $entityWorkflow): array + { + $related = $this->getRelatedEntity($entityWorkflow); + + if (null === $related) { + return []; + } + + return $this->thirdPartiesAssociated->getThirdPartiesAssociated($related); + } } From 19eb6f7ebb44091d25cd546e34796c06d89bfe1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 23 Oct 2024 01:10:39 +0200 Subject: [PATCH 6/6] Add suggested persons and third parties in form Integrated suggested persons and third parties into the WorkflowStepType form. This enhancement auto-populates suggestion fields for better user experience. It ensures that the suggestion data for persons and third parties is readily available in the form configuration. --- src/Bundle/ChillMainBundle/Form/WorkflowStepType.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Bundle/ChillMainBundle/Form/WorkflowStepType.php b/src/Bundle/ChillMainBundle/Form/WorkflowStepType.php index 18afc5c58..222927b42 100644 --- a/src/Bundle/ChillMainBundle/Form/WorkflowStepType.php +++ b/src/Bundle/ChillMainBundle/Form/WorkflowStepType.php @@ -46,6 +46,8 @@ class WorkflowStepType extends AbstractType $place = $workflow->getMarking($entityWorkflow); $placeMetadata = $workflow->getMetadataStore()->getPlaceMetadata(array_keys($place->getPlaces())[0]); $suggestedUsers = $this->entityWorkflowManager->getSuggestedUsers($entityWorkflow); + $suggestedThirdParties = $this->entityWorkflowManager->getSuggestedThirdParties($entityWorkflow); + $suggestedPersons = $this->entityWorkflowManager->getSuggestedPersons($entityWorkflow); if (null === $options['entity_workflow']) { throw new \LogicException('if transition is true, entity_workflow should be defined'); @@ -155,6 +157,7 @@ class WorkflowStepType extends AbstractType 'label' => 'workflow.signature_zone.person signatures', 'multiple' => true, 'empty_data' => '[]', + 'suggested' => $suggestedPersons, ]) ->add('futureUserSignature', PickUserDynamicType::class, [ 'label' => 'workflow.signature_zone.user signature', @@ -196,6 +199,7 @@ class WorkflowStepType extends AbstractType 'help' => 'workflow.transition_destinee_third_party_help', 'multiple' => true, 'empty_data' => [], + 'suggested' => $suggestedThirdParties, ]); $builder