ynh_extension_meeo/services/NoteManager.php

117 lines
3.8 KiB
PHP
Raw Normal View History

2024-07-19 14:52:37 +00:00
<?php
namespace YesWiki\Meeo\Service;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use YesWiki\Bazar\Service\EntryManager;
use YesWiki\Bazar\Service\ListManager;
use YesWiki\Core\Controller\AuthController;
2024-08-05 17:02:45 +00:00
use YesWiki\Core\Service\UserManager;
2024-07-19 14:52:37 +00:00
use YesWiki\Wiki;
use YesWiki\Meeo\Bulletin\Bulletin;
2024-07-20 08:13:50 +00:00
use YesWiki\Meeo\Service\EleveManager;
2024-07-19 14:52:37 +00:00
class NoteManager {
protected $wiki;
protected $params;
protected $entryManager;
protected $listManager;
protected $formId;
protected $eleveFormId;
2024-08-05 17:02:45 +00:00
protected $eeGroup;
protected $authController;
2024-08-05 17:02:45 +00:00
protected $userManager;
2024-07-19 14:52:37 +00:00
2024-08-05 17:02:45 +00:00
public function __construct( Wiki $wiki, ParameterBagInterface $params, EntryManager $entryManager, ListManager $listManager, AuthController $authController, UserManager $userManager)
2024-07-19 14:52:37 +00:00
{
$this->wiki = $wiki;
$this->params = $params;
$this->entryManager = $entryManager;
$this->listManager = $listManager;
$this->authController = $authController;
2024-08-05 17:02:45 +00:00
$this->userManager = $userManager;
$meeo_config = $this->params->get('meeo');
$this->formId = $meeo_config['notesFormId'];
$this->eleveFormId = $meeo_config['elevesFormId'];
2024-08-05 17:02:45 +00:00
$this->eeGroup = $meeo_config['groupeEE'];
2024-07-19 14:52:37 +00:00
}
public function viewBulletins() {
2024-07-27 15:19:40 +00:00
$eleveManager = $this->wiki->services->get(EleveManager::class);
2024-07-19 14:52:37 +00:00
include 'tools/meeo/libs/bulletin/Bulletin.lib.php';
2024-07-19 14:52:37 +00:00
2024-08-05 17:02:45 +00:00
$loggedUser = $this->authController->getLoggedUser();
2024-08-06 06:21:13 +00:00
// echo "<p>".var_dump($loggedUser)."</p>";
2024-08-05 17:02:45 +00:00
if ($this->userManager->isInGroup($this->eeGroup, $loggedUser['name'], false)) {
2024-07-27 15:19:40 +00:00
$eleves = $eleveManager->getAll();
2024-07-19 14:52:37 +00:00
2024-07-27 15:19:40 +00:00
$bulletins = [];
foreach ( $eleves as $eleve) {
2024-07-27 15:37:51 +00:00
$bulletins[] = new Bulletin($this->wiki, $eleve);
2024-07-27 15:19:40 +00:00
}
// echo "<p>".var_dump($eleves)."</p>";
// echo "<p>".var_dump($bulletins)."</p>";
2024-07-19 14:52:37 +00:00
2024-07-27 15:19:40 +00:00
return $this->wiki->render('@meeo/edu_notes.twig', [
"bulletins" => $bulletins,
]);
2024-08-05 17:02:45 +00:00
} else {
2024-08-06 06:19:59 +00:00
// echo "Eleve";
2024-08-05 17:02:45 +00:00
$currentEleve = $eleveManager->getCurrentEleve($loggedUser['name']);
if ($currentEleve != null) {
$bulletin = new Bulletin($this->wiki, $currentEleve);
return $this->wiki->render('@meeo/eleve_notes.twig', [
"bulletin" => $bulletin,
]);
}
}
2024-07-19 14:52:37 +00:00
}
2024-07-20 08:13:50 +00:00
public function viewControle() {
$eleves = $this->wiki->services->get(EleveManager::class)->getAll();
// echo var_dump($eleves);
$matieres = $this->listManager->getOne('ListeMatiere');
// echo var_dump($matieres);
$classes = $this->listManager->getOne('ListeClasses');
2024-09-11 06:47:50 +00:00
$notesMax = $this->listManager->getOne('ListeNoteMax');
2024-07-20 08:13:50 +00:00
// echo var_dump($classes);
2024-09-11 06:47:50 +00:00
return $this->wiki->render('@meeo/edu_controle.twig', [
'matieres' => $matieres['label'],
'classes' => $classes['label'],
'notesMax' => $notesMax['label'],
'eleves' => $eleves,
]);
}
2024-09-11 06:47:50 +00:00
public function createNote($intitule, $eleve, $matiere, $note, $max, $coef) {
2024-07-27 15:37:51 +00:00
if ($note == 0)
return;
$data = [
'bf_titre' => "Note : ".$intitule." - ".$eleve." - ".$matiere,
'bf_intitule' => $intitule,
'listeListeMatierebf_matiere' => $matiere,
2024-09-23 14:46:39 +00:00
'listeListeNotemaxbf_notemax' => $max,
'listefiche'.$this->eleveFormId.'bf_eleve' => $eleve,
'bf_note' => $note,
'bf_coef' => $coef,
'antispam' => true
];
2024-07-27 15:37:51 +00:00
$this->entryManager->create($this->formId, $data);
}
public function getNotes($eleveId, $matiereId) {
2024-07-27 15:37:51 +00:00
// echo "<p>".$eleveId."</p>";
// echo "<p>".$matiereId."</p>";
$entries = $this->entryManager->search(['formsIds' => $this->formId,
'queries' =>[
2024-07-27 15:19:40 +00:00
'listefiche'.$this->eleveFormId.'bf_eleve' => \strtolower($eleveId),
'listeListeMatierebf_matiere' => $matiereId
]
]);
// echo "<p>".var_dump($entries)."</p>";
return $entries;
}
2024-08-06 06:19:59 +00:00
}