mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
rdv: add show calendar
This commit is contained in:
parent
227be0b482
commit
3c37802821
@ -199,213 +199,194 @@ class CalendarController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
// public function showAction(Request $request, $id): Response
|
||||
// {
|
||||
// $em = $this->getDoctrine()->getManager();
|
||||
/**
|
||||
* Show a calendar item
|
||||
* @Route("/{_locale}/calendar/{id}/show", name="chill_calendar_calendar_show")
|
||||
*/
|
||||
public function showAction(Request $request, $id): Response
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
// [$person, $accompanyingPeriod] = $this->getEntity($request);
|
||||
[$user, $accompanyingPeriod] = $this->getEntity($request);
|
||||
|
||||
// if ($accompanyingPeriod instanceof AccompanyingPeriod) {
|
||||
// $view = 'ChillCalendarBundle:Calendar:showAccompanyingCourse.html.twig';
|
||||
// } elseif ($person instanceof Person) {
|
||||
// $view = 'ChillCalendarBundle:Calendar:showPerson.html.twig';
|
||||
// }
|
||||
if ($accompanyingPeriod instanceof AccompanyingPeriod) {
|
||||
$view = 'ChillCalendarBundle:Calendar:showAccompanyingCourse.html.twig';
|
||||
}
|
||||
// elseif ($person instanceof Person) {
|
||||
// $view = 'ChillCalendarBundle:Calendar:showPerson.html.twig';
|
||||
// }
|
||||
|
||||
// $entity = $em->getRepository('ChillCalendarBundle:Calendar')->find($id);
|
||||
$entity = $em->getRepository('ChillCalendarBundle:Calendar')->find($id);
|
||||
|
||||
// if (!$entity) {
|
||||
// throw $this->createNotFoundException('Unable to find Calendar entity.');
|
||||
// }
|
||||
if (!$entity) {
|
||||
throw $this->createNotFoundException('Unable to find Calendar entity.');
|
||||
}
|
||||
|
||||
// if (null !== $accompanyingPeriod) {
|
||||
// $entity->personsAssociated = $entity->getPersonsAssociated();
|
||||
// $entity->personsNotAssociated = $entity->getPersonsNotAssociated();
|
||||
// }
|
||||
if (null !== $accompanyingPeriod) {
|
||||
$entity->personsAssociated = $entity->getPersonsAssociated();
|
||||
$entity->personsNotAssociated = $entity->getPersonsNotAssociated();
|
||||
}
|
||||
|
||||
// // TODO revoir le Voter de Activity pour tenir compte qu'une activité peut appartenir a une période
|
||||
// // $this->denyAccessUnlessGranted('CHILL_ACTIVITY_SEE', $entity);
|
||||
// $deleteForm = $this->createDeleteForm($id, $accompanyingPeriod);
|
||||
|
||||
// $deleteForm = $this->createDeleteForm($id, $person, $accompanyingPeriod);
|
||||
if ($view === null) {
|
||||
throw $this->createNotFoundException('Template not found');
|
||||
}
|
||||
|
||||
// // TODO
|
||||
// /*
|
||||
// $event = new PrivacyEvent($person, array(
|
||||
// 'element_class' => Activity::class,
|
||||
// 'element_id' => $entity->getId(),
|
||||
// 'action' => 'show'
|
||||
// ));
|
||||
// $this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
|
||||
// */
|
||||
return $this->render($view, array(
|
||||
//'person' => $person,
|
||||
'accompanyingCourse' => $accompanyingPeriod,
|
||||
'entity' => $entity,
|
||||
//'delete_form' => $deleteForm->createView(),
|
||||
));
|
||||
}
|
||||
|
||||
// if ($view === null) {
|
||||
// throw $this->createNotFoundException('Template not found');
|
||||
// }
|
||||
|
||||
// return $this->render($view, array(
|
||||
// 'person' => $person,
|
||||
// 'accompanyingCourse' => $accompanyingPeriod,
|
||||
// 'entity' => $entity,
|
||||
// 'delete_form' => $deleteForm->createView(),
|
||||
// ));
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Displays a form to edit an existing Activity entity.
|
||||
// *
|
||||
// */
|
||||
// public function editAction($id, Request $request): Response
|
||||
// {
|
||||
// $em = $this->getDoctrine()->getManager();
|
||||
/**
|
||||
* Edit a calendar item
|
||||
* @Route("/{_locale}/calendar/{id}/edit", name="chill_calendar_calendar_edit")
|
||||
*/
|
||||
public function editAction($id, Request $request): Response
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
// [$person, $accompanyingPeriod] = $this->getEntity($request);
|
||||
[$person, $accompanyingPeriod] = $this->getEntity($request);
|
||||
|
||||
// if ($accompanyingPeriod instanceof AccompanyingPeriod) {
|
||||
// $view = 'ChillCalendarBundle:Calendar:editAccompanyingCourse.html.twig';
|
||||
// } elseif ($person instanceof Person) {
|
||||
// $view = 'ChillCalendarBundle:Calendar:editPerson.html.twig';
|
||||
// }
|
||||
if ($accompanyingPeriod instanceof AccompanyingPeriod) {
|
||||
$view = 'ChillCalendarBundle:Calendar:editAccompanyingCourse.html.twig';
|
||||
}
|
||||
// elseif ($person instanceof Person) {
|
||||
// $view = 'ChillCalendarBundle:Calendar:editPerson.html.twig';
|
||||
// }
|
||||
|
||||
// $entity = $em->getRepository('ChillCalendarBundle:Calendar')->find($id);
|
||||
$entity = $em->getRepository('ChillCalendarBundle:Calendar')->find($id);
|
||||
|
||||
// if (!$entity) {
|
||||
// throw $this->createNotFoundException('Unable to find Calendar entity.');
|
||||
// }
|
||||
if (!$entity) {
|
||||
throw $this->createNotFoundException('Unable to find Calendar entity.');
|
||||
}
|
||||
|
||||
// // TODO
|
||||
// // $this->denyAccessUnlessGranted('CHILL_ACTIVITY_UPDATE', $entity);
|
||||
$form = $this->createForm(CalendarType::class, $entity, [
|
||||
'center' => $entity->getCenter(),
|
||||
'role' => new Role('CHILL_ACTIVITY_UPDATE'),
|
||||
'activityType' => $entity->getType(),
|
||||
'accompanyingPeriod' => $accompanyingPeriod,
|
||||
])->handleRequest($request);
|
||||
|
||||
// $form = $this->createForm(CalendarType::class, $entity, [
|
||||
// 'center' => $entity->getCenter(),
|
||||
// 'role' => new Role('CHILL_ACTIVITY_UPDATE'),
|
||||
// 'activityType' => $entity->getType(),
|
||||
// 'accompanyingPeriod' => $accompanyingPeriod,
|
||||
// ])->handleRequest($request);
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$em->persist($entity);
|
||||
$em->flush();
|
||||
|
||||
// if ($form->isSubmitted() && $form->isValid()) {
|
||||
// $em->persist($entity);
|
||||
// $em->flush();
|
||||
$this->addFlash('success', $this->get('translator')->trans('Success : activity updated!'));
|
||||
|
||||
// $this->addFlash('success', $this->get('translator')->trans('Success : activity updated!'));
|
||||
$params = $this->buildParamsToUrl($person, $accompanyingPeriod);
|
||||
$params['id'] = $id;
|
||||
return $this->redirectToRoute('chill_activity_activity_show', $params);
|
||||
}
|
||||
|
||||
// $params = $this->buildParamsToUrl($person, $accompanyingPeriod);
|
||||
// $params['id'] = $id;
|
||||
// return $this->redirectToRoute('chill_activity_activity_show', $params);
|
||||
// }
|
||||
$deleteForm = $this->createDeleteForm($id, $person, $accompanyingPeriod);
|
||||
|
||||
// $deleteForm = $this->createDeleteForm($id, $person, $accompanyingPeriod);
|
||||
if ($view === null) {
|
||||
throw $this->createNotFoundException('Template not found');
|
||||
}
|
||||
|
||||
// /*
|
||||
// * TODO
|
||||
// $event = new PrivacyEvent($person, array(
|
||||
// 'element_class' => Calendar::class,
|
||||
// 'element_id' => $entity->getId(),
|
||||
// 'action' => 'edit'
|
||||
// ));
|
||||
// $this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
|
||||
// */
|
||||
$activity_array = $this->serializer->normalize($entity, 'json', ['groups' => 'read']);
|
||||
|
||||
// if ($view === null) {
|
||||
// throw $this->createNotFoundException('Template not found');
|
||||
// }
|
||||
return $this->render($view, array(
|
||||
'entity' => $entity,
|
||||
'edit_form' => $form->createView(),
|
||||
'delete_form' => $deleteForm->createView(),
|
||||
'accompanyingCourse' => $accompanyingPeriod,
|
||||
'activity_json' => $activity_array
|
||||
));
|
||||
}
|
||||
|
||||
// $activity_array = $this->serializer->normalize($entity, 'json', ['groups' => 'read']);
|
||||
/**
|
||||
* Delete a calendar item
|
||||
* @Route("/{_locale}/calendar/{id}/delete", name="chill_calendar_calendar_delete")
|
||||
*/
|
||||
public function deleteAction(Request $request, $id)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
// return $this->render($view, array(
|
||||
// 'entity' => $entity,
|
||||
// 'edit_form' => $form->createView(),
|
||||
// 'delete_form' => $deleteForm->createView(),
|
||||
// 'person' => $person,
|
||||
// 'accompanyingCourse' => $accompanyingPeriod,
|
||||
// 'activity_json' => $activity_array
|
||||
// ));
|
||||
// }
|
||||
[$person, $accompanyingPeriod] = $this->getEntity($request);
|
||||
|
||||
// /**
|
||||
// * Deletes a Calendar entity.
|
||||
// *
|
||||
// */
|
||||
// public function deleteAction(Request $request, $id)
|
||||
// {
|
||||
// $em = $this->getDoctrine()->getManager();
|
||||
if ($accompanyingPeriod instanceof AccompanyingPeriod) {
|
||||
$view = 'ChillCalendarBundle:Calendar:confirm_deleteAccompanyingCourse.html.twig';
|
||||
} elseif ($person instanceof Person) {
|
||||
$view = 'ChillCalendarBundle:Calendar:confirm_deletePerson.html.twig';
|
||||
}
|
||||
|
||||
// [$person, $accompanyingPeriod] = $this->getEntity($request);
|
||||
/* @var $activity Calendar */
|
||||
$activity = $em->getRepository('ChillCalendarBundle:Calendar')->find($id);
|
||||
|
||||
// if ($accompanyingPeriod instanceof AccompanyingPeriod) {
|
||||
// $view = 'ChillCalendarBundle:Calendar:confirm_deleteAccompanyingCourse.html.twig';
|
||||
// } elseif ($person instanceof Person) {
|
||||
// $view = 'ChillCalendarBundle:Calendar:confirm_deletePerson.html.twig';
|
||||
// }
|
||||
if (!$activity) {
|
||||
throw $this->createNotFoundException('Unable to find Calendar entity.');
|
||||
}
|
||||
|
||||
// /* @var $activity Calendar */
|
||||
// $activity = $em->getRepository('ChillCalendarBundle:Calendar')->find($id);
|
||||
// TODO
|
||||
// $this->denyAccessUnlessGranted('CHILL_ACTIVITY_DELETE', $activity);
|
||||
|
||||
// if (!$activity) {
|
||||
// throw $this->createNotFoundException('Unable to find Calendar entity.');
|
||||
// }
|
||||
$form = $this->createDeleteForm($id, $person, $accompanyingPeriod);
|
||||
|
||||
// // TODO
|
||||
// // $this->denyAccessUnlessGranted('CHILL_ACTIVITY_DELETE', $activity);
|
||||
if ($request->getMethod() === Request::METHOD_DELETE) {
|
||||
$form->handleRequest($request);
|
||||
|
||||
// $form = $this->createDeleteForm($id, $person, $accompanyingPeriod);
|
||||
if ($form->isValid()) {
|
||||
|
||||
// if ($request->getMethod() === Request::METHOD_DELETE) {
|
||||
// $form->handleRequest($request);
|
||||
$this->logger->notice("An activity has been removed", array(
|
||||
'by_user' => $this->getUser()->getUsername(),
|
||||
'activity_id' => $activity->getId(),
|
||||
'person_id' => $activity->getPerson() ? $activity->getPerson()->getId() : null,
|
||||
'comment' => $activity->getComment()->getComment(),
|
||||
'scope_id' => $activity->getScope() ? $activity->getScope()->getId() : null,
|
||||
'reasons_ids' => $activity->getReasons()
|
||||
->map(function ($ar) { return $ar->getId(); })
|
||||
->toArray(),
|
||||
'type_id' => $activity->getType()->getId(),
|
||||
'duration' => $activity->getDurationTime() ? $activity->getDurationTime()->format('U') : null,
|
||||
'date' => $activity->getDate()->format('Y-m-d'),
|
||||
'attendee' => $activity->getAttendee()
|
||||
));
|
||||
|
||||
// if ($form->isValid()) {
|
||||
$em->remove($activity);
|
||||
$em->flush();
|
||||
|
||||
// $this->logger->notice("An activity has been removed", array(
|
||||
// 'by_user' => $this->getUser()->getUsername(),
|
||||
// 'activity_id' => $activity->getId(),
|
||||
// 'person_id' => $activity->getPerson() ? $activity->getPerson()->getId() : null,
|
||||
// 'comment' => $activity->getComment()->getComment(),
|
||||
// 'scope_id' => $activity->getScope() ? $activity->getScope()->getId() : null,
|
||||
// 'reasons_ids' => $activity->getReasons()
|
||||
// ->map(function ($ar) { return $ar->getId(); })
|
||||
// ->toArray(),
|
||||
// 'type_id' => $activity->getType()->getId(),
|
||||
// 'duration' => $activity->getDurationTime() ? $activity->getDurationTime()->format('U') : null,
|
||||
// 'date' => $activity->getDate()->format('Y-m-d'),
|
||||
// 'attendee' => $activity->getAttendee()
|
||||
// ));
|
||||
$this->addFlash('success', $this->get('translator')
|
||||
->trans("The activity has been successfully removed."));
|
||||
|
||||
// $em->remove($activity);
|
||||
// $em->flush();
|
||||
$params = $this->buildParamsToUrl($person, $accompanyingPeriod);
|
||||
return $this->redirectToRoute('chill_activity_activity_list', $params);
|
||||
}
|
||||
}
|
||||
|
||||
// $this->addFlash('success', $this->get('translator')
|
||||
// ->trans("The activity has been successfully removed."));
|
||||
if ($view === null) {
|
||||
throw $this->createNotFoundException('Template not found');
|
||||
}
|
||||
|
||||
// $params = $this->buildParamsToUrl($person, $accompanyingPeriod);
|
||||
// return $this->redirectToRoute('chill_activity_activity_list', $params);
|
||||
// }
|
||||
// }
|
||||
return $this->render($view, array(
|
||||
'activity' => $activity,
|
||||
'delete_form' => $form->createView(),
|
||||
'person' => $person,
|
||||
'accompanyingCourse' => $accompanyingPeriod,
|
||||
));
|
||||
}
|
||||
|
||||
// if ($view === null) {
|
||||
// throw $this->createNotFoundException('Template not found');
|
||||
// }
|
||||
/**
|
||||
* Creates a form to delete a Calendar entity by id.
|
||||
*/
|
||||
private function createDeleteForm(int $id, ?Person $person, ?AccompanyingPeriod $accompanyingPeriod): Form
|
||||
{
|
||||
$params = $this->buildParamsToUrl($person, $accompanyingPeriod);
|
||||
$params['id'] = $id;
|
||||
|
||||
// return $this->render($view, array(
|
||||
// 'activity' => $activity,
|
||||
// 'delete_form' => $form->createView(),
|
||||
// 'person' => $person,
|
||||
// 'accompanyingCourse' => $accompanyingPeriod,
|
||||
// ));
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Creates a form to delete a Calendar entity by id.
|
||||
// */
|
||||
// private function createDeleteForm(int $id, ?Person $person, ?AccompanyingPeriod $accompanyingPeriod): Form
|
||||
// {
|
||||
// $params = $this->buildParamsToUrl($person, $accompanyingPeriod);
|
||||
// $params['id'] = $id;
|
||||
|
||||
// return $this->createFormBuilder()
|
||||
// ->setAction($this->generateUrl('chill_activity_activity_delete', $params))
|
||||
// ->setMethod('DELETE')
|
||||
// ->add('submit', SubmitType::class, array('label' => 'Delete'))
|
||||
// ->getForm()
|
||||
// ;
|
||||
// }
|
||||
return $this->createFormBuilder()
|
||||
->setAction($this->generateUrl('chill_activity_activity_delete', $params))
|
||||
->setMethod('DELETE')
|
||||
->add('submit', SubmitType::class, array('label' => 'Delete'))
|
||||
->getForm()
|
||||
;
|
||||
}
|
||||
|
||||
private function getEntity(Request $request): array
|
||||
{
|
||||
|
@ -373,4 +373,32 @@ class Calendar
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPersonsAssociated(): array
|
||||
{
|
||||
if (null !== $this->accompanyingPeriod) {
|
||||
$personsAssociated = [];
|
||||
foreach ($this->accompanyingPeriod->getParticipations() as $participation) {
|
||||
if ($this->persons->contains($participation->getPerson())) {
|
||||
$personsAssociated[] = $participation->getPerson();
|
||||
}
|
||||
}
|
||||
return $personsAssociated;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getPersonsNotAssociated(): array
|
||||
{
|
||||
if (null !== $this->accompanyingPeriod) {
|
||||
$personsNotAssociated = [];
|
||||
foreach ($this->persons as $person) {
|
||||
if (!in_array($person, $this->getPersonsAssociated())) {
|
||||
$personsNotAssociated[] = $person;
|
||||
}
|
||||
}
|
||||
return $personsNotAssociated;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
@ -36,10 +36,6 @@
|
||||
|
||||
.. location
|
||||
|
||||
{%- if form.status is defined -%}
|
||||
{{ form_row(form.status) }}
|
||||
{% endif %}
|
||||
|
||||
{%- if form.cancelReason is defined -%}
|
||||
{{ form_row(form.cancelReason) }}
|
||||
{% endif %}
|
||||
|
@ -0,0 +1,75 @@
|
||||
<h1>{{ "Calendar"|trans }}</h1>
|
||||
|
||||
<dl class="chill_view_data">
|
||||
|
||||
</dl>
|
||||
|
||||
|
||||
<h2 class="chill-red">{{ 'Calendar data'|trans }}</h2>
|
||||
|
||||
<dt class="inline">{{ 'start date'|trans }}</dt>
|
||||
<dd>{{ entity.startDate|format_date('long') }}</dd>
|
||||
|
||||
<dt class="inline">{{ 'end date'|trans }}</dt>
|
||||
<dd>{{ entity.endDate|format_date('long') }}</dd>
|
||||
|
||||
<dt class="inline">{{ 'cancel reason'|trans }}</dt>
|
||||
<dd>
|
||||
{% if entity.cancelReason is not null %}
|
||||
{{ entity.cancelReason }}
|
||||
{% else %}
|
||||
<span class="chill-no-data-statement">{{ 'Unknown'|trans }}</span>
|
||||
{% endif %}
|
||||
</dd>
|
||||
|
||||
<dt class="inline">{{ 'status'|trans }}</dt>
|
||||
<dd>{{ entity.status }}</dd>
|
||||
|
||||
{% if not entity.comment.isEmpty %}
|
||||
<dt class="inline">{{ 'calendar comment'|trans }}</dt>
|
||||
<dd>{{ entity.comment|chill_entity_render_box }}</dd>
|
||||
{% endif %}
|
||||
|
||||
<dt class="inline">{{ 'sendSMS'|trans }}</dt>
|
||||
<dd>
|
||||
{% if entity.sendSMS is not null %}
|
||||
{% if entity.sendSMS %}Oui{% else %}Non{% endif %}
|
||||
{% else %}
|
||||
<span class="chill-no-data-statement">{{ 'Unknown'|trans }}</span>
|
||||
{% endif %}
|
||||
</dd>
|
||||
|
||||
|
||||
</dl>
|
||||
|
||||
{% set accompanying_course_id = null %}
|
||||
{% if accompanyingCourse %}
|
||||
{% set accompanying_course_id = accompanyingCourse.id %}
|
||||
{% endif %}
|
||||
|
||||
<ul class="record_actions sticky-form-buttons">
|
||||
<li class="cancel">
|
||||
<a class="btn btn-cancel" href="{{ path('chill_calendar_calendar', { 'accompanying_period_id': accompanying_course_id } ) }}">
|
||||
{{ 'Back to the list'|trans }}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="btn btn-update" href="{{ path('chill_calendar_calendar_edit', { 'id': entity.id, 'accompanying_period_id': accompanying_course_id }) }}">
|
||||
{{ 'Edit'|trans }}
|
||||
</a>
|
||||
</li>
|
||||
|
||||
{# TODO
|
||||
{% if is_granted('CHILL_ACTIVITY_DELETE', entity) %}
|
||||
#}
|
||||
|
||||
<li>
|
||||
<a href="{{ path('chill_calendar_calendar_delete', { 'id': entity.id, 'accompanying_period_id': accompanying_course_id } ) }}" class="btn btn-delete">
|
||||
{{ 'Delete'|trans }}
|
||||
</a>
|
||||
</li>
|
||||
|
||||
{#
|
||||
{% endif %}
|
||||
#}
|
||||
</ul>
|
@ -0,0 +1,15 @@
|
||||
{% extends "@ChillPerson/AccompanyingCourse/layout.html.twig" %}
|
||||
|
||||
{% set activeRouteKey = 'chill_calendar_calendar_list' %}
|
||||
|
||||
{% block title 'Calendar'|trans %}
|
||||
|
||||
{% block content -%}
|
||||
<div class="calendar-show">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-10 col-xxl">
|
||||
{% include 'ChillCalendarBundle:Calendar:show.html.twig' with {'context': 'accompanyingCourse'} %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
Loading…
x
Reference in New Issue
Block a user