From e3040f4bfb1f4dae6c23e316c789f586cb99d7f0 Mon Sep 17 00:00:00 2001 From: nobohan Date: Tue, 23 Nov 2021 09:26:38 +0100 Subject: [PATCH] correct deprecated activity method --- .../Controller/ActivityController.php | 80 +++++++++++++++++-- 1 file changed, 74 insertions(+), 6 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php index 17eae166e..989ce518e 100644 --- a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php +++ b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php @@ -384,8 +384,8 @@ final class ActivityController extends AbstractController $form = $this->createForm(ActivityType::class, $entity, [ 'center' => $entity->getCenter(), - 'role' => new Role('CHILL_ACTIVITY_CREATE'), - 'activityType' => $entity->getType(), + 'role' => new Role('CHILL_ACTIVITY_CREATE'), + 'activityType' => $entity->getActivityType(), 'accompanyingPeriod' => $accompanyingPeriod, ])->handleRequest($request); @@ -482,10 +482,26 @@ final class ActivityController extends AbstractController throw $this->createNotFoundException('Unable to find Activity entity.'); } - if (null !== $accompanyingPeriod) { - // @TODO: Properties created dynamically. - $entity->personsAssociated = $entity->getPersonsAssociated(); - $entity->personsNotAssociated = $entity->getPersonsNotAssociated(); + // TODO + // $this->denyAccessUnlessGranted('CHILL_ACTIVITY_UPDATE', $entity); + + $form = $this->createForm(ActivityType::class, $entity, [ + 'center' => $entity->getCenter(), + 'role' => new Role('CHILL_ACTIVITY_UPDATE'), + 'activityType' => $entity->getActivityType(), + 'accompanyingPeriod' => $accompanyingPeriod, + ])->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $this->entityManager->persist($entity); + $this->entityManager->flush(); + + $this->addFlash('success', $this->get('translator')->trans('Success : activity updated!')); + + $params = $this->buildParamsToUrl($person, $accompanyingPeriod); + $params['id'] = $entity->getId(); + + return $this->redirectToRoute('chill_activity_activity_show', $params); } // TODO revoir le Voter de Activity pour tenir compte qu'une activité peut appartenir a une période @@ -517,7 +533,59 @@ final class ActivityController extends AbstractController private function buildParamsToUrl(?Person $person, ?AccompanyingPeriod $accompanyingPeriod): array { +<<<<<<< HEAD $params = []; +======= + $view = null; + + [$person, $accompanyingPeriod] = $this->getEntity($request); + + if ($accompanyingPeriod instanceof AccompanyingPeriod) { + $view = 'ChillActivityBundle:Activity:confirm_deleteAccompanyingCourse.html.twig'; + } elseif ($person instanceof Person) { + $view = 'ChillActivityBundle:Activity:confirm_deletePerson.html.twig'; + } + + $activity = $this->activityRepository->find($id); + + if (!$activity) { + throw $this->createNotFoundException('Unable to find Activity entity.'); + } + + // TODO + // $this->denyAccessUnlessGranted('CHILL_ACTIVITY_DELETE', $activity); + + $form = $this->createDeleteForm($activity->getId(), $person, $accompanyingPeriod); + + if ($request->getMethod() === Request::METHOD_DELETE) { + $form->handleRequest($request); + + if ($form->isValid()) { + $this->logger->notice("An activity has been removed", [ + '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( + static fn (ActivityReason $ar): int => $ar->getId() + ) + ->toArray(), + 'type_id' => $activity->getActivityType()->getId(), + 'duration' => $activity->getDurationTime() ? $activity->getDurationTime()->format('U') : null, + 'date' => $activity->getDate()->format('Y-m-d'), + 'attendee' => $activity->getAttendee() + ]); + + $this->entityManager->remove($activity); + $this->entityManager->flush(); + + $this->addFlash('success', $this->get('translator') + ->trans("The activity has been successfully removed.")); + + $params = $this->buildParamsToUrl($person, $accompanyingPeriod); +>>>>>>> correct deprecated activity method if (null !== $person) { $params['person_id'] = $person->getId();