From 43d6dc835f1d82589763c5538ea649b8dd59be33 Mon Sep 17 00:00:00 2001 From: nobohan Date: Mon, 19 Jul 2021 10:08:43 +0200 Subject: [PATCH] rdv: add thirdParty in concerned persons (WIP) --- .../ChillCalendarBundle/Form/CalendarType.php | 41 ++++++++++++++++++- .../Resources/public/vuejs/Calendar/i18n.js | 7 ---- .../Resources/public/vuejs/Calendar/store.js | 20 ++++----- .../Resources/views/Calendar/new.html.twig | 3 ++ 4 files changed, 53 insertions(+), 18 deletions(-) diff --git a/src/Bundle/ChillCalendarBundle/Form/CalendarType.php b/src/Bundle/ChillCalendarBundle/Form/CalendarType.php index 36388fa83..7500594ea 100644 --- a/src/Bundle/ChillCalendarBundle/Form/CalendarType.php +++ b/src/Bundle/ChillCalendarBundle/Form/CalendarType.php @@ -14,6 +14,7 @@ use Chill\CalendarBundle\Entity\Calendar; use Chill\CalendarBundle\Entity\CancelReason; use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\PersonBundle\Entity\Person; +use Chill\ThirdPartyBundle\Entity\ThirdParty; use Symfony\Component\Form\CallbackTransformer; use Symfony\Component\Form\Extension\Core\Type\HiddenType; @@ -81,7 +82,45 @@ class CalendarType extends AbstractType } )) ; - + + $builder->add('professionals', HiddenType::class); + $builder->get('professionals') + ->addModelTransformer(new CallbackTransformer( + function (iterable $thirdpartyAsIterable): string { + $thirdpartyIds = []; + foreach ($thirdpartyAsIterable as $value) { + $thirdpartyIds[] = $value->getId(); + } + return implode(',', $thirdpartyIds); + }, + function (?string $thirdpartyAsString): array { + return array_map( + fn(string $id): ?ThirdParty => $this->om->getRepository(ThirdParty::class)->findOneBy(['id' => (int) $id]), + explode(',', $thirdpartyAsString) + ); + } + )) + ; + + // $builder->add('users', HiddenType::class); + // $builder->get('users') + // ->addModelTransformer(new CallbackTransformer( + // function (iterable $usersAsIterable): string { + // $userIds = []; + // foreach ($usersAsIterable as $value) { + // $userIds[] = $value->getId(); + // } + // return implode(',', $userIds); + // }, + // function (?string $usersAsString): array { + // return array_map( + // fn(string $id): ?User => $this->om->getRepository(User::class)->findOneBy(['id' => (int) $id]), + // explode(',', $usersAsString) + // ); + // } + // )) + // ; + }/** * {@inheritdoc} diff --git a/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/Calendar/i18n.js b/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/Calendar/i18n.js index 3262a37a5..778072e61 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/Calendar/i18n.js +++ b/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/Calendar/i18n.js @@ -3,13 +3,6 @@ import { personMessages } from 'ChillPersonAssets/vuejs/_js/i18n' const appMessages = { fr: { activity: { - // - social_issues: "Problématiques sociales", - choose_other_social_issue: "Ajouter une autre problématique sociale...", - social_actions: "Actions d'accompagnement", - select_first_a_social_issue: "Sélectionnez d'abord une problématique sociale", - - // add_persons: "Ajouter des personnes concernées", bloc_persons: "Usagers", bloc_persons_associated: "Usagers du parcours", diff --git a/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/Calendar/store.js b/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/Calendar/store.js index 91b67aae3..2a7ce62f4 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/Calendar/store.js +++ b/src/Bundle/ChillCalendarBundle/Resources/public/vuejs/Calendar/store.js @@ -22,7 +22,9 @@ const removeIdFromValue = (string, id) => { const activity = { accompanyingPeriod: null, socialIssues: [], - persons: [] + persons: [], + professionals: [], + invites: [] }; // TODO: get this object from window.activity ? const store = createStore({ @@ -86,14 +88,12 @@ const store = createStore({ // ConcernedGroups addPersonsInvolved(state, payload) { //console.log('### mutation addPersonsInvolved', payload.result.type); - console.log(state) - console.log(payload) switch (payload.result.type) { case 'person': state.activity.persons.push(payload.result); break; case 'thirdparty': - state.activity.thirdParties.push(payload.result); + state.activity.professionals.push(payload.result); break; case 'user': state.activity.users.push(payload.result); @@ -107,7 +107,7 @@ const store = createStore({ state.activity.persons = state.activity.persons.filter(person => person !== payload); break; case 'thirdparty': - state.activity.thirdParties = state.activity.thirdParties.filter(thirdparty => thirdparty !== payload); + state.activity.professionals = state.activity.professionals.filter(thirdparty => thirdparty !== payload); break; case 'user': state.activity.users = state.activity.users.filter(user => user !== payload); @@ -138,18 +138,18 @@ const store = createStore({ commit('updateActionsSelected', payload); }, addPersonsInvolved({ commit }, payload) { - //console.log('### action addPersonsInvolved', payload.result.type); + console.log('### action addPersonsInvolved', payload.result.type); switch (payload.result.type) { case 'person': let aPersons = document.getElementById("chill_calendarbundle_calendar_persons"); aPersons.value = addIdToValue(aPersons.value, payload.result.id); break; case 'thirdparty': - let aThirdParties = document.getElementById("chill_calendarbundle_calendar_thirdParties"); + let aThirdParties = document.getElementById("chill_calendarbundle_calendar_professionals"); aThirdParties.value = addIdToValue(aThirdParties.value, payload.result.id); break; case 'user': - let aUsers = document.getElementById("chill_calendarbundle_calendar_users"); + let aUsers = document.getElementById("chill_calendarbundle_calendar_invites"); aUsers.value = addIdToValue(aUsers.value, payload.result.id); break; }; @@ -163,11 +163,11 @@ const store = createStore({ aPersons.value = removeIdFromValue(aPersons.value, payload.id); break; case 'thirdparty': - let aThirdParties = document.getElementById("chill_calendarbundle_calendar_thirdParties"); + let aThirdParties = document.getElementById("chill_calendarbundle_calendar_professionals"); aThirdParties.value = removeIdFromValue(aThirdParties.value, payload.id); break; case 'user': - let aUsers = document.getElementById("chill_calendarbundle_calendar_users"); + let aUsers = document.getElementById("chill_calendarbundle_calendar_invites"); aUsers.value = removeIdFromValue(aUsers.value, payload.id); break; }; diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/new.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/new.html.twig index 84811aaf4..84b3cc37e 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/new.html.twig +++ b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/new.html.twig @@ -12,6 +12,9 @@ {%- if form.persons is defined -%} {{ form_widget(form.persons) }} {% endif %} +{%- if form.professionals is defined -%} + {{ form_widget(form.professionals) }} +{% endif %} {%- if form.nonProfessionals is defined -%} {{ form_widget(form.nonProfessionals) }} {% endif %}