ynh_extension_meeo/actions/AbsencesAction.php

50 lines
1.6 KiB
PHP

<?php
use YesWiki\Core\YesWikiAction;
use YesWiki\Bazar\Service\EntryManager;
use YesWiki\Core\Service\UserManager;
class AbsencesAction extends YesWikiAction
{
private $formId = '6';
private $eleveIdentifier = 'listefiche5bf_eleve';
private $groupeEE = 'EquipeEducative';
public function formatArguments($arg)
{
return [];
}
public function run()
{
$entryManager = $this->getService(EntryManager::class);
$userManager = $this->getService(UserManager::class);
if ( $userManager->isInGroup($this->groupeEE, admincheck: false) ) {
$entries = $entryManager->search(['formsIds' => $this->formId]);
$grouped_entries = [];
foreach ($entries as $entry) {
$identifier = $entry[$this->eleveIdentifier];
$nom = $entryManager->getOne($identifier)['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' => $this->formId, 'queries' => [ $this->eleveIdentifier => $username."2"]]);
return $this->render('@meeo/eleve_absences.twig', [
"entries" => $entries,
]);
}
}
}