This commit is contained in:
Mickael Veaudour 2024-08-06 08:18:00 +02:00
commit 81ffc1d8fc
No known key found for this signature in database
14 changed files with 174 additions and 59 deletions

View file

@ -14,7 +14,11 @@ class ElevesAction extends YesWikiAction
public function run() public function run()
{ {
$eleveManager = $this->getService(EleveManager::class); try {
return $eleveManager->view(); $eleveManager = $this->getService(EleveManager::class);
return $eleveManager->view();
} catch (Exception $e) {
echo 'Exception reçue : '. $e->getMessage() ."\n";
}
} }
} }

View file

@ -14,7 +14,12 @@ class NotesAction extends YesWikiAction
public function run() public function run()
{ {
$noteManager = $this->getService(NoteManager::class); try {
return $noteManager->viewBulletins(); $noteManager = $this->getService(NoteManager::class);
return $noteManager->viewBulletins();
} catch (Exception $e) {
return 'Exception reçue : '.$e->getMessage()."\n";
}
} }
} }

View file

@ -16,7 +16,10 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
class CreateFormsCommand extends Command class CreateFormsCommand extends Command
{ {
protected $wiki; protected $wiki;
protected $absenceFormId;
protected $notesFormId;
protected $eleveFormId; protected $eleveFormId;
protected $yunohostFormId;
public function __construct(Wiki &$wiki) public function __construct(Wiki &$wiki)
{ {
@ -24,7 +27,10 @@ class CreateFormsCommand extends Command
$this->wiki = $wiki; $this->wiki = $wiki;
$params = $this->wiki->services->get(ParameterBagInterface::class); $params = $this->wiki->services->get(ParameterBagInterface::class);
$meeo_config = $params->get('meeo'); $meeo_config = $params->get('meeo');
$this->absenceFormId = $meeo_config['absencesFormId'];
$this->notesFormId = $meeo_config['notesFormId'];
$this->eleveFormId = $meeo_config['elevesFormId']; $this->eleveFormId = $meeo_config['elevesFormId'];
$this->yunohostFormId = $meeo_config['yunohostFormId'];
} }
protected function configure() protected function configure()
@ -57,6 +63,7 @@ class CreateFormsCommand extends Command
} }
private function createOrUpdate($formManager, $formId, $data) { private function createOrUpdate($formManager, $formId, $data) {
echo $formId.": ".$data['bn_label_nature'];
$existingForm = $formManager->getOne($formId); $existingForm = $formManager->getOne($formId);
if ($existingForm) if ($existingForm)
return $formManager->update($data); return $formManager->update($data);
@ -66,9 +73,8 @@ class CreateFormsCommand extends Command
private function absencesForm(FormManager $formManager, $meeo_config) private function absencesForm(FormManager $formManager, $meeo_config)
{ {
$formId = $meeo_config['absencesFormId'];
$data = [ $data = [
"bn_id_nature" => $formId, "bn_id_nature" => $this->absenceFormId,
"bn_label_nature" => "Absences", "bn_label_nature" => "Absences",
"bn_description" => "Absences des élèves", "bn_description" => "Absences des élèves",
"bn_condition" => "", "bn_condition" => "",
@ -87,7 +93,7 @@ EOT,
"bn_only_one_entry_message" => null "bn_only_one_entry_message" => null
]; ];
$this->createOrUpdate($formManager, $formId, $data); $this->createOrUpdate($formManager, $this->absenceFormId, $data);
} }
private function matiereList() private function matiereList()
@ -106,12 +112,10 @@ EOT,
private function notesForm(FormManager $formManager, $meeo_config) private function notesForm(FormManager $formManager, $meeo_config)
{ {
$formId = $meeo_config['notesFormId'];
$this->matiereList(); $this->matiereList();
$data = [ $data = [
"bn_id_nature" => $formId, "bn_id_nature" => $this->notesFormId,
"bn_label_nature" => "Notes", "bn_label_nature" => "Notes",
"bn_description" => "Notes des élèves", "bn_description" => "Notes des élèves",
"bn_condition" => "", "bn_condition" => "",
@ -131,7 +135,7 @@ EOT,
"bn_only_one_entry_message" => null "bn_only_one_entry_message" => null
]; ];
$this->createOrUpdate($formManager, $formId, $data); $this->createOrUpdate($formManager, $this->notesFormId, $data);
} }
private function classeList() private function classeList()
@ -149,13 +153,10 @@ EOT,
} }
private function elevesForms(FormManager $formManager, $meeo_config) { private function elevesForms(FormManager $formManager, $meeo_config) {
$formId = $meeo_config['elevesFormId'];
$this->classeList(); $this->classeList();
$data = [ $data = [
"bn_id_nature" => $formId, "bn_id_nature" => $this->eleveFormId,
"bn_label_nature" => "Eleves", "bn_label_nature" => "Eleves",
"bn_description" => "Liste des élèves", "bn_description" => "Liste des élèves",
"bn_condition" => "", "bn_condition" => "",
@ -172,7 +173,7 @@ EOT,
"bn_only_one_entry_message" => null "bn_only_one_entry_message" => null
]; ];
$this->createOrUpdate($formManager, $formId, $data); $this->createOrUpdate($formManager, $this->eleveFormId, $data);
} }
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)

