diff --git a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php index 0513e933c..c87f7ebd1 100644 --- a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php +++ b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php @@ -229,6 +229,7 @@ class CalendarController extends AbstractController $durationTimeInMinutes = $durationTime->days*1440 + $durationTime->h*60 + $durationTime->i; $activityData = [ + 'calendarId' => $id, 'personsId' => $personsId, 'professionalsId' => $professionalsId, 'date' => $entity->getStartDate()->format('Y-m-d'), diff --git a/src/Bundle/ChillCalendarBundle/DependencyInjection/ChillCalendarExtension.php b/src/Bundle/ChillCalendarBundle/DependencyInjection/ChillCalendarExtension.php index 8660fac52..eaa8a1416 100644 --- a/src/Bundle/ChillCalendarBundle/DependencyInjection/ChillCalendarExtension.php +++ b/src/Bundle/ChillCalendarBundle/DependencyInjection/ChillCalendarExtension.php @@ -29,6 +29,7 @@ class ChillCalendarExtension extends Extension implements PrependExtensionInterf $loader->load('services/controller.yml'); $loader->load('services/fixtures.yml'); $loader->load('services/form.yml'); + $loader->load('services/event.yml'); } public function prepend(ContainerBuilder $container) diff --git a/src/Bundle/ChillCalendarBundle/Event/ListenToActivityCreate.php b/src/Bundle/ChillCalendarBundle/Event/ListenToActivityCreate.php new file mode 100644 index 000000000..76a47015d --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Event/ListenToActivityCreate.php @@ -0,0 +1,40 @@ +requestStack = $requestStack; + } + + public function postPersist(Activity $activity, LifecycleEventArgs $event): void + { + // Get the calendarId from the request + $request = $this->requestStack->getCurrentRequest(); + if ($request->query->has('activityData')) { + $activityData = $request->query->get('activityData'); + if (array_key_exists('calendarId', $activityData)) { + $calendarId = $activityData['calendarId']; + } + } + + // Attach the activity to the calendar + $em = $event->getObjectManager(); + + $calendar = $em->getRepository(\Chill\CalendarBundle\Entity\Calendar::class)->find($calendarId); + $calendar->setActivity($activity); + + $em->persist($calendar); + $em->flush(); + + } +} \ No newline at end of file diff --git a/src/Bundle/ChillCalendarBundle/Resources/config/services/event.yml b/src/Bundle/ChillCalendarBundle/Resources/config/services/event.yml new file mode 100644 index 000000000..348677174 --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Resources/config/services/event.yml @@ -0,0 +1,10 @@ +services: + Chill\CalendarBundle\Event\ListenToActivityCreate: + autowire: true + autoconfigure: true + tags: + - + name: 'doctrine.orm.entity_listener' + event: 'postPersist' + entity: 'Chill\ActivityBundle\Entity\Activity' + \ No newline at end of file