diff --git a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php index 4495948fe..78f0bad7e 100644 --- a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php +++ b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php @@ -110,6 +110,34 @@ class AccompanyingCourseController extends Controller ]); } + /** + * Comments page of Accompanying Course section. + * + * @Route("/{_locale}/parcours/{accompanying_period_id}/comments", name="chill_person_accompanying_period_comment_list") + * @ParamConverter("accompanyingCourse", options={"id": "accompanying_period_id"}) + */ + public function commentAction(AccompanyingPeriod $accompanyingCourse, Request $request): Response + { + $comment = new AccompanyingPeriod\Comment(); + + $form = $this->createForm(AccompanyingCourseCommentType::class, $comment, []); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $em = $this->getDoctrine()->getManager(); + + $em->persist($comment); + $em->flush(); + + return $this->redirectToRoute($route); + } + + return $this->render('@ChillPerson/AccompanyingCourse/comment_list.html.twig', [ + 'accompanyingCourse' => $accompanyingCourse, + 'form' => $form->createView(), + ]); + } + /** * Edit page of Accompanying Course section. * @@ -217,35 +245,4 @@ class AccompanyingCourseController extends Controller 'accompanying_period_id' => $period->getId(), ]); } - - /** - * Comments page of Accompanying Course section. - * - * @Route("/{_locale}/parcours/{accompanying_period_id}/comments", name="chill_person_accompanying_period_comment_list") - * @ParamConverter("accompanyingCourse", options={"id": "accompanying_period_id"}) - */ - public function commentAction(AccompanyingPeriod $accompanyingCourse, Request $request): Response - { - - $comment = new AccompanyingPeriod\Comment(); - - $form = $this->createForm(AccompanyingCourseCommentType::class, $comment, []); - $form->handleRequest($request); - - if ($form->isSubmitted() && $form->isValid()) { - - $em = $this->getDoctrine()->getManager(); - - $em->persist($comment); - $em->flush(); - - return $this->redirectToRoute($route); - } - - return $this->render('@ChillPerson/AccompanyingCourse/comment_list.html.twig', [ - 'accompanyingCourse' => $accompanyingCourse, - 'form' => $form->createView() - ]); - } - } diff --git a/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadAccompanyingPeriodWork.php b/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadAccompanyingPeriodWork.php index 64c7d2701..d34c705ac 100644 --- a/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadAccompanyingPeriodWork.php +++ b/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadAccompanyingPeriodWork.php @@ -95,7 +95,7 @@ class LoadAccompanyingPeriodWork extends \Doctrine\Bundle\FixturesBundle\Fixture // 1 of 10, force an evaluation if (0 === $i % 10) { $evaluation = $this->getRandomEvaluation(); - $action = $evaluation->getSocialAction(); + $action = $evaluation->getSocialActions()->first(); $issue = $action->getIssue(); $period->addSocialIssue($issue); diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php index 9c13dcd2f..685010836 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php @@ -180,14 +180,6 @@ class AccompanyingPeriod implements */ private ?int $id = null; - /** - * @ORM\ManyToOne( - * targetEntity=Comment::class - * ) - * @Groups({"read"}) - */ - private ?Comment $pinnedComment = null; - /** * @var string * @ORM\Column(type="string", nullable=true) @@ -229,6 +221,14 @@ class AccompanyingPeriod implements */ private ?Person $personLocation = null; + /** + * @ORM\ManyToOne( + * targetEntity=Comment::class + * ) + * @Groups({"read"}) + */ + private ?Comment $pinnedComment = null; + /** * @ORM\Column(type="text") * @Groups({"read", "write"}) @@ -603,14 +603,6 @@ class AccompanyingPeriod implements return $this->id; } - /** - * @Groups({"read"}) - */ - public function getPinnedComment(): ?Comment - { - return $this->pinnedComment; - } - public function getIntensity(): ?string { return $this->intensity; @@ -738,6 +730,14 @@ class AccompanyingPeriod implements ); } + /** + * @Groups({"read"}) + */ + public function getPinnedComment(): ?Comment + { + return $this->pinnedComment; + } + /** * @return Collection|SocialAction[] All the descendant social actions of all * the descendants of the entity @@ -1027,24 +1027,6 @@ class AccompanyingPeriod implements return $this; } - /** - * @Groups({"write"}) - */ - public function setPinnedComment(?Comment $comment = null): self - { - if (null !== $this->pinnedComment) { - $this->removeComment($this->pinnedComment); - } - - if ($comment instanceof Comment) { - $this->addComment($comment); - } - - $this->pinnedComment = $comment; - - return $this; - } - public function setIntensity(string $intensity): self { $this->intensity = $intensity; @@ -1083,6 +1065,24 @@ class AccompanyingPeriod implements return $this; } + /** + * @Groups({"write"}) + */ + public function setPinnedComment(?Comment $comment = null): self + { + if (null !== $this->pinnedComment) { + $this->removeComment($this->pinnedComment); + } + + if ($comment instanceof Comment) { + $this->addComment($comment); + } + + $this->pinnedComment = $comment; + + return $this; + } + public function setRemark(?string $remark = null): self { $this->remark = (string) $remark; diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/Comment.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/Comment.php index 7be0eccd1..105633e43 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/Comment.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/Comment.php @@ -112,6 +112,11 @@ class Comment implements TrackCreationInterface, TrackUpdateInterface return $this->updatedBy; } + public function isPinned(): bool + { + return $this->getAccompanyingPeriod()->getPinnedComment() === $this; + } + public function setAccompanyingPeriod(?AccompanyingPeriod $accompanyingPeriod): self { $this->accompanyingPeriod = $accompanyingPeriod; @@ -158,9 +163,4 @@ class Comment implements TrackCreationInterface, TrackUpdateInterface return $this; } - - public function isPinned(): bool - { - return $this->getAccompanyingPeriod()->getPinnedComment() === $this; - } } diff --git a/src/Bundle/ChillPersonBundle/Entity/Person.php b/src/Bundle/ChillPersonBundle/Entity/Person.php index a3524d306..882be10ed 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person.php @@ -244,7 +244,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI * @Assert\Date( * groups={"general", "creation"} * ) - * @Assert\GreaterThan(propertyPath="birthDate") + * @Assert\GreaterThanOrEqual(propertyPath="birthdate") * @Assert\LessThanOrEqual("today") */ private ?DateTimeImmutable $deathdate = null; diff --git a/src/Bundle/ChillPersonBundle/Entity/SocialWork/Evaluation.php b/src/Bundle/ChillPersonBundle/Entity/SocialWork/Evaluation.php index 5ee08a15c..1350ae6d8 100644 --- a/src/Bundle/ChillPersonBundle/Entity/SocialWork/Evaluation.php +++ b/src/Bundle/ChillPersonBundle/Entity/SocialWork/Evaluation.php @@ -91,6 +91,11 @@ class Evaluation return $this->notificationDelay; } + public function getSocialActions(): Collection + { + return $this->socialActions; + } + public function getTitle(): array { return $this->title; diff --git a/src/Bundle/ChillPersonBundle/Form/AccompanyingCourseCommentType.php b/src/Bundle/ChillPersonBundle/Form/AccompanyingCourseCommentType.php index 5d580d325..b123a4c4d 100644 --- a/src/Bundle/ChillPersonBundle/Form/AccompanyingCourseCommentType.php +++ b/src/Bundle/ChillPersonBundle/Form/AccompanyingCourseCommentType.php @@ -1,4 +1,5 @@ $period->getId(), ], ]) ->setExtras(['order' => 50]); - */ + */ $workflow = $this->registry->get($period, 'accompanying_period_lifecycle'); diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkCreate/App.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkCreate/App.vue index 12d6716a4..2cbc0cdac 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkCreate/App.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkCreate/App.vue @@ -8,10 +8,10 @@

