diff options
| author | polo <ordipolo@gmx.fr> | 2025-06-21 01:44:16 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2025-06-21 01:44:16 +0200 |
| commit | 8ee3440f204dfc6532a49a05719ba37a8c4df359 (patch) | |
| tree | 03dec8764e55d1a4e1983fcceea8ccd99686989a /src/controller/calendar.php | |
| parent | f0e0b449f2bd6c4417e467b2903b29ad03a9626d (diff) | |
| download | fullcalendar-8ee3440f204dfc6532a49a05719ba37a8c4df359.tar.gz fullcalendar-8ee3440f204dfc6532a49a05719ba37a8c4df359.tar.bz2 fullcalendar-8ee3440f204dfc6532a49a05719ba37a8c4df359.zip | |
échanges client/serveur
Diffstat (limited to 'src/controller/calendar.php')
| -rw-r--r-- | src/controller/calendar.php | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/src/controller/calendar.php b/src/controller/calendar.php new file mode 100644 index 0000000..ab2832e --- /dev/null +++ b/src/controller/calendar.php | |||
| @@ -0,0 +1,99 @@ | |||
| 1 | <?php | ||
| 2 | // src/controller/calendar.php | ||
| 3 | |||
| 4 | // chargement des évènements à la création du calendrier | ||
| 5 | // et au changement de dates affichées (boutons flèches mais pas changement de vue) | ||
| 6 | if($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['action']) && $_GET['action'] === 'get_events' | ||
| 7 | && isset($_GET['start']) && isset($_GET['end']) && empty($_POST)) | ||
| 8 | { | ||
| 9 | // bornes début et fin du calendrier affiché à l'heure locale | ||
| 10 | // noter que la vue "planning" est similaire à la vue "semaine" | ||
| 11 | $start = new DateTime($_GET['start']); | ||
| 12 | $end = new DateTime($_GET['end']); | ||
| 13 | $start->setTimezone(new DateTimeZone('UTC')); | ||
| 14 | $end->setTimezone(new DateTimeZone('UTC')); | ||
| 15 | |||
| 16 | // recherche des évènement en BDD avec ceci: | ||
| 17 | // WHERE end >= :start AND start <= :end | ||
| 18 | // on prend les évènements se finissant après le début | ||
| 19 | // ou commençant avant la fin de la fourchette | ||
| 20 | |||
| 21 | // affichage format ISO à l'heure UTC | ||
| 22 | //$date->format('Y-m-d\TH:i:s\Z'); | ||
| 23 | |||
| 24 | // chatgpt suggère l'utilisation d'un DTO => une classe de données simple et tout "public" | ||
| 25 | // => pour des évènements obtenables autant depuis la BDD que de fichiers .ics par exemple | ||
| 26 | |||
| 27 | $events = [ | ||
| 28 | [ | ||
| 29 | 'id' => 1, | ||
| 30 | 'title' => 'Évènement1', | ||
| 31 | 'start' => '2025-06-03T05:00:00Z', // Z indique que l'heure est en UTC | ||
| 32 | 'end' => '2025-06-03T09:00:00Z', | ||
| 33 | 'allDay' => false, | ||
| 34 | 'color' => '#ffa500', // couleur hexa, éviter les couleurs CSS qui ne fonctionnent pas dans value="" en HTML | ||
| 35 | //'url' => 'https://dev.nageurs-bigoudens.fr', // comportement: https://fullcalendar.io/docs/eventClick | ||
| 36 | 'description' => 'blablabla', | ||
| 37 | ], | ||
| 38 | [ | ||
| 39 | 'id' => 2, | ||
| 40 | 'title' => 'Évènement2', | ||
| 41 | 'start' => '2025-06-06T08:00:00Z', | ||
| 42 | 'end' => '2025-06-07T08:00:00Z', | ||
| 43 | 'allDay' => false, | ||
| 44 | 'color' => '#e01b24', | ||
| 45 | 'description' => 'truc machin', | ||
| 46 | ], | ||
| 47 | [ | ||
| 48 | 'id' => 3, | ||
| 49 | 'title' => 'Évènement3', | ||
| 50 | 'start' => '2025-06-08', | ||
| 51 | 'end' => '2025-06-09', | ||
| 52 | 'allDay' => true, // pas d'heure | ||
| 53 | 'color' => '#008000', | ||
| 54 | 'description' => 'ça va chier', | ||
| 55 | ], | ||
| 56 | // provoque une erreur, si allDay la fin ne peut être égale au début | ||
| 57 | /*[ | ||
| 58 | 'id' => 4, | ||
| 59 | 'title' => 'Évènement4', | ||
| 60 | 'start' => '2025-06-09', | ||
| 61 | 'end' => '2025-06-09', | ||
| 62 | 'allDay' => true, | ||
| 63 | 'color' => '#1a5fb4', | ||
| 64 | ],*/ | ||
| 65 | ]; | ||
| 66 | |||
| 67 | header('Content-Type: application/json'); | ||
| 68 | echo json_encode($events); | ||
| 69 | die; | ||
| 70 | } | ||
| 71 | |||
| 72 | // actions sur le calendrier | ||
| 73 | elseif(isset($_SESSION['admin']) && $_SESSION['admin'] === true | ||
| 74 | && $_SERVER['REQUEST_METHOD'] === 'POST' && $_SERVER['CONTENT_TYPE'] === 'application/json') | ||
| 75 | { | ||
| 76 | $data = file_get_contents('php://input'); | ||
| 77 | $json = json_decode($data, true); | ||
| 78 | |||
| 79 | if($_GET['action'] === 'new_event'){ | ||
| 80 | // BDD | ||
| 81 | //print_r($json);die; | ||
| 82 | $id = 7; // généré par la BDD | ||
| 83 | echo json_encode(['success' => true, 'id' => $id]); | ||
| 84 | } | ||
| 85 | elseif($_GET['action'] === 'update_event'){ | ||
| 86 | // BDD | ||
| 87 | //print_r($json);die; | ||
| 88 | echo json_encode(['success' => true]); | ||
| 89 | } | ||
| 90 | elseif($_GET['action'] === 'remove_event'){ | ||
| 91 | // BDD | ||
| 92 | //echo $json['id']; die; | ||
| 93 | echo json_encode(['success' => true]); | ||
| 94 | } | ||
| 95 | else{ | ||
| 96 | echo json_encode(['success' => false]); | ||
| 97 | } | ||
| 98 | die; | ||
| 99 | } \ No newline at end of file | ||
