diff --git a/actions/ElevesAction.php b/actions/ElevesAction.php index 2c8c739..3c869f3 100644 --- a/actions/ElevesAction.php +++ b/actions/ElevesAction.php @@ -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"; + } } } \ No newline at end of file diff --git a/actions/NotesAction.php b/actions/NotesAction.php index 68ff53d..5c9e437 100644 --- a/actions/NotesAction.php +++ b/actions/NotesAction.php @@ -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"; + } + } } diff --git a/commands/CreateFormsCommand.php b/commands/CreateFormsCommand.php index 4323bc9..6797db6 100644 --- a/commands/CreateFormsCommand.php +++ b/commands/CreateFormsCommand.php @@ -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) diff --git a/config.yaml b/config.yaml index c383eb5..f1b0252 100644 --- a/config.yaml +++ b/config.yaml @@ -4,7 +4,7 @@ parameters: absencesFormId: 7 notesFormId: 8 yunohostFormId: 5 - groupeEE: 'EquipeEducative' + groupeEE: 'equipeeducative' redirect: eleveUpdate: '?Eleves' controle: '?Bulletin' diff --git a/controllers/ApiController.php b/controllers/ApiController.php index d60637e..b71e7db 100644 --- a/controllers/ApiController.php +++ b/controllers/ApiController.php @@ -1,13 +1,19 @@ 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); } } \ No newline at end of file diff --git a/libs/bulletin/Bulletin.lib.php b/libs/bulletin/Bulletin.lib.php index ae4c7fd..1b035bd 100644 --- a/libs/bulletin/Bulletin.lib.php +++ b/libs/bulletin/Bulletin.lib.php @@ -18,8 +18,9 @@ class Bulletin { $listManager = $wiki->services->get(ListManager::class); $matieres = $listManager->getOne('ListeMatiere'); // echo "

".var_dump($matieres)."

"; - foreach ($matieres['nodes'] as $matiere) { - $this->matieres[] = new Matiere($wiki, $this, $matiere["id"], $matiere["label"]); + foreach ($matieres['label'] as $id => $matiere) { + // echo "

".$id.""; + $this->matieres[] = new Matiere($wiki, $this, $id, $matiere); } } diff --git a/libs/eleves/eleve.lib.php b/libs/eleves/eleve.lib.php index 904f2af..e3afe92 100644 --- a/libs/eleves/eleve.lib.php +++ b/libs/eleves/eleve.lib.php @@ -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 "

".var_dump($data)."

"; - //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 "

".var_dump($this)."

"; @@ -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; } diff --git a/services/AbsenceManager.php b/services/AbsenceManager.php new file mode 100644 index 0000000..9650f77 --- /dev/null +++ b/services/AbsenceManager.php @@ -0,0 +1,40 @@ +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); + } +} \ No newline at end of file diff --git a/services/EleveManager.php b/services/EleveManager.php index 153af8a..a1a4f80 100644 --- a/services/EleveManager.php +++ b/services/EleveManager.php @@ -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 "

".var_dump($eleve)."

"; $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 "

".var_dump($eleve)."

"; + if ($eleve->getUserId() == $username) + return $eleve; + } } public function view() { @@ -64,6 +70,6 @@ class EleveManager { $classes = $this->listManager->getOne('ListeClasses'); // echo "

".var_dump($classes)."

"; - 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']]); } } diff --git a/services/NoteManager.php b/services/NoteManager.php index 74407a7..f390823 100644 --- a/services/NoteManager.php +++ b/services/NoteManager.php @@ -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 "

".$username."

"; include 'tools/meeo/libs/bulletin/Bulletin.lib.php'; - $currentEleve = $eleveManager->getCurrentEleve($username); - // echo "

".var_dump($currentEleve)."

"; - // if ($currentEleve == null) { + $loggedUser = $this->authController->getLoggedUser(); + echo "

".var_dump($loggedUser)."

"; + 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) { diff --git a/templates/edu_controle.twig b/templates/edu_controle.twig index 63d1db5..509f387 100644 --- a/templates/edu_controle.twig +++ b/templates/edu_controle.twig @@ -11,8 +11,8 @@
@@ -21,8 +21,8 @@
diff --git a/templates/edu_creer_absence.twig b/templates/edu_creer_absence.twig index d42fe0e..1938416 100644 --- a/templates/edu_creer_absence.twig +++ b/templates/edu_creer_absence.twig @@ -21,10 +21,10 @@ -
- +
+
- +
diff --git a/templates/edu_eleves.twig b/templates/edu_eleves.twig index 1c1f751..ba3bd7a 100644 --- a/templates/edu_eleves.twig +++ b/templates/edu_eleves.twig @@ -10,8 +10,8 @@
{{ eleve.getNom() }}
diff --git a/templates/eleve_creer_absence.twig b/templates/eleve_creer_absence.twig new file mode 100644 index 0000000..de17e68 --- /dev/null +++ b/templates/eleve_creer_absence.twig @@ -0,0 +1,9 @@ +Le message sera à voir avec l'équipe educative. + +
+

Bonjour {{ eleve.getNom() }},

+ +

Nous vous signalons que votre enfant a été absent {{ absence['date_debut_absence']}}.

+ +

Merci d'en prendre note.

+
\ No newline at end of file