mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
rdv: add show calendar
This commit is contained in:
@@ -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
|
||||
{
|
||||
|
Reference in New Issue
Block a user