From 226c3eedef8c402576ad237990302944f6771ebb Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Tue, 2 Nov 2021 13:27:51 +0100 Subject: [PATCH 01/62] Update Social Work Metadata importer based on change request. --- .../Service/Import/SocialWorkMetadata.php | 255 ++++++++++++------ 1 file changed, 177 insertions(+), 78 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Service/Import/SocialWorkMetadata.php b/src/Bundle/ChillPersonBundle/Service/Import/SocialWorkMetadata.php index 4683344dd..28bb212ea 100644 --- a/src/Bundle/ChillPersonBundle/Service/Import/SocialWorkMetadata.php +++ b/src/Bundle/ChillPersonBundle/Service/Import/SocialWorkMetadata.php @@ -49,96 +49,196 @@ final class SocialWorkMetadata implements SocialWorkMetadataInterface $this->entityManager = $entityManager; } + /** + * @throws Exception + */ public function import(iterable $dataset): bool { + // Initialisation of the previous result row with the proper data structure. + $result = [ + 'socialIssues' => [ + 'socialIssue' => null, + 'socialIssueChild' => null, + ], + 'socialActions' => [ + 'socialAction' => null, + 'socialActionChild' => null, + ], + 'goal' => null, + 'result' => null, + 'eval' => null, + ]; + foreach ($dataset as $row) { - $this->import1( - array_map( - static fn (string $column): ?string => '' === $column ? null : $column, - array_map('trim', $row) - ) - ); + $result = $this + ->import1( + // Columns cleanup before importing data. + array_map( + static fn (string $column): ?string => '' === $column ? null : $column, + array_map('trim', $row) + ), + $result + ); } return true; } - private function import1(array $row): void + /** + * Row Structure: + * + * Index 0: Parent SocialIssue + * Index 1: Child SocialIssue + * Index 2: Parent SocialAction + * Index 3: Child SocialAction + * Index 4: Goal + * Index 5: Result + * Index 6: Evaluation + * + * @param array $row + * @param array|array|Goal|Result|Evaluation> $previousRow + * + * @return array|array|Goal|Result|Evaluation> + * + * @throws Exception + */ + private function import1(array $row, array $previousRow): array { - // Structure: - // Index 0: SocialIssue.parent - // Index 1: SocialIssue - // Index 2: SocialAction.parent - // Index 3: SocialAction - // Index 4: Goal - // Index 5: Result - // Index 6: Evaluation + $socialIssues = $this + ->handleSocialIssue( + $row[0], + $row[1], + $previousRow['socialIssues']['socialIssue'] ?? null, + $previousRow['socialIssues']['socialIssueChild'] ?? null + ); - $socialIssue = $this->handleSocialIssue($row[0], $row[1]); + $socialActions = $this + ->handleSocialAction( + $row[2], + $row[3], + $socialIssues['socialIssue'], + $previousRow['socialActions']['socialAction'] ?? null, + $previousRow['socialActions']['socialActionChild'] ?? null + ); - $socialAction = $this->handleSocialAction($row[2], $row[3], $socialIssue); - - $goal = $this->handleGoal($row[4], $socialAction); - - $result = $this->handleResult($row[5], $socialAction, $goal); - - $eval = $this->handleEvaluation($row[6], $socialAction); + $goal = $this->handleGoal($row[4], $socialActions['socialAction']); + $result = $this->handleResult($row[5], $socialActions['socialAction'], $goal); + $eval = $this->handleEvaluation($row[6], $socialActions['socialAction']); $this->entityManager->flush(); + + return [ + 'socialIssues' => $socialIssues, + 'socialActions' => $socialActions, + 'goal' => $goal, + 'result' => $result, + 'eval' => $eval, + ]; } - private function handleSocialIssue(?string $socialIssueTitle = null, ?string $socialIssueChildrenTitle = null): SocialIssue - { - if (null !== $socialIssueChildrenTitle) { - /** @var SocialIssue $socialIssueChildren */ - $socialIssueChildren = $this->getOrCreateEntity($this->socialIssueRepository, 'title', ['fr' => $socialIssueChildrenTitle]); - $socialIssueChildren->setTitle(['fr' => $socialIssueChildrenTitle]); + /** + * @return array + * + * @throws Exception + */ + private function handleSocialIssue( + ?string $socialIssueTitle, + ?string $socialIssueChildTitle, + ?SocialIssue $previousSocialIssue, + ?SocialIssue $previousSocialIssueChild, + ): array { + if (null !== $previousSocialIssue && ($socialIssueTitle === $previousSocialIssue->getTitle())) { + $return = [ + 'socialIssue' => $previousSocialIssue, + ]; - $this->entityManager->persist($socialIssueChildren); + return $return + [ + 'socialIssueChild' => (null !== $previousSocialIssueChild && ($socialIssueChildTitle === $previousSocialIssueChild->getTitle())) ? $previousSocialIssueChild : null, + ]; } /** @var SocialIssue $socialIssue */ - $socialIssue = $this->getOrCreateEntity($this->socialIssueRepository, 'title', ['fr' => $socialIssueTitle]); - $socialIssue->setTitle(['fr' => $socialIssueTitle]); + $socialIssue = $this + ->getOrCreateEntity( + $this->socialIssueRepository, + 'title', + ['fr' => $socialIssueTitle] + ) + ->setTitle(['fr' => $socialIssueTitle]); - if (null !== $socialIssueChildrenTitle) { - $socialIssue->addChild($socialIssueChildren); + if (null !== $socialIssueChildTitle) { + /** @var SocialIssue $socialIssueChild */ + $socialIssueChild = $this + ->getOrCreateEntity( + $this->socialIssueRepository, + 'title', + ['fr' => $socialIssueChildTitle] + ) + ->setTitle(['fr' => $socialIssueChildTitle]); + + $this->entityManager->persist($socialIssueChild); + + $socialIssue->addChild($socialIssueChild); } $this->entityManager->persist($socialIssue); - return null === $socialIssueChildrenTitle ? $socialIssue : $socialIssueChildren; + return [ + 'socialIssue' => $socialIssue, + 'socialIssueChild' => $socialIssueChild ?? null, + ]; } - private function handleSocialAction(?string $socialActionTitle, ?string $socialActionChildrenTitle, SocialIssue $socialIssue): SocialAction - { - if (null !== $socialActionChildrenTitle) { - /** @var SocialAction $socialActionChildren */ - $socialActionChildren = $this->getOrCreateEntity($this->socialActionRepository, 'title', ['fr' => $socialActionChildrenTitle]); - $socialActionChildren->setTitle(['fr' => $socialActionChildrenTitle]); + /** + * @return array + * + * @throws Exception + */ + private function handleSocialAction( + ?string $socialActionTitle, + ?string $socialActionChildTitle, + SocialIssue $socialIssue, + ?SocialAction $previousSocialAction, + ?SocialAction $previousSocialActionChild + ): array { + if (null !== $previousSocialAction && ($socialActionTitle === $previousSocialAction->getTitle())) { + $return = [ + 'socialAction' => $previousSocialAction, + ]; - $this->entityManager->persist($socialActionChildren); + return $return + [ + 'socialActionChild' => (null !== $previousSocialActionChild && ($socialActionChildTitle === $previousSocialActionChild->getTitle())) ? $previousSocialActionChild : null, + ]; } /** @var SocialIssue $socialIssue */ $socialAction = $this->getOrCreateEntity($this->socialActionRepository, 'title', ['fr' => $socialActionTitle]); $socialAction->setTitle(['fr' => $socialActionTitle]); - if (null !== $socialActionChildrenTitle) { - $socialActionChildren->setIssue($socialIssue); - $this->entityManager->persist($socialActionChildren); + if (null !== $socialActionChildTitle) { + /** @var SocialAction $socialActionChild */ + $socialActionChild = $this->getOrCreateEntity($this->socialActionRepository, 'title', ['fr' => $socialActionChildTitle]); + $socialActionChild->setTitle(['fr' => $socialActionChildTitle]); - $socialAction->addChild($socialActionChildren); + $this->entityManager->persist($socialActionChild); + + $socialActionChild->setIssue($socialIssue); + $this->entityManager->persist($socialActionChild); + + $socialAction->addChild($socialActionChild); } else { $socialAction->setIssue($socialIssue); } $this->entityManager->persist($socialAction); - return null === $socialActionChildrenTitle ? $socialAction : $socialActionChildren; + return [ + 'socialAction' => $socialAction, + 'socialActionChild' => $socialActionChild ?? null + ]; } - private function handleGoal(?string $goalTitle = null, ?SocialAction $socialAction = null): ?Goal + private function handleGoal(?string $goalTitle, SocialAction $socialAction): ?Goal { if (null === $goalTitle) { return null; @@ -148,19 +248,16 @@ final class SocialWorkMetadata implements SocialWorkMetadataInterface $goal = $this->getOrCreateEntity($this->goalRepository, 'title', ['fr' => $goalTitle]); $goal->setTitle(['fr' => $goalTitle]); - if (null !== $socialAction) { - $socialAction->addGoal($goal); - $goal->addSocialAction($socialAction); - - $this->entityManager->persist($socialAction); - } + $socialAction->addGoal($goal); + $goal->addSocialAction($socialAction); + $this->entityManager->persist($socialAction); $this->entityManager->persist($goal); return $goal; } - private function handleResult(?string $resultTitle = null, ?SocialAction $socialAction = null, ?Goal $goal = null): ?Result + private function handleResult(?string $resultTitle, SocialAction $socialAction, ?Goal $goal): ?Result { if (null === $resultTitle) { return null; @@ -175,8 +272,6 @@ final class SocialWorkMetadata implements SocialWorkMetadataInterface $goal->addResult($result); $this->entityManager->persist($goal); - } else { - $result->addSocialAction($socialAction); } $result->addSocialAction($socialAction); @@ -204,6 +299,9 @@ final class SocialWorkMetadata implements SocialWorkMetadataInterface return $eval; } + /** + * @return array + */ private function findByJson(ObjectRepository $repository, string $field, array $jsonCriterias): array { $qb = $this @@ -214,7 +312,7 @@ final class SocialWorkMetadata implements SocialWorkMetadataInterface $expr = $qb->expr(); - $temporaryJsonCriterias = $jsonParameters = []; + $temporaryJsonCriterias = []; foreach ($jsonCriterias as $key => $value) { $temporaryJsonCriterias[] = [$field, $key, $value, sprintf(':placeholder_%s_%s', $field, $key)]; @@ -256,15 +354,19 @@ final class SocialWorkMetadata implements SocialWorkMetadataInterface $temporaryJsonCriterias ); - $query = $qb + return $qb ->select('s') ->where(...$jsonPredicates) ->setParameters($jsonParameters) - ->getQuery(); - - return $query->getResult(); + ->getQuery() + ->getResult(); } + /** + * @return object + * + * @throws Exception + */ private function getOrCreateEntity(ObjectRepository $repository, string $field, array $jsonCriterias = []) { $results = $this @@ -274,24 +376,21 @@ final class SocialWorkMetadata implements SocialWorkMetadataInterface $jsonCriterias ); - switch (true) { - case count($results) === 0: - $entity = $repository->getClassName(); - $entity = new $entity(); - break; - case count($results) === 1; - $entity = current($results); - break; - case count($results) > 1; - throw new Exception( - sprintf( - 'More than one entity(%s) found.', - $repository->getClassName() - ) - ); + if ($results === []) { + $entity = $repository->getClassName(); + + return new $entity; } - return $entity; + if (count($results) === 1) { + return reset($results); + } + + throw new Exception( + sprintf( + 'Unable to create entity.' + ) + ); } From 90b256daafde518449a9cd5d70f3c73a3ee576bd Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Wed, 3 Nov 2021 10:14:10 +0100 Subject: [PATCH 02/62] fix: Remove extra comma. --- .../ChillPersonBundle/Service/Import/SocialWorkMetadata.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bundle/ChillPersonBundle/Service/Import/SocialWorkMetadata.php b/src/Bundle/ChillPersonBundle/Service/Import/SocialWorkMetadata.php index 28bb212ea..f7fb59742 100644 --- a/src/Bundle/ChillPersonBundle/Service/Import/SocialWorkMetadata.php +++ b/src/Bundle/ChillPersonBundle/Service/Import/SocialWorkMetadata.php @@ -145,7 +145,7 @@ final class SocialWorkMetadata implements SocialWorkMetadataInterface ?string $socialIssueTitle, ?string $socialIssueChildTitle, ?SocialIssue $previousSocialIssue, - ?SocialIssue $previousSocialIssueChild, + ?SocialIssue $previousSocialIssueChild ): array { if (null !== $previousSocialIssue && ($socialIssueTitle === $previousSocialIssue->getTitle())) { $return = [ From ce171ec7477d5af69a9b3256b49eefebbf55198d Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Mon, 6 Dec 2021 12:21:59 +0100 Subject: [PATCH 03/62] household-members-editor: lightly improve ux (TO CHECK) --- .../Resources/public/vuejs/HouseholdMembersEditor/App.vue | 7 ++++++- .../HouseholdMembersEditor/components/CurrentHousehold.vue | 2 +- .../public/vuejs/HouseholdMembersEditor/js/i18n.js | 1 + .../Resources/views/Household/members_editor.html.twig | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdMembersEditor/App.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdMembersEditor/App.vue index 52eac5ea6..5b098846b 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdMembersEditor/App.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdMembersEditor/App.vue @@ -15,7 +15,12 @@
    -
  • +
  • + +
  • +
  • diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdMembersEditor/components/CurrentHousehold.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdMembersEditor/components/CurrentHousehold.vue index 1f76c8a5b..15b8a4346 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdMembersEditor/components/CurrentHousehold.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdMembersEditor/components/CurrentHousehold.vue @@ -1,5 +1,5 @@ diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons/TypePerson.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons/TypePerson.vue index a6b4695f9..8bd4887cc 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons/TypePerson.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons/TypePerson.vue @@ -1,6 +1,5 @@ diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig b/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig index 3bd97579e..4f1e739a8 100644 --- a/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig +++ b/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig @@ -84,18 +84,15 @@ {{ _self.label(thirdparty, options) }} {% if thirdparty.kind == 'child' %} - - {{ 'thirdparty.child'|trans }} + {{ 'thirdparty.child'|trans }} {% elseif thirdparty.kind == 'company' %} - - {{ 'thirdparty.company'|trans }} + {{ 'thirdparty.company'|trans }} {% else %} - - {{ 'thirdparty.contact'|trans }} + {{ 'thirdparty.contact'|trans }} {% endif %} @@ -175,26 +172,33 @@ {% if options['showContacts'] and thirdparty.activeChildren|length > 0 %}
    - {{ 'thirdparty.Children'|trans }} : - {% for c in thirdparty.activeChildren %} - {% include '@ChillMain/OnTheFly/_insert_vue_onthefly.html.twig' with { - targetEntity: { name: 'thirdparty', id: c.id }, - action: 'show', - displayBadge: true, - buttonText: c|chill_entity_render_string - } %} - {% endfor %} +
    +
    +
    {{ 'thirdparty.Children'|trans ~ ': ' }}
    + {% for c in thirdparty.activeChildren %} + {% include '@ChillMain/OnTheFly/_insert_vue_onthefly.html.twig' with { + targetEntity: { name: 'thirdparty', id: c.id }, + action: 'show', + displayBadge: true, + buttonText: c|chill_entity_render_string + } %} + {% endfor %} +
    {% endif %} + {% if options['showParent'] and thirdparty.isChild %}
    - {{ 'thirdparty.Contact of'|trans }} : - {% include '@ChillMain/OnTheFly/_insert_vue_onthefly.html.twig' with { - targetEntity: { name: 'thirdparty', id: thirdparty.parent.id }, - action: 'show', - displayBadge: true, - buttonText: thirdparty.parent|chill_entity_render_string - } %} +
    +
    +
    {{ 'thirdparty.Contact of'|trans ~ ': ' }}
    + {% include '@ChillMain/OnTheFly/_insert_vue_onthefly.html.twig' with { + targetEntity: { name: 'thirdparty', id: thirdparty.parent.id }, + action: 'show', + displayBadge: true, + buttonText: thirdparty.parent|chill_entity_render_string + } %} +
    {% endif %} From 62b8b3e6b7d53007db6be0d67bf34f30f2933f9a Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Thu, 9 Dec 2021 16:17:25 +0100 Subject: [PATCH 13/62] add thirdparty comment in acccourse resources --- .../AccompanyingCourse/components/Resources/ResourceItem.vue | 4 +--- src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php | 1 + .../public/vuejs/_components/Entity/ThirdPartyRenderBox.vue | 3 +++ .../public/vuejs/_components/OnTheFly/ThirdParty.vue | 1 + .../Serializer/Normalizer/ThirdPartyNormalizer.php | 1 + 5 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Resources/ResourceItem.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Resources/ResourceItem.vue index 612d78a7b..e17555c6a 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Resources/ResourceItem.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Resources/ResourceItem.vue @@ -14,9 +14,6 @@ }">