rdv: add new rdv form

This commit is contained in:
nobohan
2021-07-16 12:57:11 +02:00
parent b01eba2533
commit 114df16e0f
8 changed files with 200 additions and 47 deletions

View File

@@ -156,17 +156,6 @@ class CalendarController extends AbstractController
// $view = 'ChillCalendarBundle:Calendar:newUser.html.twig';
// }
// $activityType_id = $request->get('activityType_id', 0);
// $activityType = $em->getRepository(\Chill\ActivityBundle\Entity\ActivityType::class)
// ->find($activityType_id);
// if (!$activityType instanceof \Chill\ActivityBundle\Entity\ActivityType ||
// !$activityType->isActive()) {
// $params = $this->buildParamsToUrl($user, $accompanyingPeriod);
// return $this->redirectToRoute('chill_activity_activity_select_type', $params);
// }
$entity = new Calendar();
$entity->setUser($this->getUser());
@@ -181,28 +170,25 @@ class CalendarController extends AbstractController
// $entity->setType($activityType);
// $entity->setDate(new \DateTime('now'));
// $form = $this->createForm(ActivityType::class, $entity, [
// 'center' => $entity->getCenter(),
// 'role' => new Role('CHILL_ACTIVITY_CREATE'),
// 'activityType' => $entity->getType(),
// 'accompanyingPeriod' => $accompanyingPeriod,
// ])->handleRequest($request);
$form = $this->createForm(CalendarType::class, $entity, [
'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 created!'));
$this->addFlash('success', $this->get('translator')->trans('Success : calendar item created!'));
// $params = $this->buildParamsToUrl($person, $accompanyingPeriod);
// $params['id'] = $entity->getId();
$params = $this->buildParamsToUrl($user, $accompanyingPeriod); //TODO useful?
$params['id'] = $entity->getId();
// return $this->redirectToRoute('chill_activity_activity_show', $params);
// }
return $this->redirectToRoute('chill_calendar_calendar_show', $params);
}
// if ($view === null) {
// throw $this->createNotFoundException('Template not found');
// }
if ($view === null) {
throw $this->createNotFoundException('Template not found');
}
// $activity_array = $this->serializer->normalize($entity, 'json', ['groups' => 'read']);
@@ -210,7 +196,7 @@ class CalendarController extends AbstractController
'user' => $user,
'accompanyingCourse' => $accompanyingPeriod,
'entity' => $entity,
// 'form' => $form->createView(),
'form' => $form->createView(),
//'activity_json' => $calendar_array
]);
}
@@ -456,20 +442,20 @@ class CalendarController extends AbstractController
];
}
// private function buildParamsToUrl(
// ?Person $person,
// ?AccompanyingPeriod $accompanyingPeriod
// ): array {
// $params = [];
private function buildParamsToUrl(
?User $user,
?AccompanyingPeriod $accompanyingPeriod
): array {
$params = [];
// if ($person) {
// $params['person_id'] = $person->getId();
// }
if ($user) {
$params['user_id'] = $user->getId();
}
// if ($accompanyingPeriod) {
// $params['accompanying_period_id'] = $accompanyingPeriod->getId();
// }
if ($accompanyingPeriod) {
$params['accompanying_period_id'] = $accompanyingPeriod->getId();
}
// return $params;
// }
return $params;
}
}