ynh_extension_meeo/actions/AbsencesAction.php
2024-08-06 08:58:32 +02:00

54 lines
1.8 KiB
PHP

<?php
use YesWiki\Core\YesWikiAction;
use YesWiki\Bazar\Service\EntryManager;
use YesWiki\Core\Service\UserManager;
class AbsencesAction extends YesWikiAction
{
public function formatArguments($arg)
{
return [];
}
public function run()
{
$meeo_config = $this->params->get('meeo');
$formId = $meeo_config['absencesFormId'];
$eleveIdentifier = 'listefiche'.$meeo_config['elevesFormId'].'bf_eleve';
$groupeEE = $meeo_config['groupeEE'];
$entryManager = $this->getService(EntryManager::class);
$userManager = $this->getService(UserManager::class);
if ( $userManager->isInGroup($groupeEE, admincheck: false) ) {
$entries = $entryManager->search(['formsIds' => $formId]);
$grouped_entries = [];
foreach ($entries as $entry) {
$identifier = $entry[$eleveIdentifier];
$eleve = $entryManager->getOne($identifier);
echo "<p>".var_dump($eleve)."</p>";
$nom = $eleve['bf_nom'];
if (!isset($grouped_entries[$identifier])) {
$grouped_entries[$identifier] = [
'nom' => $nom,
'entries' => []
];
}
$grouped_entries[$identifier]['entries'][] = $entry;
}
return $this->render('@meeo/edu_absences.twig', [
"groups" => $grouped_entries,
]);
} else {
$username = $userManager->getLoggedUsername();
$entries = $entryManager->search(['formsIds' => $formId, 'queries' => [ $eleveIdentifier => $username."2"]]);
return $this->render('@meeo/eleve_absences.twig', [
"entries" => $entries,
]);
}
}
}