diff --git a/commands/CreateFormsCommand.php b/commands/CreateFormsCommand.php index 71beed5..e587cd0 100644 --- a/commands/CreateFormsCommand.php +++ b/commands/CreateFormsCommand.php @@ -16,11 +16,14 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; class CreateFormsCommand extends Command { protected $wiki; + protected $eleveFormId; public function __construct(Wiki &$wiki) { parent::__construct(); $this->wiki = $wiki; + $meeo_config = $this->wiki->params->get('meeo'); + $this->eleveFormId = $meeo_config['elevesFormId']; } protected function configure() @@ -73,7 +76,7 @@ class CreateFormsCommand extends Command "bn_sem_use_template" => "1", "bn_template" => <<eleveFormId***Elève*** *** *** *** *** ***1*** *** *** * *** * *** *** *** *** listedatedeb***bf_date_debut***Debut*** *** ***today*** *** ***1*** *** *** * *** * *** *** *** *** listedatedeb***bf_date_fin***Fin*** *** ***today*** *** ***1*** *** *** * *** * *** *** *** *** textelong***bf_commentaire***Commentaire*** *** *** *** ***wiki***0*** *** *** * *** * *** *** *** *** @@ -118,7 +121,7 @@ EOT, titre***Note : {{bf_intitule}} - {{bf_eleve}} - {{bf_matiere}}***Titre Automatique*** texte***bf_intitule***Intitulé*** *** *** *** ***text***1*** *** *** * *** * *** *** *** *** liste***ListeMatiere***Matière*** *** *** ***bf_matiere*** ***1*** *** *** * *** * *** *** *** *** -listefiche***6***Elève*** *** *** ***bf_eleve*** ***1*** *** *** * *** * *** *** *** *** +listefiche***$this->eleveFormId***Elève*** *** *** ***bf_eleve*** ***1*** *** *** * *** * *** *** *** *** texte***bf_note***Note***0***20*** *** ***number***1*** *** *** * *** * *** *** *** *** texte***bf_coef***Coefficient***0.5***10***1*** ***number***0*** *** *** * *** * *** *** *** *** EOT, diff --git a/controllers/ApiController.php b/controllers/ApiController.php index 1fcd4e0..7523b81 100644 --- a/controllers/ApiController.php +++ b/controllers/ApiController.php @@ -39,7 +39,7 @@ class ApiController extends YesWikiController * @Route("/api/meeo/controle",methods={"POST"},options={"acl":{"public"}}) */ public function control(Request $request) { - $eleveController = $this->getService(NoteManager::class); + $noteManager = $this->getService(NoteManager::class); $content = $request->getContent(); parse_str($content, $parameters); @@ -51,8 +51,7 @@ class ApiController extends YesWikiController }, ARRAY_FILTER_USE_KEY); $controle = new Controle($parameters['intitule'], $parameters['matiere'], $parameters['coef'], $eleves); - - $eleveController->addNotes($controle->getNotes()); + $controle->createNotes($noteManager); return $this->wiki->redirect('?Notes', 200); } } \ No newline at end of file diff --git a/libs/controle/Controle.lib.php b/libs/controle/Controle.lib.php index 64f11d2..66e01ca 100644 --- a/libs/controle/Controle.lib.php +++ b/libs/controle/Controle.lib.php @@ -2,6 +2,8 @@ namespace YesWiki\MeeO\Controle; +use YesWiki\Meeo\Service\NoteManager; + class Controle { public $intitule; public $matiere; @@ -28,18 +30,9 @@ class Controle { return $outputArray; } - public function getNotes() { - $notes = []; + public function createNotes(NoteManager $noteManager) { foreach ($this->eleves as $eleve => $note) { - $notes[] = [ - 'bf_titre' => "Note : ".$this->intitule." - ".$eleve." - ".$this->matiere, - 'bf_intitule' => $this->intitule, - 'listeListeMatierebf_matiere' => $this->matiere, - 'listefiche6bf_eleve' => $eleve, - 'bf_note' => $note, - 'bf_coef' => $this->coef, - ]; + $noteManager->createNote($this->intitule, $eleve, $this->matiere, $note, $this->coef); }; - return $notes; } } \ No newline at end of file diff --git a/services/NoteManager.php b/services/NoteManager.php index 157f30b..df6dfaa 100644 --- a/services/NoteManager.php +++ b/services/NoteManager.php @@ -16,6 +16,7 @@ class NoteManager { protected $entryManager; protected $listManager; protected $formId; + protected $eleveFormId; protected $authController; public function __construct( Wiki $wiki, ParameterBagInterface $params, EntryManager $entryManager, ListManager $listManager, AuthController $authController) @@ -28,12 +29,10 @@ class NoteManager { $meeo_config = $this->params->get('meeo'); $this->formId = $meeo_config['notesFormId']; + $this->eleveFormId = $meeo_config['elevesFormId']; } public function viewBulletins() { - // $eleveIdentifier = 'listefiche'.$meeo_config['elevesFormId'].'bf_eleve'; - // $groupeEE = $meeo_config['groupeEE']; - $username = $this->authController->getLoggedUserName(); $eleves = $this->wiki->services->get(EleveManager::class)->getAll(); @@ -72,11 +71,17 @@ class NoteManager { return $this->wiki->render('@meeo/edu_controle.twig', ['matieres' => $matieres['label'], 'classes' => $classes['label'], 'eleves' => $eleves]); } - public function addNotes($notes) { - foreach ($notes as $note) { - $note['antispam'] = true; - $this->entryManager->create($this->formId, $note); - } + public function createNote($intitule, $eleve, $matiere, $note, $coef) { + $note = [ + 'bf_titre' => "Note : ".$intitule." - ".$eleve." - ".$matiere, + 'bf_intitule' => $intitule, + 'listeListeMatierebf_matiere' => $matiere, + 'listefiche'.$this->eleveFormId.'bf_eleve' => $eleve, + 'bf_note' => $note, + 'bf_coef' => $coef, + 'antispam' => true + ]; + $this->entryManager->create($this->formId, $note); } public function getNotes($eleveId, $matiereId) { @@ -84,7 +89,7 @@ class NoteManager { // echo "

".$matiereId."

"; $entries = $this->entryManager->search(['formsIds' => $this->formId, 'queries' =>[ - 'listefiche6bf_eleve' => $eleveId, + 'listefiche'.$this->eleveFormId.'bf_eleve' => $eleveId, 'listeListeMatierebf_matiere' => $matiereId ] ]);