ynh_extension_meeo/controllers/ApiController.php

94 lines
3.1 KiB
PHP
Raw Normal View History

<?php
namespace YesWiki\Meeo\Controller;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use YesWiki\Core\ApiResponse;
use YesWiki\Core\YesWikiController;
use YesWiki\Meeo\Controle\Controle;
2024-07-29 16:50:23 +00:00
use YesWiki\Meeo\Service\AbsenceManager;
use YesWiki\Meeo\Service\EleveManager;
use YesWiki\Meeo\Service\NoteManager;
class ApiController extends YesWikiController
{
private $redirectParams;
public function __construct(ParameterBagInterface $params) {
$this->redirectParams = $params->get('meeo')['redirect'];
}
/**
* @Route("/api/meeo/eleves",methods={"POST"},options={"acl":{"public"}})
*/
public function eleveUpdate(Request $request) {
$eleveController = $this->getService(EleveManager::class);
$content = $request->getContent();
parse_str($content, $parameters);
$datas = [];
foreach ($parameters as $cle => $valeur) {
$clef_action = explode('_', $cle);
if ($clef_action[1] == 'classe' && $valeur != 'aucune') {
2024-07-27 13:22:09 +00:00
$eleve = $eleveController->getEleve($clef_action[0]);
// echo var_dump($valeur);
$eleve->setClasse($valeur);
echo var_dump($eleve);
$datas[] = $eleveController->updateEleve($eleve);
}
if ($clef_action[1] == 'del') {
$eleveController->del($clef_action[0]);
}
}
2024-07-28 09:14:51 +00:00
// return new ApiResponse($data);
return $this->wiki->redirect($this->redirectParams['eleveUpdate'], 200);
}
/**
* @Route("/api/meeo/controle",methods={"POST"},options={"acl":{"public"}})
*/
2024-07-27 15:19:40 +00:00
public function controle(Request $request) {
$noteManager = $this->getService(NoteManager::class);
$content = $request->getContent();
parse_str($content, $parameters);
include 'tools/meeo/libs/controle/Controle.lib.php';
$eleves = array_filter($parameters, function($key) {
return strpos($key, 'eleve_') === 0;
}, ARRAY_FILTER_USE_KEY);
$controle = new Controle($parameters['intitule'], $parameters['matiere'], $parameters['coef'], $eleves);
$controle->createNotes($noteManager);
2024-07-28 09:14:51 +00:00
// return new ApiResponse($controle);
return $this->wiki->redirect($this->redirectParams['controle'], 200);
}
2024-07-28 09:14:51 +00:00
/**
* @Route("/api/meeo/absence",methods={"POST"},options={"acl":{"public"}})
*/
public function absence(Request $request) {
$content = $request->getContent();
parse_str($content, $parameters);
2024-07-29 16:50:23 +00:00
// Créer l'absence dans bazar
$eleve = $this->getService(EleveManager::class)->getEleve($parameters['eleve']);
$absenceManager = $this->getService(AbsenceManager::class);
$absenceManager->create($eleve, $parameters['date_debut_absence'], $parameters['date_fin_absence'], $parameters['justification']);
// Récupération de l'expéditeur
// Récupération du destinataire
// Génération du rendu du mail
// Envoi de mail à la personne qui a été absente
2024-07-28 09:14:51 +00:00
return new ApiResponse($parameters);
// return $this->wiki->redirect($this->redirectParams['absence'], 200);
2024-07-28 09:14:51 +00:00
}
}