diff options
| author | polo <ordipolo@gmx.fr> | 2026-10-23 00:47:32 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2026-10-23 00:47:32 +0200 |
| commit | f27cca08ff786ceff1870147f6d6bad14d71117f (patch) | |
| tree | d36597a72025313d6faf4ed228755fa267ebe2f6 /src/controller/CalendarController.php | |
| parent | c7309f900ef05bd5cb313110ec159b761af394ec (diff) | |
| download | cms-f27cca08ff786ceff1870147f6d6bad14d71117f.tar.gz cms-f27cca08ff786ceff1870147f6d6bad14d71117f.tar.bz2 cms-f27cca08ff786ceff1870147f6d6bad14d71117f.zip | |
dossiers avec majuscule, namespace pour toutes les classes, autoload psr-4, UserDataService::createZip déplacé dans Backup
Diffstat (limited to 'src/controller/CalendarController.php')
| -rw-r--r-- | src/controller/CalendarController.php | 74 |
1 files changed, 0 insertions, 74 deletions
diff --git a/src/controller/CalendarController.php b/src/controller/CalendarController.php deleted file mode 100644 index 1a62afa..0000000 --- a/src/controller/CalendarController.php +++ /dev/null | |||
| @@ -1,74 +0,0 @@ | |||
| 1 | <?php | ||
| 2 | // /src/controller/CalendarController.php | ||
| 3 | |||
| 4 | declare(strict_types=1); | ||
| 5 | |||
| 6 | use Doctrine\ORM\EntityManager; | ||
| 7 | use App\Entity\Event; | ||
| 8 | use Symfony\Component\HttpFoundation\JsonResponse; | ||
| 9 | |||
| 10 | class CalendarController | ||
| 11 | { | ||
| 12 | static public function getData(EntityManager $entityManager): JsonResponse | ||
| 13 | { | ||
| 14 | // bornes début et fin du calendrier affiché à l'heure locale | ||
| 15 | // noter que la vue "planning" est similaire à la vue "semaine" | ||
| 16 | $start = new DateTime($_GET['start']); | ||
| 17 | $end = new DateTime($_GET['end']); | ||
| 18 | $start->setTimezone(new DateTimeZone('UTC')); | ||
| 19 | $end->setTimezone(new DateTimeZone('UTC')); | ||
| 20 | |||
| 21 | // affichage format ISO à l'heure UTC | ||
| 22 | //$date->format('Y-m-d\TH:i:s\Z'); | ||
| 23 | |||
| 24 | // on prend les évènements se finissant après le début ou commençant avant la fin de la fourchette | ||
| 25 | $dql = 'SELECT e FROM App\Entity\Event e WHERE e.end >= :start AND e.start <= :end'; | ||
| 26 | $bulk_data = $entityManager->createQuery($dql) | ||
| 27 | ->setParameter('start', $start) | ||
| 28 | ->setParameter('end', $end) | ||
| 29 | ->getResult(); | ||
| 30 | |||
| 31 | $events = []; | ||
| 32 | foreach($bulk_data as $one_entry){ | ||
| 33 | $event = new EventDTO($one_entry); | ||
| 34 | $events[] = $event->toArray(); | ||
| 35 | } | ||
| 36 | |||
| 37 | return new JsonResponse($events); | ||
| 38 | } | ||
| 39 | |||
| 40 | static public function newEvent(array $json, EntityManager $entityManager): JsonResponse | ||
| 41 | { | ||
| 42 | try{ | ||
| 43 | $event = new Event($json); | ||
| 44 | } | ||
| 45 | catch(InvalidArgumentException $e){ | ||
| 46 | return new JsonResponse(['success' => false, 'error' => $e->getMessage()], JsonResponse::HTTP_BAD_REQUEST); // code 400 | ||
| 47 | } | ||
| 48 | $entityManager->persist($event); | ||
| 49 | $entityManager->flush(); | ||
| 50 | |||
| 51 | return new JsonResponse(['success' => true, 'id' => $event->getId()]); | ||
| 52 | } | ||
| 53 | static public function updateEvent(array $json, EntityManager $entityManager): JsonResponse | ||
| 54 | { | ||
| 55 | $event = $entityManager->find('App\Entity\Event', (int)$json['id']); | ||
| 56 | try{ | ||
| 57 | $event->securedUpdateFromJSON($json); | ||
| 58 | } | ||
| 59 | catch(InvalidArgumentException $e){ | ||
| 60 | return new JsonResponse(['success' => false, 'error' => $e->getMessage()], JsonResponse::HTTP_BAD_REQUEST); // code 400 | ||
| 61 | } | ||
| 62 | $entityManager->flush(); | ||
| 63 | |||
| 64 | return new JsonResponse(['success' => true]); | ||
| 65 | } | ||
| 66 | static public function removeEvent(array $json, EntityManager $entityManager): JsonResponse | ||
| 67 | { | ||
| 68 | $event = $entityManager->find('App\Entity\Event', (int)$json['id']); | ||
| 69 | $entityManager->remove($event); | ||
| 70 | $entityManager->flush(); | ||
| 71 | |||
| 72 | return new JsonResponse(['success' => true]); | ||
| 73 | } | ||
| 74 | } \ No newline at end of file | ||
