accompanying course summary (WIP)

This commit is contained in:
nobohan 2021-06-28 22:00:07 +02:00
parent 4f49292178
commit 048161e300
3 changed files with 103 additions and 77 deletions

View File

@ -47,12 +47,12 @@ class AccompanyingPeriodController extends AbstractController
* @var EventDispatcherInterface * @var EventDispatcherInterface
*/ */
protected $eventDispatcher; protected $eventDispatcher;
/** /**
* @var ValidatorInterface * @var ValidatorInterface
*/ */
protected $validator; protected $validator;
/** /**
* AccompanyingPeriodController constructor. * AccompanyingPeriodController constructor.
* *
@ -64,23 +64,31 @@ class AccompanyingPeriodController extends AbstractController
$this->eventDispatcher = $eventDispatcher; $this->eventDispatcher = $eventDispatcher;
$this->validator = $validator; $this->validator = $validator;
} }
public function listAction(int $person_id): Response public function listAction(int $person_id): Response
{ {
$person = $this->_getPerson($person_id); $person = $this->_getPerson($person_id);
$event = new PrivacyEvent($person, [ $event = new PrivacyEvent($person, [
'element_class' => AccompanyingPeriod::class, 'element_class' => AccompanyingPeriod::class,
'action' => 'list' 'action' => 'list'
]); ]);
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event); $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', [ return $this->render('ChillPersonBundle:AccompanyingPeriod:list.html.twig', [
'accompanying_periods' => $person->getAccompanyingPeriodsOrdered(), 'accompanying_periods' => $accompanyingPeriods,
'person' => $person 'person' => $person,
'participating_persons' => $participatingPersons
]); ]);
} }
public function createAction(int $person_id, Request $request): Response public function createAction(int $person_id, Request $request): Response
{ {
$person = $this->_getPerson($person_id); $person = $this->_getPerson($person_id);
@ -90,17 +98,17 @@ class AccompanyingPeriodController extends AbstractController
$accompanyingPeriod = new AccompanyingPeriod(new \DateTime('now')); $accompanyingPeriod = new AccompanyingPeriod(new \DateTime('now'));
$accompanyingPeriod->setClosingDate(new \DateTime('now')); $accompanyingPeriod->setClosingDate(new \DateTime('now'));
$accompanyingPeriod->addPerson($person); $accompanyingPeriod->addPerson($person);
//or $person->addAccompanyingPeriod($accompanyingPeriod); //or $person->addAccompanyingPeriod($accompanyingPeriod);
$form = $this->createForm( $form = $this->createForm(
AccompanyingPeriodType::class, AccompanyingPeriodType::class,
$accompanyingPeriod, [ $accompanyingPeriod, [
'period_action' => 'create', 'period_action' => 'create',
'center' => $person->getCenter() 'center' => $person->getCenter()
]); ]);
if ($request->getMethod() === 'POST') { if ($request->getMethod() === 'POST') {
$form->handleRequest($request); $form->handleRequest($request);
$errors = $this->_validatePerson($person); $errors = $this->_validatePerson($person);
@ -120,7 +128,7 @@ class AccompanyingPeriodController extends AbstractController
$this->generateUrl('chill_person_accompanying_period_list', [ $this->generateUrl('chill_person_accompanying_period_list', [
'person_id' => $person->getId() 'person_id' => $person->getId()
])); ]));
} else { } else {
$flashBag->add('error', $this->get('translator') $flashBag->add('error', $this->get('translator')
->trans('Error! Period not created!')); ->trans('Error! Period not created!'));
@ -137,7 +145,7 @@ class AccompanyingPeriodController extends AbstractController
'accompanying_period' => $accompanyingPeriod 'accompanying_period' => $accompanyingPeriod
]); ]);
} }
/** /**
* @throws Exception * @throws Exception
*/ */
@ -154,7 +162,7 @@ class AccompanyingPeriodController extends AbstractController
/** @var Person $person */ /** @var Person $person */
$person = $this->_getPerson($person_id); $person = $this->_getPerson($person_id);
// CHECK // CHECK
if (! $accompanyingPeriod->containsPerson($person)) { if (! $accompanyingPeriod->containsPerson($person)) {
throw new Exception("Accompanying period " . $period_id . " does not contain person " . $person_id); 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']) if ($form->isValid(['Default', 'closed'])
&& count($errors) === 0) { && count($errors) === 0) {
$em->flush(); $em->flush();
$flashBag->add('success', $flashBag->add('success',
@ -186,9 +194,9 @@ class AccompanyingPeriodController extends AbstractController
$this->generateUrl('chill_person_accompanying_period_list', [ $this->generateUrl('chill_person_accompanying_period_list', [
'person_id' => $person->getId() 'person_id' => $person->getId()
])); ]));
} else { } else {
$flashBag->add('error', $this->get('translator') $flashBag->add('error', $this->get('translator')
->trans('Error when updating the period')); ->trans('Error when updating the period'));
@ -204,19 +212,19 @@ class AccompanyingPeriodController extends AbstractController
'accompanying_period' => $accompanyingPeriod 'accompanying_period' => $accompanyingPeriod
]); ]);
} }
/** /**
* @throws \Exception * @throws \Exception
*/ */
public function closeAction(int $person_id, Request $request): Response public function closeAction(int $person_id, Request $request): Response
{ {
$person = $this->_getPerson($person_id); $person = $this->_getPerson($person_id);
$this->denyAccessUnlessGranted(PersonVoter::UPDATE, $person, 'You are not allowed to update this person'); $this->denyAccessUnlessGranted(PersonVoter::UPDATE, $person, 'You are not allowed to update this person');
if ($person->isOpen() === false) { if ($person->isOpen() === false) {
$this->get('session')->getFlashBag() $this->get('session')->getFlashBag()
->add('error', $this->get('translator') ->add('error', $this->get('translator')
->trans('Beware period is closed', ['%name%' => $person->__toString()] ->trans('Beware period is closed', ['%name%' => $person->__toString()]
@ -229,7 +237,7 @@ class AccompanyingPeriodController extends AbstractController
} }
$current = $person->getCurrentAccompanyingPeriod(); $current = $person->getCurrentAccompanyingPeriod();
$form = $this->createForm(AccompanyingPeriodType::class, $current, [ $form = $this->createForm(AccompanyingPeriodType::class, $current, [
'period_action' => 'close', 'period_action' => 'close',
'center' => $person->getCenter() 'center' => $person->getCenter()
@ -256,7 +264,7 @@ class AccompanyingPeriodController extends AbstractController
'person_id' => $person->getId() 'person_id' => $person->getId()
]) ])
); );
} else { } else {
$this->get('session')->getFlashBag() $this->get('session')->getFlashBag()
->add('error', $this->get('translator') ->add('error', $this->get('translator')
@ -267,7 +275,7 @@ class AccompanyingPeriodController extends AbstractController
->add('info', $error->getMessage()); ->add('info', $error->getMessage());
} }
} }
} else { //if form is not valid } else { //if form is not valid
$this->get('session')->getFlashBag() $this->get('session')->getFlashBag()
->add('error', ->add('error',
@ -288,7 +296,7 @@ class AccompanyingPeriodController extends AbstractController
'accompanying_period' => $current 'accompanying_period' => $current
]); ]);
} }
private function _validatePerson(Person $person): ConstraintViolationListInterface private function _validatePerson(Person $person): ConstraintViolationListInterface
{ {
$errors = $this->validator->validate($person, null, $errors = $this->validator->validate($person, null,
@ -296,10 +304,10 @@ class AccompanyingPeriodController extends AbstractController
// Can be disabled with config // Can be disabled with config
if (false === $this->container->getParameter('chill_person.allow_multiple_simultaneous_accompanying_periods')) { if (false === $this->container->getParameter('chill_person.allow_multiple_simultaneous_accompanying_periods')) {
$errors_accompanying_period = $this->validator->validate($person, null, $errors_accompanying_period = $this->validator->validate($person, null,
['accompanying_period_consistent']); ['accompanying_period_consistent']);
foreach($errors_accompanying_period as $error ) { foreach($errors_accompanying_period as $error ) {
$errors->add($error); $errors->add($error);
} }
@ -307,7 +315,7 @@ class AccompanyingPeriodController extends AbstractController
return $errors; return $errors;
} }
public function openAction(int $person_id, Request $request): Response public function openAction(int $person_id, Request $request): Response
{ {
$person = $this->_getPerson($person_id); $person = $this->_getPerson($person_id);
@ -384,7 +392,7 @@ class AccompanyingPeriodController extends AbstractController
'accompanying_period' => $accompanyingPeriod 'accompanying_period' => $accompanyingPeriod
]); ]);
} }
public function reOpenAction(int $person_id, int $period_id, Request $request): Response public function reOpenAction(int $person_id, int $period_id, Request $request): Response
{ {
/** @var Person $person */ /** @var Person $person */
@ -392,7 +400,7 @@ class AccompanyingPeriodController extends AbstractController
/* @var $period AccompanyingPeriod */ /* @var $period AccompanyingPeriod */
$period = \array_filter( $period = \array_filter(
$person->getAccompanyingPeriods(), $person->getAccompanyingPeriods(),
function (AccompanyingPeriod $p) use ($period_id) { function (AccompanyingPeriod $p) use ($period_id) {
return $p->getId() === ($period_id); return $p->getId() === ($period_id);
} }
@ -417,13 +425,13 @@ class AccompanyingPeriodController extends AbstractController
return $this->redirectToRoute('chill_person_accompanying_period_list', [ return $this->redirectToRoute('chill_person_accompanying_period_list', [
'person_id' => $person->getId() 'person_id' => $person->getId()
]); ]);
} elseif ($confirm === false && $period->canBeReOpened($person)) { } elseif ($confirm === false && $period->canBeReOpened($person)) {
return $this->render('ChillPersonBundle:AccompanyingPeriod:re_open.html.twig', [ return $this->render('ChillPersonBundle:AccompanyingPeriod:re_open.html.twig', [
'period' => $period, 'period' => $period,
'person' => $person 'person' => $person
]); ]);
} else { } else {
return (new Response()) return (new Response())
->setStatusCode(Response::HTTP_BAD_REQUEST) ->setStatusCode(Response::HTTP_BAD_REQUEST)

View File

@ -8,22 +8,28 @@
<h1>{{ 'Accompanying period list'|trans }}</h1> <h1>{{ 'Accompanying period list'|trans }}</h1>
<table class="rounded">
<thead>
<tr>
<th class="chill-red">{{ 'accompanying_period.dates'|trans }}</th>
{% if chill_accompanying_periods.fields.user == 'visible' %}
<th class="chill-blue">{{ 'Accompanying user'|trans }}</th>
{% endif %}
<th class="chill-orange">{{ 'Remark'|trans }}</th>
<th>&nbsp;</th>
</tr>
</thead> {% for accompanying_period in accompanying_periods %}
<tbody>
{% for accompanying_period in accompanying_periods %} <div class="flex-table">
<tr> <div class="item-bloc">
<td> <div class="item-row">
<div class="item-col">
{{'Accompanying period'|trans}} #{{ accompanying_period.id }}
</div>
<div class="item-col">
{% if chill_accompanying_periods.fields.user == 'visible' %}
{% if accompanying_period.user %}
{{ accompanying_period.user.username }}
{% else %}
<span class="chill-no-data-statement">{{ 'No accompanying user'|trans }}</span>
{% endif %}
{% endif %}
</div>
</div>
<div class="item-row">
{% if accompanying_period.closingDate == null %} {% if accompanying_period.closingDate == null %}
{{ 'accompanying_period.dates_from_%opening_date%'|trans({ '%opening_date%': accompanying_period.openingDate|format_date('long') } ) }} {{ 'accompanying_period.dates_from_%opening_date%'|trans({ '%opening_date%': accompanying_period.openingDate|format_date('long') } ) }}
{% else %} {% else %}
@ -32,36 +38,46 @@
'%closing_date%': accompanying_period.closingDate|format_date('long')} '%closing_date%': accompanying_period.closingDate|format_date('long')}
) }} ) }}
{% if accompanying_period.isOpen == false %} {% if accompanying_period.isOpen == false %}
<dl class="chill_view_data"> <dl class="chill_view_data">
<dt>{{ 'Closing motive'|trans }}&nbsp;:</dt> <dt>{{ 'Closing motive'|trans }}&nbsp;:</dt>
<dd>{{ accompanying_period.closingMotive|chill_entity_render_box }}</dd> <dd>{{ accompanying_period.closingMotive|chill_entity_render_box }}</dd>
</dl> </dl>
{% endif %} {% endif %}
{% endif %} {% endif %}
</td> </div>
{% if chill_accompanying_periods.fields.user == 'visible' %} <div class="item-row">
<td>
{% if accompanying_period.user %} <h3>{{ 'Participants'|trans }}</h3>
{{ accompanying_period.user.username }} {% if accompanying_period.participations.count > 0 %}
{% for p in accompanying_period.participations %}
<p>
<a href="{{ path('chill_person_accompanying_period_list', { person_id: p.person.id }) }}">
{{ p.person.firstname ~ ' ' ~ p.person.lastname }}
</a>
</p>
{% endfor %}
{% else %}
<span class="chill-no-data-statement">{{ 'No data given'|trans }}</span>
{% endif %}
</div>
<div class="item-col">
<h3>{{ 'Requestors'|trans }}</h3>
{% if accompanying_period.requestorPerson is not null or accompanying_period.requestorThirdParty is not null %}
{% if accompanying_period.requestorPerson is not null %}
<p>{{ accompanying_period.requestorPerson.firstname ~ ' ' ~ accompanying_period.requestorPerson.lastname }}</p>
{% endif %}
{% if accompanying_period.requestorThirdParty is not null %}
<p>{{ accompanying_period.requestorThirdParty.firstname ~ ' ' ~ accompanying_period.requestorThirdParty.lastname }}</p>
{% endif %}
{% else %} {% else %}
<span class="chill-no-data-statement">{{ 'No accompanying user'|trans }}</span> <span class="chill-no-data-statement">{{ 'No data given'|trans }}</span>
{% endif %} {% endif %}
</td> </div>
{% endif %}
<td> <div class="item-row">
{% if accompanying_period is not empty %}
<blockquote class="chill-user-quote">
{{ accompanying_period.remark|chill_markdown_to_html }}
</blockquote>
{% else %}
{{ null|chill_print_or_message('No remark', 'blockquote') }}
{% endif %}
</td>
<td>
<ul class="record_actions"> <ul class="record_actions">
{# TODO if enable_accompanying_course_with_multiple_persons is true ... #} {# TODO if enable_accompanying_course_with_multiple_persons is true ... #}
<li> <li>
<a href="{{ path('chill_person_accompanying_course_index', { 'accompanying_period_id': accompanying_period.id }) }}" class="sc-button bt-show"></a> <a href="{{ path('chill_person_accompanying_course_index', { 'accompanying_period_id': accompanying_period.id }) }}" class="sc-button bt-show"></a>
@ -85,14 +101,15 @@
</li> </li>
{% endif %} {% endif %}
</ul> </ul>
</div>
</td> </div>
</tr> </div>
{% endfor %} <p></p>
</tbody> {% endfor %}
</table>
<div class="form_control">
<div class="form_control">
<ul class="record_actions"> <ul class="record_actions">
<li class="cancel"> <li class="cancel">
<a href="{{ path ('chill_person_view', {'person_id' : person.id } ) }}" class="sc-button bt-cancel"> <a href="{{ path ('chill_person_view', {'person_id' : person.id } ) }}" class="sc-button bt-cancel">

View File

@ -165,6 +165,7 @@ An accompanying period starts: Une période d'accompagnement est ouverte
Any accompanying periods are open: Aucune période d'accompagnement ouverte Any accompanying periods are open: Aucune période d'accompagnement ouverte
An accompanying period is open: Une période d'accompagnement est ouverte An accompanying period is open: Une période d'accompagnement est ouverte
Accompanying period list: Périodes d'accompagnement Accompanying period list: Périodes d'accompagnement
Accompanying period: Période d'accompagnement
New accompanying course: Nouveau parcours d'accompagnement New accompanying course: Nouveau parcours d'accompagnement
Choose a motive: Motif de fermeture Choose a motive: Motif de fermeture
Re-open accompanying period: Ré-ouvrir Re-open accompanying period: Ré-ouvrir
@ -353,4 +354,4 @@ accompanying_course_work:
no_results: Aucun résultat - orientation no_results: Aucun résultat - orientation
results: Résultats - orientations results: Résultats - orientations
goal: Objectif - motif - dispositif goal: Objectif - motif - dispositif