[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_type" => "",
"bn_sem_use_template" => "1", "bn_sem_use_template" => "1",
"bn_template" => <<<EOT "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*** *** *** * *** * *** *** *** *** listefiche***$this->yunohostFormId***Liste déroulante*** *** *** ***bf_nom*** ***1*** *** *** * *** * *** *** *** ***
liste***ListeClasses***Classe*** *** ***aucune***bf_classe*** ***1*** *** *** * *** * *** *** *** *** liste***ListeClasses***Classe*** *** ***aucune***bf_classe*** ***1*** *** *** * *** * *** *** *** ***
EOT, EOT,

View file

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

View file

@ -25,13 +25,17 @@ class ApiController extends YesWikiController
foreach ($parameters as $cle => $valeur) { foreach ($parameters as $cle => $valeur) {
$clef_action = explode('_', $cle); $clef_action = explode('_', $cle);
if ($clef_action[1] == 'classe' && $valeur != 'aucune') { 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') { if ($clef_action[1] == 'del') {
$eleveController->del($clef_action[0]); $eleveController->del($clef_action[0]);
} }
} }
// return ApiResponse($data);
return $this->wiki->redirect('?Eleves', 200); return $this->wiki->redirect('?Eleves', 200);
} }

View file

@ -5,14 +5,20 @@ namespace YesWiki\Meeo\Eleve;
use YesWiki\Bazar\Service\EntryManager; use YesWiki\Bazar\Service\EntryManager;
class Eleve { class Eleve {
public $data; private $data;
public $classe; private $user;
public $user;
public function __construct(EntryManager $entryManager, $data) { public function __construct(EntryManager $entryManager, $data) {
$this->data = $data; $this->data = $data;
$this->classe = $data['listeListeClassesbf_classe']; // echo "<p>".var_dump($data)."</p>";
$this->user = $entryManager->getOne($data['listeficheListebf_nom']); //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>"; // echo "<p>".var_dump($this)."</p>";
} }
@ -27,4 +33,19 @@ class Eleve {
return $this->user['bf_nom']; 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; namespace YesWiki\Meeo\Service;
include 'tools/meeo/libs/eleves/eleve.lib.php';
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use YesWiki\Bazar\Service\EntryManager; use YesWiki\Bazar\Service\EntryManager;
use YesWiki\Bazar\Service\ListManager; use YesWiki\Bazar\Service\ListManager;
@ -28,13 +30,15 @@ class EleveManager {
$this->entryManager->delete($id); $this->entryManager->delete($id);
} }
public function updateClasse($id, $classe) { public function updateEleve(Eleve $eleve) {
return $this->entryManager->update($id, ['listeListeClassesbf_classe' => $classe, 'antispam' => true]); $id = $eleve->getId();
$data = $eleve->getData();
$data['antispam'] = true;
echo var_dump($data);
return $this->entryManager->update($id, $data);
} }
public function getAll() { public function getAll() {
include 'tools/meeo/libs/eleves/eleve.lib.php';
$eleves = []; $eleves = [];
foreach ($this->entryManager->search(['formsIds' => $this->formId]) as $data) foreach ($this->entryManager->search(['formsIds' => $this->formId]) as $data)
{ {
@ -46,6 +50,10 @@ class EleveManager {
return $eleves; return $eleves;
} }
public function getEleve(string $id) {
return new Eleve($this->entryManager, $this->entryManager->getOne($id));
}
public function getCurrentEleve(string $username) { public function getCurrentEleve(string $username) {
return $this->entryManager->getOne(str_replace(".","", $username)); return $this->entryManager->getOne(str_replace(".","", $username));
} }