[Eleves] Fix sur les élèves

This commit is contained in:
mckmonster 2024-07-27 15:22:09 +02:00
parent b70cc3dc59
commit 20f5541d41
5 changed files with 46 additions and 13 deletions

View file

@ -163,7 +163,7 @@ EOT,
"bn_sem_type" => "",
"bn_sem_use_template" => "1",
"bn_template" => <<<EOT
titre***{{ bf_nom }} - {{ classe }}***Titre Automatique***
titre***{{ bf_nom }} - {{ bf_classe }}***Titre Automatique***
listefiche***$this->yunohostFormId***Liste déroulante*** *** *** ***bf_nom*** ***1*** *** *** * *** * *** *** *** ***
liste***ListeClasses***Classe*** *** ***aucune***bf_classe*** ***1*** *** *** * *** * *** *** *** ***
EOT,

View file

@ -62,7 +62,7 @@ class UpdateElevesFromYunohostCommand extends Command {
if ($eleveEntry == null) {
$entryManager->create($elevesFormId, [
'bf_titre' => $yunohostEntry['id_fiche'],
'listefiche'.$this->yunohostFormId.'Listebf_nom' => $yunohostEntry['id_fiche'],
'listefiche'.$yunohostFormId.'Listebf_nom' => $yunohostEntry['id_fiche'],
'antispam' => 1
]);
}

View file

@ -25,13 +25,17 @@ class ApiController extends YesWikiController
foreach ($parameters as $cle => $valeur) {
$clef_action = explode('_', $cle);
if ($clef_action[1] == 'classe' && $valeur != 'aucune') {
$datas[] = $eleveController->updateClasse($clef_action[0], $valeur);
$eleve = $eleveController->getEleve($clef_action[0]);
// echo var_dump($valeur);
$eleve->setClasse($valeur);
echo var_dump($eleve);
$datas[] = $eleveController->updateEleve($eleve);
}
if ($clef_action[1] == 'del') {
$eleveController->del($clef_action[0]);
}
}
// return ApiResponse($data);
return $this->wiki->redirect('?Eleves', 200);
}

View file

@ -5,14 +5,20 @@ namespace YesWiki\Meeo\Eleve;
use YesWiki\Bazar\Service\EntryManager;
class Eleve {
public $data;
public $classe;
public $user;
private $data;
private $user;
public function __construct(EntryManager $entryManager, $data) {
$this->data = $data;
$this->classe = $data['listeListeClassesbf_classe'];
$this->user = $entryManager->getOne($data['listeficheListebf_nom']);
// echo "<p>".var_dump($data)."</p>";
//TODO récupérer le bon numéro de liste
if (empty($data['listefiche5Listebf_nom']))
$userId = $data['listefichebf_nom'];
else
$userId = $data['listefiche5Listebf_nom'];
$this->user = $entryManager->getOne($userId);
// echo "<p>".var_dump($this)."</p>";
}
@ -27,4 +33,19 @@ class Eleve {
return $this->user['bf_nom'];
}
}
public function getClasse() {
if (empty($this->data['listeListeClassesbf_classe'])) {
return $this->data['bf_classe'];
}
return $this->data['listeListeClassesbf_classe'];
}
public function setClasse(string $classe) {
$this->data['listeListeClassesbf_classe'] = $classe;
}
public function getData() {
return $this->data;
}
}

View file

@ -2,6 +2,8 @@
namespace YesWiki\Meeo\Service;
include 'tools/meeo/libs/eleves/eleve.lib.php';
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use YesWiki\Bazar\Service\EntryManager;
use YesWiki\Bazar\Service\ListManager;
@ -28,13 +30,15 @@ class EleveManager {
$this->entryManager->delete($id);
}
public function updateClasse($id, $classe) {
return $this->entryManager->update($id, ['listeListeClassesbf_classe' => $classe, 'antispam' => true]);
public function updateEleve(Eleve $eleve) {
$id = $eleve->getId();
$data = $eleve->getData();
$data['antispam'] = true;
echo var_dump($data);
return $this->entryManager->update($id, $data);
}
public function getAll() {
include 'tools/meeo/libs/eleves/eleve.lib.php';
$eleves = [];
foreach ($this->entryManager->search(['formsIds' => $this->formId]) as $data)
{
@ -46,6 +50,10 @@ class EleveManager {
return $eleves;
}
public function getEleve(string $id) {
return new Eleve($this->entryManager, $this->entryManager->getOne($id));
}
public function getCurrentEleve(string $username) {
return $this->entryManager->getOne(str_replace(".","", $username));
}