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

View file

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

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;
@ -15,14 +21,17 @@ class ApiController extends YesWikiController
{
private $redirectParams;
public function __construct(ParameterBagInterface $params) {
$this->redirectParams = $params->get('meeo')['redirect'];
public function __construct() {
}
/**
* @Route("/api/meeo/eleves",methods={"POST"},options={"acl":{"public"}})
*/
public function eleveUpdate(Request $request) {
$params = $this->getService(ParameterBagInterface::class);
$redirectParams = $params->get('meeo')['redirect'];
$eleveController = $this->getService(EleveManager::class);
$content = $request->getContent();
@ -43,13 +52,16 @@ class ApiController extends YesWikiController
}
}
// 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"}})
*/
public function controle(Request $request) {
$params = $this->getService(ParameterBagInterface::class);
$redirectParams = $params->get('meeo')['redirect'];
$noteManager = $this->getService(NoteManager::class);
$content = $request->getContent();
@ -64,18 +76,43 @@ class ApiController extends YesWikiController
$controle = new Controle($parameters['intitule'], $parameters['matiere'], $parameters['coef'], $eleves);
$controle->createNotes($noteManager);
// 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"}})
*/
public function absence(Request $request) {
// $noteManager = $this->getService(NoteManager::class);
$params = $this->getService(ParameterBagInterface::class);
$redirectParams = $params->get('meeo')['redirect'];
$content = $request->getContent();
parse_str($content, $parameters);
return new ApiResponse($parameters);
// return $this->wiki->redirect($this->redirectParams['absence'], 200);
// 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($redirectParams['absence'], 200);
}
}

View file

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

View file

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

@ -13,6 +13,7 @@ use YesWiki\Meeo\Eleve\Eleve;
class EleveManager {
private $formId;
private $yunoshostFormId;
private $entryManager;
private $listManager;
private $wiki;
@ -22,6 +23,7 @@ class EleveManager {
$meeo_config = $params->get('meeo');
$this->wiki = $wiki;
$this->formId = $meeo_config['elevesFormId'];
$this->yunoshostFormId = $meeo_config['yunohostFormId'];
$this->entryManager = $entryManager;
$this->listManager = $listManager;
}
@ -42,8 +44,7 @@ class EleveManager {
$eleves = [];
foreach ($this->entryManager->search(['formsIds' => $this->formId]) as $data)
{
$eleve = new Eleve($this->entryManager, $data);
$eleve = new Eleve($this->entryManager, $this->yunoshostFormId, $data);
// echo "<p>".var_dump($eleve)."</p>";
$eleves[] = $eleve;
}
@ -51,11 +52,16 @@ class EleveManager {
}
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) {
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() {
@ -64,6 +70,6 @@ class EleveManager {
$classes = $this->listManager->getOne('ListeClasses');
// 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\ListManager;
use YesWiki\Core\Controller\AuthController;
use YesWiki\Core\Service\UserManager;
use YesWiki\Wiki;
use YesWiki\Meeo\Bulletin\Bulletin;
use YesWiki\Meeo\Service\EleveManager;
@ -16,31 +17,35 @@ class NoteManager {
protected $listManager;
protected $formId;
protected $eleveFormId;
protected $eeGroup;
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->params = $params;
$this->entryManager = $entryManager;
$this->listManager = $listManager;
$this->authController = $authController;
$this->userManager = $userManager;
$meeo_config = $this->params->get('meeo');
$this->formId = $meeo_config['notesFormId'];
$this->eleveFormId = $meeo_config['elevesFormId'];
$this->eeGroup = $meeo_config['groupeEE'];
}
public function viewBulletins() {
$eleveManager = $this->wiki->services->get(EleveManager::class);
$username = $this->authController->getLoggedUserName();
// echo "<p>".$username."</p>";
include 'tools/meeo/libs/bulletin/Bulletin.lib.php';
$currentEleve = $eleveManager->getCurrentEleve($username);
// echo "<p>".var_dump($currentEleve)."</p>";
// if ($currentEleve == null) {
$loggedUser = $this->authController->getLoggedUser();
echo "<p>".var_dump($loggedUser)."</p>";
if ($this->userManager->isInGroup($this->eeGroup, $loggedUser['name'], false)) {
$eleves = $eleveManager->getAll();
$bulletins = [];
@ -53,12 +58,16 @@ class NoteManager {
return $this->wiki->render('@meeo/edu_notes.twig', [
"bulletins" => $bulletins,
]);
// } else {
// $bulletin = new Bulletin($this->wiki, $currentEleve);
// return $this->wiki->render('@meeo/eleve_notes.twig', [
// "bulletin" => $bulletin,
// ]);
// }
} else {
echo "Eleve";
$currentEleve = $eleveManager->getCurrentEleve($loggedUser['name']);
if ($currentEleve != null) {
$bulletin = new Bulletin($this->wiki, $currentEleve);
return $this->wiki->render('@meeo/eleve_notes.twig', [
"bulletin" => $bulletin,
]);
}
}
}
public function viewControle() {
@ -68,7 +77,7 @@ class NoteManager {
// echo var_dump($matieres);
$classes = $this->listManager->getOne('ListeClasses');
// 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) {

View file

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

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

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