2024-07-17 17:15:22 +00:00
|
|
|
<?php
|
|
|
|
namespace YesWiki\Meeo\Controller;
|
|
|
|
|
2024-07-29 17:28:09 +00:00
|
|
|
include_once "includes/email.inc.php";
|
|
|
|
|
|
|
|
include_once "includes/email.inc.php";
|
|
|
|
|
2024-07-30 08:48:11 +00:00
|
|
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
2024-07-17 17:15:22 +00:00
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
|
|
use YesWiki\Core\ApiResponse;
|
2024-07-29 16:58:52 +00:00
|
|
|
use YesWiki\Core\Controller\AuthController;
|
2024-07-17 17:15:22 +00:00
|
|
|
use YesWiki\Core\YesWikiController;
|
2024-07-20 18:58:35 +00:00
|
|
|
use YesWiki\Meeo\Controle\Controle;
|
2024-07-29 16:50:23 +00:00
|
|
|
use YesWiki\Meeo\Service\AbsenceManager;
|
2024-07-18 19:18:59 +00:00
|
|
|
use YesWiki\Meeo\Service\EleveManager;
|
2024-07-20 18:58:35 +00:00
|
|
|
use YesWiki\Meeo\Service\NoteManager;
|
2024-07-17 17:15:22 +00:00
|
|
|
|
|
|
|
class ApiController extends YesWikiController
|
|
|
|
{
|
2024-07-30 08:48:11 +00:00
|
|
|
private $redirectParams;
|
|
|
|
|
2024-08-03 09:56:26 +00:00
|
|
|
public function __construct() {
|
|
|
|
|
2024-07-30 08:48:11 +00:00
|
|
|
}
|
|
|
|
|
2024-07-17 17:15:22 +00:00
|
|
|
/**
|
|
|
|
* @Route("/api/meeo/eleves",methods={"POST"},options={"acl":{"public"}})
|
|
|
|
*/
|
|
|
|
public function eleveUpdate(Request $request) {
|
2024-08-03 09:56:26 +00:00
|
|
|
$params = $this->getService(ParameterBagInterface::class);
|
|
|
|
$redirectParams = $params->get('meeo')['redirect'];
|
|
|
|
|
2024-07-18 19:18:59 +00:00
|
|
|
$eleveController = $this->getService(EleveManager::class);
|
2024-07-17 17:15:22 +00:00
|
|
|
$content = $request->getContent();
|
|
|
|
|
|
|
|
parse_str($content, $parameters);
|
|
|
|
|
2024-07-18 19:18:59 +00:00
|
|
|
$datas = [];
|
2024-07-17 17:15:22 +00:00
|
|
|
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);
|
2024-07-17 17:15:22 +00:00
|
|
|
}
|
|
|
|
if ($clef_action[1] == 'del') {
|
2024-07-18 19:18:59 +00:00
|
|
|
$eleveController->del($clef_action[0]);
|
2024-07-17 17:15:22 +00:00
|
|
|
}
|
|
|
|
}
|
2024-07-28 09:14:51 +00:00
|
|
|
// return new ApiResponse($data);
|
2024-08-03 09:56:26 +00:00
|
|
|
return $this->wiki->redirect($redirectParams['eleveUpdate'], 200);
|
2024-07-17 17:15:22 +00:00
|
|
|
}
|
2024-07-20 18:58:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @Route("/api/meeo/controle",methods={"POST"},options={"acl":{"public"}})
|
|
|
|
*/
|
2024-07-27 15:19:40 +00:00
|
|
|
public function controle(Request $request) {
|
2024-08-03 09:56:26 +00:00
|
|
|
$params = $this->getService(ParameterBagInterface::class);
|
|
|
|
$redirectParams = $params->get('meeo')['redirect'];
|
|
|
|
|
2024-07-21 09:43:47 +00:00
|
|
|
$noteManager = $this->getService(NoteManager::class);
|
2024-07-20 18:58:35 +00:00
|
|
|
$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);
|
|
|
|
|
2024-09-11 06:47:50 +00:00
|
|
|
$controle = new Controle($parameters['intitule'], $parameters['matiere'], $parameters['max'], $parameters['coef'], $eleves);
|
2024-07-21 09:43:47 +00:00
|
|
|
$controle->createNotes($noteManager);
|
2024-07-28 09:14:51 +00:00
|
|
|
// return new ApiResponse($controle);
|
2024-08-03 09:56:26 +00:00
|
|
|
return $this->wiki->redirect($redirectParams['controle'], 200);
|
2024-07-20 18:58:35 +00:00
|
|
|
}
|
2024-07-28 09:14:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @Route("/api/meeo/absence",methods={"POST"},options={"acl":{"public"}})
|
|
|
|
*/
|
|
|
|
public function absence(Request $request) {
|
2024-08-03 09:56:26 +00:00
|
|
|
$params = $this->getService(ParameterBagInterface::class);
|
|
|
|
$redirectParams = $params->get('meeo')['redirect'];
|
2024-07-28 09:14:51 +00:00
|
|
|
$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);
|
2024-07-29 17:07:12 +00:00
|
|
|
$absence = $absenceManager->create($eleve, $parameters['date_debut_absence'], $parameters['date_fin_absence'], $parameters['justification']);
|
2024-07-29 16:50:23 +00:00
|
|
|
|
|
|
|
// Récupération de l'expéditeur
|
2024-07-29 17:28:09 +00:00
|
|
|
$expediteur = $this->getService(AuthController::class)->getLoggedUser();
|
|
|
|
// echo "Expediteur : ".var_dump($expediteur)."\n";
|
2024-07-29 16:50:23 +00:00
|
|
|
|
2024-09-04 14:07:57 +00:00
|
|
|
foreach ($eleve->getParentEmails() as $destinataire) {
|
|
|
|
echo "Envoyer à : ".$destinataire."\n";
|
|
|
|
|
|
|
|
// Génération du rendu du mail
|
|
|
|
$body = $this->render("@meeo/eleve_creer_absence.twig", [
|
|
|
|
'eleve' => $eleve,
|
|
|
|
'absence' => $parameters
|
|
|
|
]);
|
|
|
|
// echo $body;
|
|
|
|
|
|
|
|
// Envoi de mail à la personne qui a été absente
|
|
|
|
if (!send_mail($expediteur['email'], $expediteur['name'], $destinataire, "Absence", $body, $body))
|
|
|
|
echo "Erreur d'envoie de mail";
|
|
|
|
}
|
|
|
|
|
2024-09-04 14:09:38 +00:00
|
|
|
// return new ApiResponse($parameters);
|
|
|
|
return $this->wiki->redirect($redirectParams['absence'], 200);
|
2024-07-28 09:14:51 +00:00
|
|
|
}
|
2024-07-17 17:15:22 +00:00
|
|
|
}
|