Ajout d'un fonction permettant de créer les notes à partir d'un bulletin

This commit is contained in:
mckmonster 2024-07-20 20:58:35 +02:00
parent 43d586f57b
commit 573d5753b2
5 changed files with 83 additions and 21 deletions

View file

@ -117,7 +117,7 @@ EOT,
"bn_template" => <<<EOT "bn_template" => <<<EOT
titre***Note : {{bf_intitule}} - {{bf_eleve}} - {{bf_matiere}}***Titre Automatique*** titre***Note : {{bf_intitule}} - {{bf_eleve}} - {{bf_matiere}}***Titre Automatique***
texte***bf_intitule***Intitulé*** *** *** *** ***text***1*** *** *** * *** * *** *** *** *** texte***bf_intitule***Intitulé*** *** *** *** ***text***1*** *** *** * *** * *** *** *** ***
liste***ListeMatière***Matière*** *** *** ***bf_matiere*** ***1*** *** *** * *** * *** *** *** *** liste***ListeMatiere***Matière*** *** *** ***bf_matiere*** ***1*** *** *** * *** * *** *** *** ***
listefiche***6***Elève*** *** *** ***bf_eleve*** ***1*** *** *** * *** * *** *** *** *** listefiche***6***Elève*** *** *** ***bf_eleve*** ***1*** *** *** * *** * *** *** *** ***
texte***bf_note***Note***0***20*** *** ***number***1*** *** *** * *** * *** *** *** *** texte***bf_note***Note***0***20*** *** ***number***1*** *** *** * *** * *** *** *** ***
texte***bf_coef***Coefficient***0.5***10***1*** ***number***0*** *** *** * *** * *** *** *** *** texte***bf_coef***Coefficient***0.5***10***1*** ***number***0*** *** *** * *** * *** *** *** ***

View file

@ -6,7 +6,9 @@ use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
use YesWiki\Core\ApiResponse; use YesWiki\Core\ApiResponse;
use YesWiki\Core\YesWikiController; use YesWiki\Core\YesWikiController;
use YesWiki\Meeo\Controle\Controle;
use YesWiki\Meeo\Service\EleveManager; use YesWiki\Meeo\Service\EleveManager;
use YesWiki\Meeo\Service\NoteManager;
class ApiController extends YesWikiController class ApiController extends YesWikiController
{ {
@ -32,4 +34,27 @@ class ApiController extends YesWikiController
return $this->wiki->redirect('?Eleves', 200); return $this->wiki->redirect('?Eleves', 200);
} }
/**
* @Route("/api/meeo/controle",methods={"POST"},options={"acl":{"public"}})
*/
public function control(Request $request) {
$eleveController = $this->getService(NoteManager::class);
$content = $request->getContent();
parse_str($content, $parameters);
include 'tools/meeo/libs/controle/Controle.lib.php';
$eleves = array_filter($parameters, function($key) {
return strpos($key, 'eleve_') === 0;
}, ARRAY_FILTER_USE_KEY);
$controle = new Controle($parameters['intitule'], $parameters['matiere'], $parameters['coef'], $eleves);
$eleveController->addNotes($controle->getNotes());
return new ApiResponse(['parameters' => $controle->getNotes()]);
// return $this->wiki->redirect('?Notes', 200);
}
} }

View file

@ -1,18 +1,45 @@
<?php <?php
namespace YesWiki\MeeO\Controle\Controle; namespace YesWiki\MeeO\Controle;
class Control { class Controle {
private $wiki; public $intitule;
private $intitule; public $matiere;
private $matiere; public $coef;
private $coef; public $eleves;
private $eleves;
public function __construct($wiki, $intitule, $matiere, $coef) { public function __construct($intitule, $matiere, $coef, $eleves) {
$this->wiki = $wiki;
$this->intitule = $intitule; $this->intitule = $intitule;
$this->matiere = $matiere; $this->matiere = $matiere;
$this->coef = $coef; $this->coef = $coef;
$this->eleves = $this->removePrefixFromKeys($eleves, "eleve_");
}
function removePrefixFromKeys($inputArray, $prefix) {
$outputArray = array();
foreach ($inputArray as $key => $value) {
if (strpos($key, $prefix) === 0) {
$newKey = substr($key, strlen($prefix)); // Remove the prefix
$outputArray[$newKey] = $value;
} else {
$outputArray[$key] = $value;
}
}
return $outputArray;
}
public function getNotes() {
$notes = [];
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,
];
};
return $notes;
} }
} }

View file

