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.dates'|trans }} | - {% if chill_accompanying_periods.fields.user == 'visible' %} -{{ 'Accompanying user'|trans }} | - {% endif %} -{{ '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 %}
-
|
- {% if chill_accompanying_periods.fields.user == 'visible' %}
-
- {% 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 %} - |
- {% endif %}
-
- {% if accompanying_period is not empty %}
- - {{ accompanying_period.remark|chill_markdown_to_html }} -- {% else %} - {{ null|chill_print_or_message('No remark', 'blockquote') }} - {% endif %} - |
- + + + - | -