summaryrefslogtreecommitdiff
path: root/src/controller/ajax_calendar.php
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2025-06-24 23:57:59 +0200
committerpolo <ordipolo@gmx.fr>2025-06-24 23:57:59 +0200
commit7a13d53e43c7db7fe39474208ffa54ba2906d308 (patch)
tree5bb9af2935c0e7c753c5eace6d9e4538c739a383 /src/controller/ajax_calendar.php
parent41adf94ebf868232aa43fe9b8b80029896da9da7 (diff)
downloadcms-7a13d53e43c7db7fe39474208ffa54ba2906d308.zip
petites améliorations au système de mot de passe
Diffstat (limited to 'src/controller/ajax_calendar.php')
-rw-r--r--src/controller/ajax_calendar.php87
1 files changed, 0 insertions, 87 deletions
diff --git a/src/controller/ajax_calendar.php b/src/controller/ajax_calendar.php
deleted file mode 100644
index 79268f6..0000000
--- a/src/controller/ajax_calendar.php
+++ /dev/null
@@ -1,87 +0,0 @@
1<?php
2// src/controller/calendar.php
3
4declare(strict_types=1);
5
6use 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)
10if($_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
42elseif(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 try{
50 $event = new Event($json);
51 }
52 catch(InvalidArgumentException $e){
53 echo json_encode(['success' => false, 'error' => $e->getMessage()]);
54 http_response_code(400);
55 die;
56 }
57 $entityManager->persist($event);
58 $entityManager->flush();
59
60 echo json_encode(['success' => true, 'id' => $event->getId()]);
61 }
62 elseif($_GET['action'] === 'update_event'){
63 $event = $entityManager->find('App\Entity\Event', (int)$json['id']);
64 try{
65 $event->securedUpdateFromJSON($json);
66 }
67 catch(InvalidArgumentException $e){
68 echo json_encode(['success' => false, 'error' => $e->getMessage()]);
69 http_response_code(400);
70 die;
71 }
72 $entityManager->flush();
73
74 echo json_encode(['success' => true]);
75 }
76 elseif($_GET['action'] === 'remove_event'){
77 $event = $entityManager->find('App\Entity\Event', (int)$json['id']);
78 $entityManager->remove($event);
79 $entityManager->flush();
80
81 echo json_encode(['success' => true]);
82 }
83 else{
84 echo json_encode(['success' => false]);
85 }
86 die;
87} \ No newline at end of file