From 2b2be5166ef113d598427c47236898dfc224ce1c Mon Sep 17 00:00:00 2001 From: Mickael Veaudour Date: Tue, 5 Nov 2024 11:05:51 +0100 Subject: [PATCH] Group bulletin par classe --- libs/classes/Classe.lib.php | 40 +++++++++++++++++++++++++++++++++++++ services/NoteManager.php | 28 ++++++++++++++++++-------- templates/edu_notes.twig | 23 +++++++++++++++------ 3 files changed, 77 insertions(+), 14 deletions(-) create mode 100644 libs/classes/Classe.lib.php diff --git a/libs/classes/Classe.lib.php b/libs/classes/Classe.lib.php new file mode 100644 index 0000000..d320c55 --- /dev/null +++ b/libs/classes/Classe.lib.php @@ -0,0 +1,40 @@ +id = $id; + $this->name = $name; + + $noteManager = $wiki->services->get(NoteManager::class); + foreach ($noteManager->allBulletins() as $bulletin) { + if ($bulletin->getClasse() == $this->id) { + array_push($this->bulletins, $bulletin); + } + } + } + + public function getId() { + return $this->id; + } + + public function getName() { + return $this->name; + } + + public function getBulletins() { + return $this->bulletins; + } + + public function haveBulletins(){ + return sizeof($this->bulletins) > 0; + } +} \ No newline at end of file diff --git a/services/NoteManager.php b/services/NoteManager.php index 920580b..c211f63 100644 --- a/services/NoteManager.php +++ b/services/NoteManager.php @@ -9,6 +9,7 @@ use YesWiki\Core\Service\UserManager; use YesWiki\Wiki; use YesWiki\Meeo\Bulletin\Bulletin; use YesWiki\Meeo\Service\EleveManager; +use YesWiki\Meeo\Classes\Classe; class NoteManager { protected $wiki; @@ -36,26 +37,37 @@ class NoteManager { $this->eeGroup = $meeo_config['groupeEE']; } + public function allBulletins() { + $eleveManager = $this->wiki->services->get(EleveManager::class); + $eleves = $eleveManager->getAll(); + + $bulletins = []; + foreach ( $eleves as $eleve) { + $bulletins[] = new Bulletin($this->wiki, $eleve); + } + return $bulletins; + } + public function viewBulletins() { $eleveManager = $this->wiki->services->get(EleveManager::class); include 'tools/meeo/libs/bulletin/Bulletin.lib.php'; + include 'tools/meeo/libs/classes/Classe.lib.php'; $loggedUser = $this->authController->getLoggedUser(); // echo "

".var_dump($loggedUser)."

"; if (true) {//($this->userManager->isInGroup($this->eeGroup, $loggedUser['name'], false)) { - $eleves = $eleveManager->getAll(); - - $bulletins = []; - foreach ( $eleves as $eleve) { - $bulletins[] = new Bulletin($this->wiki, $eleve); - } // echo "

".var_dump($eleves)."

"; // echo "

".var_dump($bulletins)."

"; - + $classes = []; + $listClasse = $this->listManager->getOne('ListeClasses'); + foreach ($listClasse['label'] as $id => $classe) { + array_push($classes, new Classe($this->wiki, $id, $classe)); + } + // echo "

".var_dump($classes)."

"; return $this->wiki->render('@meeo/edu_notes.twig', [ - "bulletins" => $bulletins, + "classes" => $classes, "opened" => "" ]); } else { diff --git a/templates/edu_notes.twig b/templates/edu_notes.twig index bb1470c..4c6fdb9 100644 --- a/templates/edu_notes.twig +++ b/templates/edu_notes.twig @@ -1,7 +1,18 @@ -
-{% for bulletin in bulletins|sort %} - {% if bulletin.isVisible() %} - {% include '@meeo/eleve_notes.twig' with { 'bulletin' : bulletin } %} - {% endif %} -{% endfor %} +
+ {% for classe in classes %} + {% if classe.haveBulletins() %} +
+
{{ classe.getName() }}
+
+
+ {% for bulletin in classe.getBulletins() %} + {% if bulletin.isVisible() %} + {% include '@meeo/eleve_notes.twig' with { 'bulletin' : bulletin } %} + {% endif %} + {% endfor %} +
+
+
+ {% endif %} + {% endfor %}