{{ $t('pick_social_issue_linked_with_action') }}

- {{ si.text }} + {{ si.text }}
-
+

{{ $t('pick_an_action') }}

-
+
{{ $t('form_has_errors') }}

    -
  • +
  • {{ e }}
@@ -120,6 +120,7 @@ const i18n = { endDate: "Date de fin", form_has_errors: "Le formulaire comporte des erreurs", pick_social_issue: "Choisir une problématique sociale", + pick_other_social_issue: "Veuillez choisir un autre problématique", pick_an_action: "Choisir une action d'accompagnement", pick_social_issue_linked_with_action: "Indiquez la problématique sociale liée à l'action d'accompagnement", persons_involved: "Usagers concernés", @@ -178,12 +179,10 @@ export default { personsPicked: { get() { let s = this.$store.state.personsPicked.map(p => p.id); - // console.log('persons picked', s); return s; }, set(v) { - // console.log('persons picked', v); this.$store.commit('setPersonsPickedIds', v); } }, @@ -226,6 +225,11 @@ export default { this.$store.commit('setEndDate', ISOToDate(value)); } }, + setSocialIssue: { + set() { + this.$store.dispatch('setSocialIssue', socialIssues[socialIssues.length - 1]) + } + } } } diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkCreate/store.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkCreate/store.js index 8633c003d..408115257 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkCreate/store.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkCreate/store.js @@ -31,7 +31,6 @@ const store = createStore({ return null !== state.socialActionPicked; }, hasSocialIssuePicked(state) { - console.log(state.socialIssuePicked); return null !== state.socialIssuePicked; }, isLoadingSocialActions(state) { @@ -74,36 +73,27 @@ const store = createStore({ }, mutations: { setSocialActionsReachables(state, actions) { - // console.log('set social action reachables'); - // console.log(actions); - state.socialActionsReachables = actions; }, setSocialAction(state, socialAction) { - // console.log('socialAction', socialAction); state.socialActionPicked = socialAction; }, setSocialIssue(state, socialIssueId) { - // console.log('set social issue', socialIssueId); if (socialIssueId === null) { state.socialIssuePicked = null; } else { let mapped = state.socialIssues .find(e => e.id === socialIssueId); state.socialIssuePicked = mapped; - // console.log('social issue setted', state.socialIssuePicked); } }, addIssueInList(state, issue) { - //console.log('add issue list', issue.id); state.socialIssues.push(issue); }, updateIssuesOther(state, payload) { - //console.log('update issues other'); state.socialIssuesOther = payload; }, removeIssueInOther(state, issue) { - //console.log('remove issue other', issue.id); state.socialIssuesOther = state.socialIssuesOther.filter( (i) => i.id !== issue.id ); @@ -124,12 +114,12 @@ const store = createStore({ state.endDate = date; }, setPersonsPickedIds(state, ids) { - console.log('persons ids', ids); + state.personsPicked = state.personsReachables .filter(p => ids.includes(p.id)) }, addErrors(state, { errors, cancel_posting }) { - console.log('add errors', errors); + state.errors = errors; if (cancel_posting) { state.isPostingWork = false; @@ -138,8 +128,6 @@ const store = createStore({ }, actions: { pickSocialIssue({ commit }, socialIssueId) { - console.log('pick social issue'); - commit('setIsLoadingSocialActions', true); commit('setSocialAction', null); commit('setSocialActionsReachables', []); diff --git a/src/Bundle/ChillPersonBundle/Tests/Entity/AccompanyingPeriodTest.php b/src/Bundle/ChillPersonBundle/Tests/Entity/AccompanyingPeriodTest.php index 0ecc886f8..a459c3c18 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Entity/AccompanyingPeriodTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Entity/AccompanyingPeriodTest.php @@ -60,32 +60,6 @@ final class AccompanyingPeriodTest extends \PHPUnit\Framework\TestCase $this->assertFalse($period->isClosingAfterOpening()); } - public function testPinnedComment() - { - $period = new AccompanyingPeriod(new DateTime()); - $comment = new Comment(); - $replacingComment = new Comment(); - - $period->setPinnedComment(null); - $this->assertNull($period->getPinnedComment()); - - $period->setPinnedComment($comment); - $this->assertSame($period->getPinnedComment(), $comment); - $this->assertSame($period, $comment->getAccompanyingPeriod()); - $this->assertEquals(0, count($period->getComments()), 'The initial comment should not appears in the list of comments'); - - $period->setPinnedComment($replacingComment); - $this->assertSame($period->getPinnedComment(), $replacingComment); - $this->assertSame($period, $replacingComment->getAccompanyingPeriod()); - $this->assertEquals(0, count($period->getComments()), 'The initial comment should not appears in the list of comments'); - $this->assertNull($comment->getAccompanyingPeriod()); - - $period->setPinnedComment(null); - $this->assertNull($period->getPinnedComment()); - $this->assertNull($replacingComment->getAccompanyingPeriod()); - $this->assertEquals(0, count($period->getComments()), 'The initial comment should not appears in the list of comments'); - } - public function testIsClosed() { $period = new AccompanyingPeriod(new DateTime()); @@ -145,6 +119,32 @@ final class AccompanyingPeriodTest extends \PHPUnit\Framework\TestCase $this->assertEquals(1, $period->getParticipationsContainsPerson($person4)->count()); } + public function testPinnedComment() + { + $period = new AccompanyingPeriod(new DateTime()); + $comment = new Comment(); + $replacingComment = new Comment(); + + $period->setPinnedComment(null); + $this->assertNull($period->getPinnedComment()); + + $period->setPinnedComment($comment); + $this->assertSame($period->getPinnedComment(), $comment); + $this->assertSame($period, $comment->getAccompanyingPeriod()); + $this->assertEquals(0, count($period->getComments()), 'The initial comment should not appears in the list of comments'); + + $period->setPinnedComment($replacingComment); + $this->assertSame($period->getPinnedComment(), $replacingComment); + $this->assertSame($period, $replacingComment->getAccompanyingPeriod()); + $this->assertEquals(0, count($period->getComments()), 'The initial comment should not appears in the list of comments'); + $this->assertNull($comment->getAccompanyingPeriod()); + + $period->setPinnedComment(null); + $this->assertNull($period->getPinnedComment()); + $this->assertNull($replacingComment->getAccompanyingPeriod()); + $this->assertEquals(0, count($period->getComments()), 'The initial comment should not appears in the list of comments'); + } + public function testRequestor() { $period = new AccompanyingPeriod(new DateTime()); diff --git a/src/Bundle/ChillPersonBundle/migrations/Version20211213150253.php b/src/Bundle/ChillPersonBundle/migrations/Version20211213150253.php index fc977165f..f02ad75b0 100644 --- a/src/Bundle/ChillPersonBundle/migrations/Version20211213150253.php +++ b/src/Bundle/ChillPersonBundle/migrations/Version20211213150253.php @@ -1,5 +1,12 @@ addSql('ALTER TABLE chill_person_accompanying_period DROP CONSTRAINT FK_E260A868B0804E90'); + $this->addSql('DROP INDEX IDX_E260A868B0804E90'); + $this->addSql('ALTER TABLE chill_person_accompanying_period RENAME COLUMN pinnedcomment_id TO initialcomment_id'); + $this->addSql('ALTER TABLE chill_person_accompanying_period ADD CONSTRAINT fk_e260a8683111d50b FOREIGN KEY (initialcomment_id) REFERENCES chill_person_accompanying_period_comment (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('CREATE INDEX idx_e260a8683111d50b ON chill_person_accompanying_period (initialcomment_id)'); + } + public function getDescription(): string { return 'rename initialComment attribute to pinnedComment'; @@ -26,13 +41,4 @@ final class Version20211213150253 extends AbstractMigration $this->addSql('ALTER TABLE chill_person_accompanying_period ADD CONSTRAINT FK_E260A868B0804E90 FOREIGN KEY (pinnedcomment_id) REFERENCES chill_person_accompanying_period_comment (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); $this->addSql('CREATE INDEX IDX_E260A868B0804E90 ON chill_person_accompanying_period (pinnedcomment_id)'); } - - public function down(Schema $schema): void - { - $this->addSql('ALTER TABLE chill_person_accompanying_period DROP CONSTRAINT FK_E260A868B0804E90'); - $this->addSql('DROP INDEX IDX_E260A868B0804E90'); - $this->addSql('ALTER TABLE chill_person_accompanying_period RENAME COLUMN pinnedcomment_id TO initialcomment_id'); - $this->addSql('ALTER TABLE chill_person_accompanying_period ADD CONSTRAINT fk_e260a8683111d50b FOREIGN KEY (initialcomment_id) REFERENCES chill_person_accompanying_period_comment (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('CREATE INDEX idx_e260a8683111d50b ON chill_person_accompanying_period (initialcomment_id)'); - } } diff --git a/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php b/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php index 2466f745c..06b0dddbc 100644 --- a/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php +++ b/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php @@ -219,7 +219,6 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface private ?string $telephone = null; /** - * @var array|null * @ORM\Column(name="types", type="json", nullable=true) */ private ?array $thirdPartyTypes = []; diff --git a/src/Bundle/ChillThirdPartyBundle/Tests/Serializer/Normalizer/ThirdPartyJsonDenormalizerTest.php b/src/Bundle/ChillThirdPartyBundle/Tests/Serializer/Normalizer/ThirdPartyJsonDenormalizerTest.php index 811b55136..611a0d7c7 100644 --- a/src/Bundle/ChillThirdPartyBundle/Tests/Serializer/Normalizer/ThirdPartyJsonDenormalizerTest.php +++ b/src/Bundle/ChillThirdPartyBundle/Tests/Serializer/Normalizer/ThirdPartyJsonDenormalizerTest.php @@ -1,13 +1,25 @@ normalizer->denormalize(json_decode($str, true), ThirdParty::class, 'json', [ - 'groups' => ['write'] + 'groups' => ['write'], ]); $this->assertInstanceOf(ThirdParty::class, $actual); @@ -39,5 +51,4 @@ class ThirdPartyJsonDenormalizerTest extends KernelTestCase $this->assertEquals('badaboum@email.com', $actual->getEmail()); $this->assertEquals(ThirdParty::KIND_CONTACT, $actual->getKind()); } - }