@ -16,6 +16,7 @@ class NoteManager {
protected $entryManager; protected $entryManager;
protected $listManager; protected $listManager;
protected $userManager; protected $userManager;
protected $formId;
public function __construct( Wiki $wiki, ParameterBagInterface $params, EntryManager $entryManager, ListManager $listManager, UserManager $userManager) public function __construct( Wiki $wiki, ParameterBagInterface $params, EntryManager $entryManager, ListManager $listManager, UserManager $userManager)
{ {
@ -24,17 +25,19 @@ class NoteManager {
$this->entryManager = $entryManager; $this->entryManager = $entryManager;
$this->listManager = $listManager; $this->listManager = $listManager;
$this->userManager = $userManager; $this->userManager = $userManager;
$meeo_config = $this->params->get('meeo');
$this->formId = $meeo_config['notesFormId'];
} }
public function viewBulletins() { public function viewBulletins() {
$meeo_config = $this->params->get('meeo');
$formId = $meeo_config['notesFormId'];
$eleveIdentifier = 'listefiche'.$meeo_config['elevesFormId'].'bf_eleve'; $eleveIdentifier = 'listefiche'.$meeo_config['elevesFormId'].'bf_eleve';
$groupeEE = $meeo_config['groupeEE']; $groupeEE = $meeo_config['groupeEE'];
if ( $this->userManager->isInGroup($groupeEE, admincheck: false) ) { if ( $this->userManager->isInGroup($groupeEE, admincheck: false) ) {
$eleves = $this->entryManager->search(['formsIds' => $meeo_config['elevesFormId']]); $eleves = $this->entryManager->search(['formsIds' => $meeo_config['elevesFormId']]);
$entries = $this->entryManager->search(['formsIds' => $formId]); $entries = $this->entryManager->search(['formsIds' => $this->formId]);
include 'tools/meeo/libs/bulletin/Bulletin.lib.php'; include 'tools/meeo/libs/bulletin/Bulletin.lib.php';
@ -50,7 +53,7 @@ class NoteManager {
"bulletins" => $bulletins, "bulletins" => $bulletins,
]); ]);
} else { } else {
$entries = $entryManager->search(['formsIds' => $formId]); $entries = $entryManager->search(['formsIds' => $this->formId]);
return $this->wiki->render('@meeo/eleve_notes.twig', [ return $this->wiki->render('@meeo/eleve_notes.twig', [
"bulletin" => $bulletin, "bulletin" => $bulletin,
@ -67,4 +70,11 @@ class NoteManager {
// echo var_dump($classes); // echo var_dump($classes);
return $this->wiki->render('@meeo/edu_controle.twig', ['matieres' => $matieres['label'], 'classes' => $classes['label'], 'eleves' => $eleves]); 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);
}
}
} }

View file

@ -1,16 +1,16 @@
{{ include_javascript('tools/meeo/javascripts/edu_controle_filter.js') }} {{ include_javascript('tools/meeo/javascripts/edu_controle_filter.js') }}
<form class="form-horizontal"> <form class="form-horizontal" action="?api/meeo/controle" method="post">
<div class="form-group"> <div class="form-group">
<label class="control-label col-sm-2" for="intitule">Intitulé:</label> <label class="control-label col-sm-2" for="intitule">Intitulé:</label>
<div class="col-sm-10"> <div class="col-sm-10">
<input type="text" class="form-control" id="intitule" required> <input type="text" class="form-control" id="intitule" name="intitule" required>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="control-label col-sm-2" for="matiere">Matière:</label> <label class="control-label col-sm-2" for="matiere">Matière:</label>
<div class="col-sm-10"> <div class="col-sm-10">
<select class="form-control" id="matiere" required> <select class="form-control" id="matiere" name="matiere" required>
{% for clef, matiere in matieres %} {% for clef, matiere in matieres %}
<option value="{{ clef }}">{{ matiere }}</option> <option value="{{ clef }}">{{ matiere }}</option>
{% endfor %} {% endfor %}
@ -20,7 +20,7 @@
<div class="form-group"> <div class="form-group">
<label class="control-label col-sm-2" for="classe">Classe:</label> <label class="control-label col-sm-2" for="classe">Classe:</label>
<div class="col-sm-10"> <div class="col-sm-10">
<select class="form-control" id="classe" required> <select class="form-control" id="classe" name="classe" required>
{% for classe in classes %} {% for classe in classes %}
<option>{{ classe }}</option> <option>{{ classe }}</option>
{% endfor %} {% endfor %}
@ -30,17 +30,17 @@
<div class="form-group"> <div class="form-group">
<label class="control-label col-sm-2" for="coef">Coefficient:</label> <label class="control-label col-sm-2" for="coef">Coefficient:</label>
<div class="col-sm-10"> <div class="col-sm-10">
<input type="number" class="form-control" id="coef" value="1" min="0.5" max="10" step="0.5"> <input type="number" class="form-control" id="coef" name="coef" value="1" min="0.5" max="10" step="0.5">
</div> </div>
</div> </div>
<div> <div>
<h2>Eleves</h2> <h2>Eleves</h2>
<div id="eleves"> <div id="eleves" name="eleves">
{% for eleve in eleves %} {% for eleve in eleves %}
<div class="form-group" classe="{{ eleve['listeListeClassesbf_classe'] }}" hidden> <div class="form-group" classe="{{ eleve['listeListeClassesbf_classe'] }}" hidden>
<label class="control-label col-sm-2" for="{{ eleve['id_fiche'] }}">{{ eleve['bf_nom'] }}</label> <label class="control-label col-sm-2" for="{{ eleve['id_fiche'] }}">{{ eleve['bf_nom'] }}</label>
<div class="col-sm-10"> <div class="col-sm-10">
<input type="number" class="form-control" id="{{ eleve['id_fiche'] }}" min="0" max="20" step="0.1" required> <input type="number" class="form-control" id="{{ eleve['id_fiche'] }}" name="eleve_{{ eleve['id_fiche'] }}" min="0" max="20" step="0.1" required>
</div> </div>
</div> </div>
{% endfor %} {% endfor %}