From b72d45d9dbff2c17d299788b14dbd8429bc01258 Mon Sep 17 00:00:00 2001 From: nobohan Date: Mon, 28 Jun 2021 13:50:31 +0200 Subject: [PATCH 01/15] accompanying period: hide activity entries from the menu if accompanyin period is DRAFT --- .../Menu/AccompanyingCourseMenuBuilder.php | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Menu/AccompanyingCourseMenuBuilder.php b/src/Bundle/ChillActivityBundle/Menu/AccompanyingCourseMenuBuilder.php index 71d465b6c..8906e736c 100644 --- a/src/Bundle/ChillActivityBundle/Menu/AccompanyingCourseMenuBuilder.php +++ b/src/Bundle/ChillActivityBundle/Menu/AccompanyingCourseMenuBuilder.php @@ -4,6 +4,7 @@ namespace Chill\ActivityBundle\Menu; use Chill\MainBundle\Routing\LocalMenuBuilderInterface; use Chill\MainBundle\Security\Authorization\AuthorizationHelper; +use Chill\PersonBundle\Entity\AccompanyingPeriod; use Knp\Menu\MenuItem; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Contracts\Translation\TranslatorInterface; @@ -34,21 +35,13 @@ class AccompanyingCourseMenuBuilder implements LocalMenuBuilderInterface { $period = $parameters['accompanyingCourse']; + if (AccompanyingPeriod::STEP_DRAFT !== $period->getStep()) { $menu->addChild($this->translator->trans('Activity list'), [ 'route' => 'chill_activity_activity_list', 'routeParameters' => [ 'accompanying_period_id' => $period->getId(), ]]) ->setExtras(['order' => 40]); - - $menu->addChild($this->translator->trans('Add a new activity'), [ - 'route' => 'chill_activity_activity_select_type', - 'routeParameters' => [ - 'accompanying_period_id' => $period->getId(), - ]]) - ->setExtras(['order' => 41]); - - - + } } } From bc6ba88acd6ad79b2ac319bc9c98ace03f2f4b1c Mon Sep 17 00:00:00 2001 From: nobohan Date: Mon, 28 Jun 2021 16:04:24 +0200 Subject: [PATCH 02/15] menu: fix code indentation --- .../Menu/AccompanyingCourseMenuBuilder.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Menu/AccompanyingCourseMenuBuilder.php b/src/Bundle/ChillActivityBundle/Menu/AccompanyingCourseMenuBuilder.php index 8906e736c..5935f630e 100644 --- a/src/Bundle/ChillActivityBundle/Menu/AccompanyingCourseMenuBuilder.php +++ b/src/Bundle/ChillActivityBundle/Menu/AccompanyingCourseMenuBuilder.php @@ -36,12 +36,12 @@ class AccompanyingCourseMenuBuilder implements LocalMenuBuilderInterface $period = $parameters['accompanyingCourse']; if (AccompanyingPeriod::STEP_DRAFT !== $period->getStep()) { - $menu->addChild($this->translator->trans('Activity list'), [ - 'route' => 'chill_activity_activity_list', - 'routeParameters' => [ - 'accompanying_period_id' => $period->getId(), - ]]) - ->setExtras(['order' => 40]); + $menu->addChild($this->translator->trans('Activity list'), [ + 'route' => 'chill_activity_activity_list', + 'routeParameters' => [ + 'accompanying_period_id' => $period->getId(), + ]]) + ->setExtras(['order' => 40]); } } } From f92d710a26d9568d5bf52170b1f34e61f0314362 Mon Sep 17 00:00:00 2001 From: nobohan Date: Mon, 28 Jun 2021 16:16:55 +0200 Subject: [PATCH 03/15] accompanying course summary: add social actions --- .../AccompanyingCourseController.php | 14 ++- .../views/AccompanyingCourse/index.html.twig | 94 ++++++++++++++++++- .../config/services/controller.yaml | 1 + 3 files changed, 107 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php index 82581641e..de67602b4 100644 --- a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php +++ b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php @@ -7,6 +7,7 @@ use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation; use Chill\PersonBundle\Privacy\AccompanyingPeriodPrivacyEvent; use Chill\PersonBundle\Entity\Person; +use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository; use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter; use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; use Symfony\Bundle\FrameworkBundle\Controller\Controller; @@ -35,14 +36,18 @@ class AccompanyingCourseController extends Controller protected ValidatorInterface $validator; + private AccompanyingPeriodWorkRepository $workRepository; + public function __construct( SerializerInterface $serializer, EventDispatcherInterface $dispatcher, - ValidatorInterface $validator + ValidatorInterface $validator, + AccompanyingPeriodWorkRepository $workRepository ) { $this->serializer = $serializer; $this->dispatcher = $dispatcher; $this->validator = $validator; + $this->workRepository = $workRepository; } /** @@ -102,9 +107,16 @@ class AccompanyingCourseController extends Controller ['date' => 'DESC'], ); + $works = $this->workRepository->findByAccompanyingPeriod( + $accompanyingCourse, + ['startDate' => 'DESC', 'endDate' => 'DESC'], + 3 + ); + return $this->render('@ChillPerson/AccompanyingCourse/index.html.twig', [ 'accompanyingCourse' => $accompanyingCourse, 'withoutHousehold' => $withoutHousehold, + 'works' => $works, 'activities' => $activities ]); } diff --git a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig index 364f8c7fd..09eee9351 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig @@ -222,11 +222,103 @@

{{ 'Social actions'|trans }}

- {% set person = null %} + {% for w in works %} +
+
+

+ {{ w.socialAction|chill_entity_render_box({ 'no-badge': false }) }} +

+
+ +
+
    +
  • +
    + {{ w.createdAt|format_date('long') }} +
    +
    + {{ 'accompanying_course_work.create_date'|trans }} +
    +
  • +
  • +
    + {{ w.startDate|format_date('long') }} +
    +
    + {{ 'accompanying_course_work.start_date'|trans }} +
    +
  • +
  • +
    + {{ w.endDate|format_date('long') }} +
    +
    + {{ 'accompanying_course_work.end_date'|trans }} +
    +
  • +
+
+ + {% if w.results|length > 0 %} +
+
+

{{ 'accompanying_course_work.goal'|trans }}

+

{{ 'accompanying_course_work.results without objective'|trans }}

+
+
+

{{ 'accompanying_course_work.results'|trans }}

+
    + {% for r in w.results %} +
  • {{ r.title|localize_translatable_string }}
  • + {% endfor %} +
+
+
+ {% endif %} + + {% if w.goals|length > 0 %} + {% for g in w.goals %} +
+
+

{{ 'accompanying_course_work.goal'|trans }}

+

{{ g.goal.title|localize_translatable_string }}

+
+
+ {% if g.results|length == 0 %} +

{{ 'accompanying_course_work.results'|trans }}

+

{{ 'accompanying_course_work.no_results'|trans }}

+ {% else %} +

{{ 'accompanying_course_work.results'|trans }}

+
    + {% for r in g.results %} +
  • {{ r.title|localize_translatable_string }}
  • + {% endfor %} +
+ {% endif %} +
+
+ {% endfor %} + {% endif %} + +
+ {{ 'Last updated by'|trans}}: {{ w.updatedBy|chill_entity_render_box }}, {{ w.updatedAt|format_datetime('long', 'short') }} +
+ +
+ {% endfor %} + + {% block contentActivity %} + {% set person = null %} {% include 'ChillActivityBundle:Activity:list.html.twig' with {'context': 'accompanyingCourse', 'context': 'person'} %} {% endblock %} {# ==> insert accompanyingCourse vue component #}
{% endblock %} + + +{% block css %} + {{ parent() }} + {{ encore_entry_link_tags('accompanying_course_work_list') }} +{% endblock %} diff --git a/src/Bundle/ChillPersonBundle/config/services/controller.yaml b/src/Bundle/ChillPersonBundle/config/services/controller.yaml index e7c34e78f..bad7e1745 100644 --- a/src/Bundle/ChillPersonBundle/config/services/controller.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/controller.yaml @@ -46,6 +46,7 @@ services: $serializer: '@Symfony\Component\Serializer\SerializerInterface' $dispatcher: '@Symfony\Contracts\EventDispatcher\EventDispatcherInterface' $validator: '@Symfony\Component\Validator\Validator\ValidatorInterface' + $workRepository: '@Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository' tags: ['controller.service_arguments'] Chill\PersonBundle\Controller\AccompanyingCourseApiController: From 4f49292178a4958168cc4631ac3e5b4f8217fba6 Mon Sep 17 00:00:00 2001 From: nobohan Date: Mon, 28 Jun 2021 17:18:57 +0200 Subject: [PATCH 04/15] address: fix saving of isNoAddress --- src/Bundle/ChillMainBundle/Entity/Address.php | 3 ++- .../Serializer/Normalizer/AddressNormalizer.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Entity/Address.php b/src/Bundle/ChillMainBundle/Entity/Address.php index af3fea746..f3973ff0f 100644 --- a/src/Bundle/ChillMainBundle/Entity/Address.php +++ b/src/Bundle/ChillMainBundle/Entity/Address.php @@ -132,6 +132,7 @@ class Address /** * True if the address is a "no address", aka homeless person, ... * @groups({"write"}) + * @ORM\Column(type="boolean") * * @var bool */ @@ -298,7 +299,7 @@ class Address * @param bool $isNoAddress * @return $this */ - public function setIsNoAddress(bool $isNoAddress) + public function setIsNoAddress(bool $isNoAddress): self { $this->isNoAddress = $isNoAddress; return $this; diff --git a/src/Bundle/ChillMainBundle/Serializer/Normalizer/AddressNormalizer.php b/src/Bundle/ChillMainBundle/Serializer/Normalizer/AddressNormalizer.php index 362ed7b26..e889f7f23 100644 --- a/src/Bundle/ChillMainBundle/Serializer/Normalizer/AddressNormalizer.php +++ b/src/Bundle/ChillMainBundle/Serializer/Normalizer/AddressNormalizer.php @@ -14,7 +14,7 @@ class AddressNormalizer implements NormalizerAwareInterface, NormalizerInterface public function normalize($address, string $format = null, array $context = []) { $data['address_id'] = $address->getId(); - $data['text'] = $address->getStreet().', '.$address->getStreetNumber(); + $data['text'] = $address->isNoAddress() ? '' : $address->getStreet().', '.$address->getStreetNumber(); $data['street'] = $address->getStreet(); $data['streetNumber'] = $address->getStreetNumber(); $data['postcode']['name'] = $address->getPostCode()->getName(); From 048161e300cf0bff6e3706617684364d9c3b800e Mon Sep 17 00:00:00 2001 From: nobohan Date: Mon, 28 Jun 2021 22:00:07 +0200 Subject: [PATCH 05/15] accompanying course summary (WIP) --- .../AccompanyingPeriodController.php | 68 ++++++----- .../views/AccompanyingPeriod/list.html.twig | 109 ++++++++++-------- .../translations/messages.fr.yml | 3 +- 3 files changed, 103 insertions(+), 77 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodController.php b/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodController.php index cff5bf909..c51152ffa 100644 --- a/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodController.php +++ b/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodController.php @@ -47,12 +47,12 @@ class AccompanyingPeriodController extends AbstractController * @var EventDispatcherInterface */ protected $eventDispatcher; - + /** * @var ValidatorInterface */ protected $validator; - + /** * AccompanyingPeriodController constructor. * @@ -64,23 +64,31 @@ class AccompanyingPeriodController extends AbstractController $this->eventDispatcher = $eventDispatcher; $this->validator = $validator; } - + public function listAction(int $person_id): Response { $person = $this->_getPerson($person_id); - + $event = new PrivacyEvent($person, [ 'element_class' => AccompanyingPeriod::class, 'action' => 'list' ]); $this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event); + $accompanyingPeriods = $person->getAccompanyingPeriodsOrdered(); + dump($accompanyingPeriods); + $participatingPersons = array(); + foreach ($accompanyingPeriods as $ap){ + $participatingPersons[] = ($ap->getOpenParticipationContainsPerson($person)); + } + return $this->render('ChillPersonBundle:AccompanyingPeriod:list.html.twig', [ - 'accompanying_periods' => $person->getAccompanyingPeriodsOrdered(), - 'person' => $person + 'accompanying_periods' => $accompanyingPeriods, + 'person' => $person, + 'participating_persons' => $participatingPersons ]); } - + public function createAction(int $person_id, Request $request): Response { $person = $this->_getPerson($person_id); @@ -90,17 +98,17 @@ class AccompanyingPeriodController extends AbstractController $accompanyingPeriod = new AccompanyingPeriod(new \DateTime('now')); $accompanyingPeriod->setClosingDate(new \DateTime('now')); - + $accompanyingPeriod->addPerson($person); //or $person->addAccompanyingPeriod($accompanyingPeriod); - + $form = $this->createForm( AccompanyingPeriodType::class, $accompanyingPeriod, [ 'period_action' => 'create', 'center' => $person->getCenter() ]); - + if ($request->getMethod() === 'POST') { $form->handleRequest($request); $errors = $this->_validatePerson($person); @@ -120,7 +128,7 @@ class AccompanyingPeriodController extends AbstractController $this->generateUrl('chill_person_accompanying_period_list', [ 'person_id' => $person->getId() ])); - + } else { $flashBag->add('error', $this->get('translator') ->trans('Error! Period not created!')); @@ -137,7 +145,7 @@ class AccompanyingPeriodController extends AbstractController 'accompanying_period' => $accompanyingPeriod ]); } - + /** * @throws Exception */ @@ -154,7 +162,7 @@ class AccompanyingPeriodController extends AbstractController /** @var Person $person */ $person = $this->_getPerson($person_id); - + // CHECK if (! $accompanyingPeriod->containsPerson($person)) { throw new Exception("Accompanying period " . $period_id . " does not contain person " . $person_id); @@ -176,7 +184,7 @@ class AccompanyingPeriodController extends AbstractController if ($form->isValid(['Default', 'closed']) && count($errors) === 0) { - + $em->flush(); $flashBag->add('success', @@ -186,9 +194,9 @@ class AccompanyingPeriodController extends AbstractController $this->generateUrl('chill_person_accompanying_period_list', [ 'person_id' => $person->getId() ])); - + } else { - + $flashBag->add('error', $this->get('translator') ->trans('Error when updating the period')); @@ -204,19 +212,19 @@ class AccompanyingPeriodController extends AbstractController 'accompanying_period' => $accompanyingPeriod ]); } - + /** * @throws \Exception */ public function closeAction(int $person_id, Request $request): Response { - + $person = $this->_getPerson($person_id); $this->denyAccessUnlessGranted(PersonVoter::UPDATE, $person, 'You are not allowed to update this person'); if ($person->isOpen() === false) { - + $this->get('session')->getFlashBag() ->add('error', $this->get('translator') ->trans('Beware period is closed', ['%name%' => $person->__toString()] @@ -229,7 +237,7 @@ class AccompanyingPeriodController extends AbstractController } $current = $person->getCurrentAccompanyingPeriod(); - + $form = $this->createForm(AccompanyingPeriodType::class, $current, [ 'period_action' => 'close', 'center' => $person->getCenter() @@ -256,7 +264,7 @@ class AccompanyingPeriodController extends AbstractController 'person_id' => $person->getId() ]) ); - + } else { $this->get('session')->getFlashBag() ->add('error', $this->get('translator') @@ -267,7 +275,7 @@ class AccompanyingPeriodController extends AbstractController ->add('info', $error->getMessage()); } } - + } else { //if form is not valid $this->get('session')->getFlashBag() ->add('error', @@ -288,7 +296,7 @@ class AccompanyingPeriodController extends AbstractController 'accompanying_period' => $current ]); } - + private function _validatePerson(Person $person): ConstraintViolationListInterface { $errors = $this->validator->validate($person, null, @@ -296,10 +304,10 @@ class AccompanyingPeriodController extends AbstractController // Can be disabled with config if (false === $this->container->getParameter('chill_person.allow_multiple_simultaneous_accompanying_periods')) { - + $errors_accompanying_period = $this->validator->validate($person, null, ['accompanying_period_consistent']); - + foreach($errors_accompanying_period as $error ) { $errors->add($error); } @@ -307,7 +315,7 @@ class AccompanyingPeriodController extends AbstractController return $errors; } - + public function openAction(int $person_id, Request $request): Response { $person = $this->_getPerson($person_id); @@ -384,7 +392,7 @@ class AccompanyingPeriodController extends AbstractController 'accompanying_period' => $accompanyingPeriod ]); } - + public function reOpenAction(int $person_id, int $period_id, Request $request): Response { /** @var Person $person */ @@ -392,7 +400,7 @@ class AccompanyingPeriodController extends AbstractController /* @var $period AccompanyingPeriod */ $period = \array_filter( - $person->getAccompanyingPeriods(), + $person->getAccompanyingPeriods(), function (AccompanyingPeriod $p) use ($period_id) { return $p->getId() === ($period_id); } @@ -417,13 +425,13 @@ class AccompanyingPeriodController extends AbstractController return $this->redirectToRoute('chill_person_accompanying_period_list', [ 'person_id' => $person->getId() ]); - + } elseif ($confirm === false && $period->canBeReOpened($person)) { return $this->render('ChillPersonBundle:AccompanyingPeriod:re_open.html.twig', [ 'period' => $period, 'person' => $person ]); - + } else { return (new Response()) ->setStatusCode(Response::HTTP_BAD_REQUEST) diff --git a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingPeriod/list.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingPeriod/list.html.twig index 05e4702aa..bf3392f6d 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingPeriod/list.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingPeriod/list.html.twig @@ -8,22 +8,28 @@

{{ 'Accompanying period list'|trans }}

- - - - - {% if chill_accompanying_periods.fields.user == 'visible' %} - - {% endif %} - - - - - - {% for accompanying_period in accompanying_periods %} - - - {% if chill_accompanying_periods.fields.user == 'visible' %} - - {% endif %} - - - - {% endfor %} - -
{{ 'accompanying_period.dates'|trans }}{{ 'Accompanying user'|trans }}{{ 'Remark'|trans }} 
+ {% for accompanying_period in accompanying_periods %} + +
+
+
+
+ {{'Accompanying period'|trans}} #{{ accompanying_period.id }} +
+ +
+ {% if chill_accompanying_periods.fields.user == 'visible' %} + {% if accompanying_period.user %} + {{ accompanying_period.user.username }} + {% else %} + {{ 'No accompanying user'|trans }} + {% endif %} + {% endif %} +
+ +
+
{% if accompanying_period.closingDate == null %} {{ 'accompanying_period.dates_from_%opening_date%'|trans({ '%opening_date%': accompanying_period.openingDate|format_date('long') } ) }} {% else %} @@ -32,36 +38,46 @@ '%closing_date%': accompanying_period.closingDate|format_date('long')} ) }} - {% if accompanying_period.isOpen == false %} -
-
{{ 'Closing motive'|trans }} :
-
{{ accompanying_period.closingMotive|chill_entity_render_box }}
-
- {% endif %} + {% if accompanying_period.isOpen == false %} +
+
{{ 'Closing motive'|trans }} :
+
{{ accompanying_period.closingMotive|chill_entity_render_box }}
+
+ {% endif %} {% endif %} -
- {% if accompanying_period.user %} - {{ accompanying_period.user.username }} + +
+ +

