ynh_extension_meeo/services/EleveManager.php

77 lines
2.2 KiB
PHP
Raw Normal View History

<?php
namespace YesWiki\Meeo\Service;
2024-07-27 13:22:09 +00:00
include 'tools/meeo/libs/eleves/eleve.lib.php';
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use YesWiki\Bazar\Service\EntryManager;
use YesWiki\Bazar\Service\ListManager;
use YesWiki\Wiki;
use YesWiki\Meeo\Eleve\Eleve;
class EleveManager {
private $formId;
2024-08-02 17:00:18 +00:00
private $yunoshostFormId;
private $entryManager;
private $listManager;
private $wiki;
2024-09-06 09:54:14 +00:00
private $meeo_config;
public function __construct( Wiki $wiki, ParameterBagInterface $params, EntryManager $entryManager, ListManager $listManager)
{
2024-09-06 09:54:14 +00:00
$this->meeo_config = $params->get('meeo');
$this->wiki = $wiki;
2024-09-06 09:54:14 +00:00
$this->formId = $this->meeo_config['elevesFormId'];
$this->yunoshostFormId = $this->meeo_config['yunohostFormId'];
$this->entryManager = $entryManager;
$this->listManager = $listManager;
}
public function del($id) {
$this->entryManager->delete($id);
}
2024-07-27 13:22:09 +00:00
public function updateEleve(Eleve $eleve) {
$id = $eleve->getId();
$data = $eleve->getData();
$data['antispam'] = true;
2024-08-06 06:17:31 +00:00
// echo var_dump($data);
2024-07-27 13:22:09 +00:00
return $this->entryManager->update($id, $data);
}
2024-07-20 08:13:50 +00:00
public function getAll() {
$eleves = [];
foreach ($this->entryManager->search(['formsIds' => $this->formId]) as $data)
{
2024-09-06 09:54:14 +00:00
$eleve = new Eleve($this->entryManager, $this->meeo_config, $data);
// echo "<p>".var_dump($eleve)."</p>";
$eleves[] = $eleve;
}
return $eleves;
}
2024-07-27 13:22:09 +00:00
public function getEleve(string $id) {
2024-09-06 09:54:14 +00:00
return new Eleve($this->entryManager, $this->meeo_config, $this->entryManager->getOne($id));
2024-07-27 13:22:09 +00:00
}
public function getCurrentEleve(string $username) {
2024-08-05 17:02:45 +00:00
$all = $this->getAll();
foreach ($all as $eleve) {
2024-08-06 06:21:13 +00:00
// echo "<p>".var_dump($eleve)."</p>";
if ($eleve->getUserId() == $username || $eleve->isParent($username))
2024-08-05 17:02:45 +00:00
return $eleve;
}
2024-07-20 08:13:50 +00:00
}
public function view() {
2024-07-20 08:13:50 +00:00
$eleves = $this->getAll();
// echo '<p>'.var_dump($eleves).'</p>';
$classes = $this->listManager->getOne('ListeClasses');
// echo "<p>".var_dump($classes)."</p>";
2024-08-02 17:19:00 +00:00
return $this->wiki->render('@meeo/edu_eleves.twig', ['eleves' => $eleves, 'classes' => $classes['label']]);
}
2024-08-06 06:17:31 +00:00
}