From 17036e83ba3ac68fd9376d8ff1ef15437cbd22af Mon Sep 17 00:00:00 2001 From: nobohan Date: Mon, 20 Sep 2021 17:02:24 +0200 Subject: [PATCH] rdv: rdv-> activity: convert some fields --- .../Controller/ActivityController.php | 29 +++++++++++++++++++ .../Controller/CalendarController.php | 5 +++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php index 2ede8737f..6d9d61355 100644 --- a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php +++ b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php @@ -205,6 +205,35 @@ class ActivityController extends AbstractController $entity->setType($activityType); $entity->setDate(new \DateTime('now')); + if ($request->query->has('activityData')) { + $activityData = $request->query->get('activityData'); + + $durationTimeInMinutes = $activityData['durationTime']; + $hours = floor($durationTimeInMinutes / 60); + $minutes = $durationTimeInMinutes % 60; + + $duration = \DateTime::createFromFormat("H:i", $hours.':'.$minutes); + if ($duration) { + $entity->setDurationTime($duration); + } + + $date = \DateTime::createFromFormat('Y-m-d', $activityData['date']); + if ($date) { + $entity->setDate($date); + } + + foreach($activityData['personsId'] as $personId){ + $person = $em->getRepository(\Chill\PersonBundle\Entity\Person::class)->find($personId); + $entity->addPerson($person); + } + + foreach($activityData['professionalsId'] as $professionalsId){ + $professional = $em->getRepository(\Chill\ThirdPartyBundle\Entity\ThirdParty::class)->find($professionalsId); + $entity->addThirdParty($professional); + } + + } + // TODO revoir le Voter de Activity pour tenir compte qu'une activité peut appartenir a une période // $this->denyAccessUnlessGranted('CHILL_ACTIVITY_CREATE', $entity); diff --git a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php index 103887d36..0513e933c 100644 --- a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php +++ b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php @@ -225,11 +225,14 @@ class CalendarController extends AbstractController array_push($professionalsId, $p->getId()); } + $durationTime = $entity->getEndDate()->diff($entity->getStartDate()); + $durationTimeInMinutes = $durationTime->days*1440 + $durationTime->h*60 + $durationTime->i; + $activityData = [ 'personsId' => $personsId, 'professionalsId' => $professionalsId, 'date' => $entity->getStartDate()->format('Y-m-d'), - 'durationTime' => $entity->getEndDate()->diff($entity->getStartDate())->format("%H:%M") + 'durationTime' => $durationTimeInMinutes ]; return $this->render($view, [