diff options
author | polo <ordipolo@gmx.fr> | 2025-06-23 03:33:38 +0200 |
---|---|---|
committer | polo <ordipolo@gmx.fr> | 2025-06-23 03:33:38 +0200 |
commit | cebc19ef236aac2968d2ffccfcff9b975b63fa8d (patch) | |
tree | 5b8e08045a45063475f533bfae4b4524720fe7bd /src/controller | |
parent | 8cf5ac1abf9e2a6134cb82d4582aecaa99b1331a (diff) | |
download | cms-cebc19ef236aac2968d2ffccfcff9b975b63fa8d.zip |
fullcalendar
Diffstat (limited to 'src/controller')
-rw-r--r-- | src/controller/ajax_calendar.php | 74 | ||||
-rw-r--r-- | src/controller/post.php | 1 |
2 files changed, 75 insertions, 0 deletions
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 @@ | |||
1 | <?php | ||
2 | // src/controller/calendar.php | ||
3 | |||
4 | declare(strict_types=1); | ||
5 | |||
6 | use App\Entity\Event; | ||
7 | |||
8 | // chargement des évènements à la création du calendrier | ||
9 | // et au changement de dates affichées (boutons flèches mais pas changement de vue) | ||
10 | if($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['action']) && $_GET['action'] === 'get_events' | ||
11 | && isset($_GET['start']) && isset($_GET['end']) && empty($_POST)) | ||
12 | { | ||
13 | // bornes début et fin du calendrier affiché à l'heure locale | ||
14 | // noter que la vue "planning" est similaire à la vue "semaine" | ||
15 | $start = new DateTime($_GET['start']); | ||
16 | $end = new DateTime($_GET['end']); | ||
17 | $start->setTimezone(new DateTimeZone('UTC')); | ||
18 | $end->setTimezone(new DateTimeZone('UTC')); | ||
19 | |||
20 | // affichage format ISO à l'heure UTC | ||
21 | //$date->format('Y-m-d\TH:i:s\Z'); | ||
22 | |||
23 | // on prend les évènements se finissant après le début ou commençant avant la fin de la fourchette | ||
24 | $dql = 'SELECT e FROM App\Entity\Event e WHERE e.end >= :start AND e.start <= :end'; | ||
25 | $bulk_data = $entityManager->createQuery($dql) | ||
26 | ->setParameter('start', $start) | ||
27 | ->setParameter('end', $end) | ||
28 | ->getResult(); | ||
29 | |||
30 | $events = []; | ||
31 | foreach($bulk_data as $one_entry){ | ||
32 | $event = new EventDTO($one_entry); | ||
33 | $events[] = $event->toArray(); | ||
34 | } | ||
35 | |||
36 | header('Content-Type: application/json'); | ||
37 | echo json_encode($events); | ||
38 | die; | ||
39 | } | ||
40 | |||
41 | // actions sur le calendrier | ||
42 | elseif(isset($_SESSION['admin']) && $_SESSION['admin'] === true | ||
43 | && $_SERVER['REQUEST_METHOD'] === 'POST' && $_SERVER['CONTENT_TYPE'] === 'application/json') | ||
44 | { | ||
45 | $data = file_get_contents('php://input'); | ||
46 | $json = json_decode($data, true); | ||
47 | |||
48 | if($_GET['action'] === 'new_event'){ | ||
49 | $event = new Event($json['title'], $json['start'], $json['end'], $json['allDay'], $json["description"], $json['color']); | ||
50 | |||
51 | $entityManager->persist($event); | ||
52 | $entityManager->flush(); | ||
53 | |||
54 | echo json_encode(['success' => true, 'id' => $event->getId()]); | ||
55 | } | ||
56 | elseif($_GET['action'] === 'update_event'){ | ||
57 | $event = $entityManager->find('App\Entity\Event', $json['id']); | ||
58 | $event->updateFromJSON($json); | ||
59 | $entityManager->flush(); | ||
60 | |||
61 | echo json_encode(['success' => true]); | ||
62 | } | ||
63 | elseif($_GET['action'] === 'remove_event'){ | ||
64 | $event = $entityManager->find('App\Entity\Event', $json['id']); | ||
65 | $entityManager->remove($event); | ||
66 | $entityManager->flush(); | ||
67 | |||
68 | echo json_encode(['success' => true]); | ||
69 | } | ||
70 | else{ | ||
71 | echo json_encode(['success' => false]); | ||
72 | } | ||
73 | die; | ||
74 | } \ 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) | |||
231 | require '../src/controller/ajax.php'; | 231 | require '../src/controller/ajax.php'; |
232 | } | 232 | } |
233 | } | 233 | } |
234 | require '../src/controller/ajax_calendar.php'; \ No newline at end of file | ||