From cebc19ef236aac2968d2ffccfcff9b975b63fa8d Mon Sep 17 00:00:00 2001 From: polo Date: Mon, 23 Jun 2025 03:33:38 +0200 Subject: fullcalendar --- src/controller/ajax_calendar.php | 74 ++++++++++++++++++++++++++++++++++++++++ src/controller/post.php | 1 + 2 files changed, 75 insertions(+) create mode 100644 src/controller/ajax_calendar.php (limited to 'src/controller') diff --git a/src/controller/ajax_calendar.php b/src/controller/ajax_calendar.php new file mode 100644 index 0000000..834c88b --- /dev/null +++ b/src/controller/ajax_calendar.php @@ -0,0 +1,74 @@ +setTimezone(new DateTimeZone('UTC')); + $end->setTimezone(new DateTimeZone('UTC')); + + // affichage format ISO à l'heure UTC + //$date->format('Y-m-d\TH:i:s\Z'); + + // on prend les évènements se finissant après le début ou commençant avant la fin de la fourchette + $dql = 'SELECT e FROM App\Entity\Event e WHERE e.end >= :start AND e.start <= :end'; + $bulk_data = $entityManager->createQuery($dql) + ->setParameter('start', $start) + ->setParameter('end', $end) + ->getResult(); + + $events = []; + foreach($bulk_data as $one_entry){ + $event = new EventDTO($one_entry); + $events[] = $event->toArray(); + } + + header('Content-Type: application/json'); + echo json_encode($events); + die; +} + +// actions sur le calendrier +elseif(isset($_SESSION['admin']) && $_SESSION['admin'] === true + && $_SERVER['REQUEST_METHOD'] === 'POST' && $_SERVER['CONTENT_TYPE'] === 'application/json') +{ + $data = file_get_contents('php://input'); + $json = json_decode($data, true); + + if($_GET['action'] === 'new_event'){ + $event = new Event($json['title'], $json['start'], $json['end'], $json['allDay'], $json["description"], $json['color']); + + $entityManager->persist($event); + $entityManager->flush(); + + echo json_encode(['success' => true, 'id' => $event->getId()]); + } + elseif($_GET['action'] === 'update_event'){ + $event = $entityManager->find('App\Entity\Event', $json['id']); + $event->updateFromJSON($json); + $entityManager->flush(); + + echo json_encode(['success' => true]); + } + elseif($_GET['action'] === 'remove_event'){ + $event = $entityManager->find('App\Entity\Event', $json['id']); + $entityManager->remove($event); + $entityManager->flush(); + + echo json_encode(['success' => true]); + } + else{ + echo json_encode(['success' => false]); + } + die; +} \ No newline at end of file diff --git a/src/controller/post.php b/src/controller/post.php index deacafb..b0bc6a0 100644 --- a/src/controller/post.php +++ b/src/controller/post.php @@ -231,3 +231,4 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) require '../src/controller/ajax.php'; } } +require '../src/controller/ajax_calendar.php'; \ No newline at end of file -- cgit v1.2.3