View file

@ -4,7 +4,7 @@ parameters:
absencesFormId: 7 absencesFormId: 7
notesFormId: 8 notesFormId: 8
yunohostFormId: 5 yunohostFormId: 5
groupeEE: 'EquipeEducative' groupeEE: 'equipeeducative'
redirect: redirect:
eleveUpdate: '?Eleves' eleveUpdate: '?Eleves'
controle: '?Bulletin' controle: '?Bulletin'

View file

@ -1,13 +1,19 @@
<?php <?php
namespace YesWiki\Meeo\Controller; 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\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
use YesWiki\Core\ApiResponse; use YesWiki\Core\ApiResponse;
use YesWiki\Core\Controller\AuthController;
use YesWiki\Core\YesWikiController; use YesWiki\Core\YesWikiController;
use YesWiki\Meeo\Controle\Controle; use YesWiki\Meeo\Controle\Controle;
use YesWiki\Meeo\Service\AbsenceManager;
use YesWiki\Meeo\Service\EleveManager; use YesWiki\Meeo\Service\EleveManager;
use YesWiki\Meeo\Service\NoteManager; use YesWiki\Meeo\Service\NoteManager;
@ -15,14 +21,17 @@ class ApiController extends YesWikiController
{ {
private $redirectParams; private $redirectParams;
public function __construct(ParameterBagInterface $params) { public function __construct() {
$this->redirectParams = $params->get('meeo')['redirect'];
} }
/** /**
* @Route("/api/meeo/eleves",methods={"POST"},options={"acl":{"public"}}) * @Route("/api/meeo/eleves",methods={"POST"},options={"acl":{"public"}})
*/ */
public function eleveUpdate(Request $request) { public function eleveUpdate(Request $request) {
$params = $this->getService(ParameterBagInterface::class);
$redirectParams = $params->get('meeo')['redirect'];
$eleveController = $this->getService(EleveManager::class); $eleveController = $this->getService(EleveManager::class);
$content = $request->getContent(); $content = $request->getContent();
@ -43,13 +52,16 @@ class ApiController extends YesWikiController
} }
} }
// return new ApiResponse($data); // return new ApiResponse($data);
return $this->wiki->redirect($this->redirectParams['eleveUpdate'], 200); return $this->wiki->redirect($redirectParams['eleveUpdate'], 200);
} }
/** /**
* @Route("/api/meeo/controle",methods={"POST"},options={"acl":{"public"}}) * @Route("/api/meeo/controle",methods={"POST"},options={"acl":{"public"}})
*/ */
public function controle(Request $request) { public function controle(Request $request) {
$params = $this->getService(ParameterBagInterface::class);
$redirectParams = $params->get('meeo')['redirect'];
$noteManager = $this->getService(NoteManager::class); $noteManager = $this->getService(NoteManager::class);
$content = $request->getContent(); $content = $request->getContent();
@ -64,18 +76,43 @@ class ApiController extends YesWikiController
$controle = new Controle($parameters['intitule'], $parameters['matiere'], $parameters['coef'], $eleves); $controle = new Controle($parameters['intitule'], $parameters['matiere'], $parameters['coef'], $eleves);
$controle->createNotes($noteManager); $controle->createNotes($noteManager);
// return new ApiResponse($controle); // return new ApiResponse($controle);
return $this->wiki->redirect($this->redirectParams['controle'], 200); return $this->wiki->redirect($redirectParams['controle'], 200);
} }
/** /**
* @Route("/api/meeo/absence",methods={"POST"},options={"acl":{"public"}}) * @Route("/api/meeo/absence",methods={"POST"},options={"acl":{"public"}})
*/ */
public function absence(Request $request) { public function absence(Request $request) {
// $noteManager = $this->getService(NoteManager::class); $params = $this->getService(ParameterBagInterface::class);
$redirectParams = $params->get('meeo')['redirect'];
$content = $request->getContent(); $content = $request->getContent();
parse_str($content, $parameters); parse_str($content, $parameters);
return new ApiResponse($parameters); // Créer l'absence dans bazar
// return $this->wiki->redirect($this->redirectParams['absence'], 200); $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($redirectParams['absence'], 200);
} }
} }

