Compare commits

...

4 commits

Author SHA1 Message Date
mckmonster
09d87dee72 [Absence] envoie de mail 2024-08-01 18:26:38 +02:00
mckmonster
d6c8fd2ba7 [Absence] Debut de texte pour le message d'absence 2024-08-01 18:25:02 +02:00
mckmonster
4a4306f1c8 [Absence] Recupération des emails expediteurs et destinataire. 2024-08-01 18:25:02 +02:00
mckmonster
00a4ad9784 [Absence] Creation entrée bazar 2024-08-01 18:25:02 +02:00
5 changed files with 86 additions and 4 deletions

View file

@ -1,13 +1,19 @@
<?php
namespace YesWiki\Meeo\Controller;
include_once "includes/email.inc.php";
include_once "includes/email.inc.php";
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\Controller\AuthController;
use YesWiki\Core\YesWikiController;
use YesWiki\Meeo\Controle\Controle;
use YesWiki\Meeo\Service\AbsenceManager;
use YesWiki\Meeo\Service\EleveManager;
use YesWiki\Meeo\Service\NoteManager;
@ -71,10 +77,33 @@ class ApiController extends YesWikiController
* @Route("/api/meeo/absence",methods={"POST"},options={"acl":{"public"}})
*/
public function absence(Request $request) {
// $noteManager = $this->getService(NoteManager::class);
$content = $request->getContent();
parse_str($content, $parameters);
// Créer l'absence dans bazar
$eleve = $this->getService(EleveManager::class)->getEleve($parameters['eleve']);
$absenceManager = $this->getService(AbsenceManager::class);
$absence = $absenceManager->create($eleve, $parameters['date_debut_absence'], $parameters['date_fin_absence'], $parameters['justification']);
// Récupération de l'expéditeur
$expediteur = $this->getService(AuthController::class)->getLoggedUser();
// echo "Expediteur : ".var_dump($expediteur)."\n";
// Récupération du destinataire
$destinataire = $eleve->getEmail();
// 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";
return new ApiResponse($parameters);
// return $this->wiki->redirect($this->redirectParams['absence'], 200);
}

View file

@ -45,6 +45,10 @@ class Eleve {
$this->data['listeListeClassesbf_classe'] = $classe;
}
public function getEmail() {
return $this->user['bf_mail'];
}
public function getData() {
return $this->data;
}

View file

@ -0,0 +1,40 @@
<?php
namespace YesWiki\Meeo\Service;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use YesWiki\Bazar\Service\EntryManager;
use YesWiki\Wiki;
use YesWiki\Meeo\Eleve\Eleve;
class AbsenceManager {
private $wiki;
private $params;
private $entryManager;
private $formId;
private $eleveFormId;
public function __construct( Wiki $wiki, ParameterBagInterface $params, EntryManager $entryManager) {
$this->wiki = $wiki;
$this->params = $params;
$this->entryManager = $entryManager;
$this->formId = $params->get('meeo')['absencesFormId'];
$this->eleveFormId = $params->get('meeo')['elevesFormId'];
}
public function create(Eleve $eleve, $debut, $fin, $justification) {
$data = [
'bf_titre' => 'Absence : '.$eleve->getId().' - '.$debut,
'listefiche'.$this->eleveFormId.'bf_eleve' => $eleve->getId(),
'bf_date_debut' => $debut,
'bf_date_fin' => $fin,
'bf_commentaire' => $justification,
'antispam' => true
];
// echo var_dump($data);
return $this->entryManager->create($this->formId, $data);
}
}

View file

@ -21,10 +21,10 @@
<input class="form-control" type="datetime-local" id="date_fin_absence" name="date_fin_absence"/>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="commentaire">Justification:</label>
<div class="form-group">
<label class="control-label col-sm-2" for="justification">Justification:</label>
<div class="col-sm-10">
<input class="form-control" type="textarea" id="commentaire" name"commentaire"/>
<input class="form-control" type="text" name="justification"/>
</div>
</div>
<button type="submit" class="btn btn-default">Envoyer</button>

View file

@ -0,0 +1,9 @@
Le message sera à voir avec l'équipe educative.
<div>
<p>Bonjour {{ eleve.getNom() }},</p>
<p>Nous vous signalons que votre enfant a été absent {{ absence['date_debut_absence']}}.</p>
<p>Merci d'en prendre note.</p>
</div>