{{ 'Participants'|trans }}

+ {% if accompanying_period.participations.count > 0 %} + {% for p in accompanying_period.participations %} +

+ + {{ p.person.firstname ~ ' ' ~ p.person.lastname }} + +

+ {% endfor %} + {% else %} + {{ 'No data given'|trans }} + {% endif %} +
+
+

{{ 'Requestors'|trans }}

+ {% if accompanying_period.requestorPerson is not null or accompanying_period.requestorThirdParty is not null %} + {% if accompanying_period.requestorPerson is not null %} +

{{ accompanying_period.requestorPerson.firstname ~ ' ' ~ accompanying_period.requestorPerson.lastname }}

+ {% endif %} + {% if accompanying_period.requestorThirdParty is not null %} +

{{ accompanying_period.requestorThirdParty.firstname ~ ' ' ~ accompanying_period.requestorThirdParty.lastname }}

+ {% endif %} {% else %} - {{ 'No accompanying user'|trans }} + {{ 'No data given'|trans }} {% endif %} -
- {% if accompanying_period is not empty %} -
- {{ accompanying_period.remark|chill_markdown_to_html }} -
- {% else %} - {{ null|chill_print_or_message('No remark', 'blockquote') }} - {% endif %} -
+ + +
    - {# TODO if enable_accompanying_course_with_multiple_persons is true ... #}
  • @@ -85,14 +101,15 @@
  • {% endif %}
+
-
+ + +

+ {% endfor %} -
+ +