View file

@ -18,8 +18,9 @@ class Bulletin {
$listManager = $wiki->services->get(ListManager::class); $listManager = $wiki->services->get(ListManager::class);
$matieres = $listManager->getOne('ListeMatiere'); $matieres = $listManager->getOne('ListeMatiere');
// echo "<p>".var_dump($matieres)."</p>"; // echo "<p>".var_dump($matieres)."</p>";
foreach ($matieres['nodes'] as $matiere) { foreach ($matieres['label'] as $id => $matiere) {
$this->matieres[] = new Matiere($wiki, $this, $matiere["id"], $matiere["label"]); // echo "<p>".$id."</pd>";
$this->matieres[] = new Matiere($wiki, $this, $id, $matiere);
} }
} }

View file

@ -8,15 +8,10 @@ class Eleve {
private $data; private $data;
private $user; private $user;
public function __construct(EntryManager $entryManager, $data) { public function __construct(EntryManager $entryManager, $yunoshostFormId, $data) {
$this->data = $data; $this->data = $data;
// echo "<p>".var_dump($data)."</p>"; // echo "<p>".var_dump($data)."</p>";
//TODO récupérer le bon numéro de liste $userId = $data['listefiche'.$yunoshostFormId.'Listebf_nom'];
if (empty($data['listefiche5Listebf_nom']))
$userId = $data['listefichebf_nom'];
else
$userId = $data['listefiche5Listebf_nom'];
$this->user = $entryManager->getOne($userId); $this->user = $entryManager->getOne($userId);
// echo "<p>".var_dump($this)."</p>"; // echo "<p>".var_dump($this)."</p>";
@ -26,6 +21,10 @@ class Eleve {
return $this->data['id_fiche']; return $this->data['id_fiche'];
} }
public function getUserId() {
return $this->user['bf_titre'];
}
public function getNom() { public function getNom() {
if (empty($this->user['bf_nom'])) { if (empty($this->user['bf_nom'])) {
return $this->user['bf_titre']; return $this->user['bf_titre'];
@ -45,6 +44,10 @@ class Eleve {
$this->data['listeListeClassesbf_classe'] = $classe; $this->data['listeListeClassesbf_classe'] = $classe;
} }
public function getEmail() {
return $this->user['bf_mail'];
}
public function getData() { public function getData() {
return $this->data; 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

@ -13,6 +13,7 @@ use YesWiki\Meeo\Eleve\Eleve;
class EleveManager { class EleveManager {
private $formId; private $formId;
private $yunoshostFormId;
private $entryManager; private $entryManager;
private $listManager; private $listManager;
private $wiki; private $wiki;
@ -22,6 +23,7 @@ class EleveManager {
$meeo_config = $params->get('meeo'); $meeo_config = $params->get('meeo');
$this->wiki = $wiki; $this->wiki = $wiki;
$this->formId = $meeo_config['elevesFormId']; $this->formId = $meeo_config['elevesFormId'];
$this->yunoshostFormId = $meeo_config['yunohostFormId'];
$this->entryManager = $entryManager; $this->entryManager = $entryManager;
$this->listManager = $listManager; $this->listManager = $listManager;
} }
@ -42,8 +44,7 @@ class EleveManager {
$eleves = []; $eleves = [];
foreach ($this->entryManager->search(['formsIds' => $this->formId]) as $data) foreach ($this->entryManager->search(['formsIds' => $this->formId]) as $data)
{ {
$eleve = new Eleve($this->entryManager, $this->yunoshostFormId, $data);
$eleve = new Eleve($this->entryManager, $data);
// echo "<p>".var_dump($eleve)."</p>"; // echo "<p>".var_dump($eleve)."</p>";
$eleves[] = $eleve; $eleves[] = $eleve;
} }
@ -51,11 +52,16 @@ class EleveManager {
} }
public function getEleve(string $id) { public function getEleve(string $id) {
return new Eleve($this->entryManager, $this->entryManager->getOne($id)); return new Eleve($this->entryManager, $this->yunoshostFormId, $this->entryManager->getOne($id));
} }
public function getCurrentEleve(string $username) { public function getCurrentEleve(string $username) {
return $this->entryManager->getOne(str_replace(".","", $username)); $all = $this->getAll();
foreach ($all as $eleve) {
echo "<p>".var_dump($eleve)."</p>";
if ($eleve->getUserId() == $username)
return $eleve;
}
} }
public function view() { public function view() {
@ -64,6 +70,6 @@ class EleveManager {
$classes = $this->listManager->getOne('ListeClasses'); $classes = $this->listManager->getOne('ListeClasses');
// echo "<p>".var_dump($classes)."</p>"; // echo "<p>".var_dump($classes)."</p>";
return $this->wiki->render('@meeo/edu_eleves.twig', ['eleves' => $eleves, 'classes' => $classes['nodes']]); return $this->wiki->render('@meeo/edu_eleves.twig', ['eleves' => $eleves, 'classes' => $classes['label']]);
} }
} }

View file

@ -5,6 +5,7 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use YesWiki\Bazar\Service\EntryManager; use YesWiki\Bazar\Service\EntryManager;
use YesWiki\Bazar\Service\ListManager; use YesWiki\Bazar\Service\ListManager;
use YesWiki\Core\Controller\AuthController; use YesWiki\Core\Controller\AuthController;
use YesWiki\Core\Service\UserManager;
use YesWiki\Wiki; use YesWiki\Wiki;
use YesWiki\Meeo\Bulletin\Bulletin; use YesWiki\Meeo\Bulletin\Bulletin;
use YesWiki\Meeo\Service\EleveManager; use YesWiki\Meeo\Service\EleveManager;
@ -16,31 +17,35 @@ class NoteManager {
protected $listManager; protected $listManager;
protected $formId; protected $formId;
protected $eleveFormId; protected $eleveFormId;
protected $eeGroup;
protected $authController; protected $authController;
protected $userManager;
public function __construct( Wiki $wiki, ParameterBagInterface $params, EntryManager $entryManager, ListManager $listManager, AuthController $authController) public function __construct( Wiki $wiki, ParameterBagInterface $params, EntryManager $entryManager, ListManager $listManager, AuthController $authController, UserManager $userManager)
{ {
$this->wiki = $wiki; $this->wiki = $wiki;
$this->params = $params; $this->params = $params;
$this->entryManager = $entryManager; $this->entryManager = $entryManager;
$this->listManager = $listManager; $this->listManager = $listManager;
$this->authController = $authController; $this->authController = $authController;
$this->userManager = $userManager;
$meeo_config = $this->params->get('meeo'); $meeo_config = $this->params->get('meeo');
$this->formId = $meeo_config['notesFormId']; $this->formId = $meeo_config['notesFormId'];
$this->eleveFormId = $meeo_config['elevesFormId']; $this->eleveFormId = $meeo_config['elevesFormId'];
$this->eeGroup = $meeo_config['groupeEE'];
} }
public function viewBulletins() { public function viewBulletins() {
$eleveManager = $this->wiki->services->get(EleveManager::class); $eleveManager = $this->wiki->services->get(EleveManager::class);
$username = $this->authController->getLoggedUserName();
// echo "<p>".$username."</p>"; // echo "<p>".$username."</p>";
include 'tools/meeo/libs/bulletin/Bulletin.lib.php'; include 'tools/meeo/libs/bulletin/Bulletin.lib.php';
$currentEleve = $eleveManager->getCurrentEleve($username); $loggedUser = $this->authController->getLoggedUser();
// echo "<p>".var_dump($currentEleve)."</p>"; echo "<p>".var_dump($loggedUser)."</p>";
// if ($currentEleve == null) { if ($this->userManager->isInGroup($this->eeGroup, $loggedUser['name'], false)) {
$eleves = $eleveManager->getAll(); $eleves = $eleveManager->getAll();
$bulletins = []; $bulletins = [];
@ -53,12 +58,16 @@ class NoteManager {
return $this->wiki->render('@meeo/edu_notes.twig', [ return $this->wiki->render('@meeo/edu_notes.twig', [
"bulletins" => $bulletins, "bulletins" => $bulletins,
]); ]);
// } else { } else {
// $bulletin = new Bulletin($this->wiki, $currentEleve); echo "Eleve";
// return $this->wiki->render('@meeo/eleve_notes.twig', [ $currentEleve = $eleveManager->getCurrentEleve($loggedUser['name']);
// "bulletin" => $bulletin, if ($currentEleve != null) {
// ]); $bulletin = new Bulletin($this->wiki, $currentEleve);
// } return $this->wiki->render('@meeo/eleve_notes.twig', [
"bulletin" => $bulletin,
]);
}
}
} }
public function viewControle() { public function viewControle() {
@ -68,7 +77,7 @@ class NoteManager {
// echo var_dump($matieres); // echo var_dump($matieres);
$classes = $this->listManager->getOne('ListeClasses'); $classes = $this->listManager->getOne('ListeClasses');
// echo var_dump($classes); // echo var_dump($classes);
return $this->wiki->render('@meeo/edu_controle.twig', ['matieres' => $matieres['nodes'], 'classes' => $classes['nodes'], 'eleves' => $eleves]); return $this->wiki->render('@meeo/edu_controle.twig', ['matieres' => $matieres['label'], 'classes' => $classes['label'], 'eleves' => $eleves]);
} }
public function createNote($intitule, $eleve, $matiere, $note, $coef) { public function createNote($intitule, $eleve, $matiere, $note, $coef) {

View file

@ -11,8 +11,8 @@
<label class="control-label col-sm-2" for="matiere">Matière:</label> <label class="control-label col-sm-2" for="matiere">Matière:</label>
<div class="col-sm-10"> <div class="col-sm-10">
<select class="form-control" id="matiere" name="matiere" required> <select class="form-control" id="matiere" name="matiere" required>
{% for matiere in matieres %} {% for id, matiere in matieres %}
<option value="{{ matiere['id'] }}">{{ matiere['label'] }}</option> <option value="{{ id }}">{{ matiere }}</option>
{% endfor %} {% endfor %}
</select> </select>
</div> </div>
@ -21,8 +21,8 @@
<label class="control-label col-sm-2" for="classe">Classe:</label> <label class="control-label col-sm-2" for="classe">Classe:</label>
<div class="col-sm-10"> <div class="col-sm-10">
<select class="form-control" id="classe" name="classe" required> <select class="form-control" id="classe" name="classe" required>
{% for classe in classes %} {% for id, classe in classes %}
<option value="{{ classe['id'] }}" >{{ classe['label'] }}</option> <option value="{{ id }}" >{{ classe }}</option>
{% endfor %} {% endfor %}
</select> </select>
</div> </div>

View file

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

View file

@ -10,8 +10,8 @@
<div class="col-sm-8">{{ eleve.getNom() }}</div> <div class="col-sm-8">{{ eleve.getNom() }}</div>
<div class="col-sm-3"> <div class="col-sm-3">
<select id="{{ eleve.getId() }}_classe" name="{{ eleve.getId() }}_classe" class="form-control"> <select id="{{ eleve.getId() }}_classe" name="{{ eleve.getId() }}_classe" class="form-control">
{% for classe in classes %} {% for id, classe in classes %}
<option value="{{classe['id']}}" {% if eleve.classe == classe['id'] %}selected{% endif %} >{{classe['label']}}</option> <option value="{{id}}" {% if eleve.classe == id %}selected{% endif %} >{{classe}}</option>
{% endfor %} {% endfor %}
</select> </select>
</div> </div>

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>