mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-10-18 03:02:49 +00:00
rdv->activity: create event for storing the linked activity to a calendar
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\CalendarBundle\Event;
|
||||
|
||||
use Chill\ActivityBundle\Entity\Activity;
|
||||
use Doctrine\Persistence\Event\LifecycleEventArgs;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
|
||||
class ListenToActivityCreate
|
||||
{
|
||||
|
||||
private RequestStack $requestStack;
|
||||
|
||||
public function __construct(RequestStack $requestStack)
|
||||
{
|
||||
$this->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();
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user