Skip to content
Snippets Groups Projects
Select Git revision
  • 0f43cea8a7ee1c9bb808e87f60fc872ffeaad4da
  • master default protected
  • b24
  • ll-wf-finitions
  • ll-workflow
  • alc-scindage-donnees-pj
  • FJ_LL_Tbl_Contrat
  • alc-docker-node
  • ll-apiplatform
  • php84
  • ll-rgpd
  • b23
  • alc-filtre-type-intervenant
  • ll-sans-mdb5
  • formules-ancienne-infra
  • ll-formules
  • alc-intervenant-dmep
  • ll-suppr-v_vol-s
  • b20
  • ll-postgresql
  • b23.0.1
  • 24.10
  • 24.9
  • 24.8
  • 24.7
  • 24.6
  • 24.5
  • 24.4
  • 24.3
  • 24.2
  • 24.1
  • 24.0
  • 23.15
  • 24.0-beta19
  • 24.0-beta18
  • 24.0-beta17
  • 24.0-beta16
  • 24.0-beta15
  • 24.0-beta14
  • 24.0-beta13
  • 23.14
41 results

DataGen.php

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    AgentController.php 11.55 KiB
    <?php
    
    namespace Agent\Controller;
    
    use Agent\Entity\Db\Agent;
    use Agent\Entity\Db\AgentValidateur;
    use Agent\Provider\Parametre\CharteParametres;
    use Agent\Provider\Role\RolesProvider;
    use Agent\Service\Agent\AgentServiceAwareTrait;
    use Agent\Service\AgentAffectation\AgentAffectationServiceAwareTrait;
    use Agent\Service\AgentGrade\AgentGradeServiceAwareTrait;
    use Agent\Service\AgentStatut\AgentStatutServiceAwareTrait;
    use Agent\Service\AgentValidateur\AgentValidateurServiceAwareTrait;
    use DemandeExterne\Service\DemandeExterne\DemandeExterneServiceAwareTrait;
    use DateTime;
    use DemandeExterne\Entity\Db\DemandeExterne;
    use Formation\Entity\Db\Inscription;
    use DemandeExterne\Provider\Etat\DemandeExterneEtats;
    use Formation\Provider\Etat\InscriptionEtats;
    use Formation\Provider\Etat\SessionEtats;
    use Formation\Service\Inscription\InscriptionServiceAwareTrait;
    use Laminas\Mvc\Controller\AbstractActionController;
    use Laminas\View\Model\JsonModel;
    use Laminas\View\Model\ViewModel;
    use UnicaenApp\View\Model\CsvModel;
    use UnicaenParametre\Service\Parametre\ParametreServiceAwareTrait;
    use UnicaenRenderer\Service\Rendu\RenduServiceAwareTrait;
    use UnicaenUtilisateur\Service\User\UserServiceAwareTrait;
    use UnicaenValidation\Service\ValidationInstance\ValidationInstanceServiceAwareTrait;
    
    class AgentController extends AbstractActionController
    {
        use AgentServiceAwareTrait;
        use AgentAffectationServiceAwareTrait;
        use AgentGradeServiceAwareTrait;
        use AgentStatutServiceAwareTrait;
        use AgentValidateurServiceAwareTrait;
        use DemandeExterneServiceAwareTrait;
        use InscriptionServiceAwareTrait;
        use ParametreServiceAwareTrait;
        use RenduServiceAwareTrait;
        use UserServiceAwareTrait;
        use ValidationInstanceServiceAwareTrait;
    
    
        public function indexAction(): ViewModel
        {
            $params = $this->params()->fromQuery();
            $agents = [];
            if ($params !== null and !empty($params)) {
                $agents = $this->getAgentService()->getAgentsWithFiltre($params);
            }
    
            return new ViewModel([
                'agents' => $agents,
                'params' => $params,
            ]);
        }
    
        public function afficherAction(): ViewModel
        {
            $agent = $this->getAgentService()->getRequestedAgent($this);
            $agentAffectations = $this->getAgentAffectationService()->getAgentAffectationsByAgent($agent);
            $agentGrades = $this->getAgentGradeService()->getAgentGradesByAgent($agent);
            $agentStatuts = $this->getAgentStatutService()->getAgentStatutsByAgent($agent);
            $validateurs = $this->getAgentValidateurService()->getAgentsValidateursByAgent($agent, true);
    
            $formations = $this->getInscriptionService()->getInscriptionsByAgent($agent);
            $inscriptions = $this->getInscriptionService()->getInscriptionsByAgent($agent);
    
            $demandes = $this->getDemandeExterneService()->getDemandesExternesByAgent($agent);
            $demandes = array_filter($demandes, function (DemandeExterne $d) {
                return (
                    $d->estNonHistorise() &&
                    !$d->isEtatActif(DemandeExterneEtats::ETAT_REJETEE) &&
                    !$d->isEtatActif(DemandeExterneEtats::ETAT_TERMINEE)
                );
            });
    
            return new ViewModel([
                'agent' => $agent,
                'agentAffectations' => $agentAffectations,
                'agentGrades' => $agentGrades,
                'agentStatuts' => $agentStatuts,
    
                'validateurs' => $validateurs,
    
                'inscriptions' => $inscriptions,
                'stages' => $demandes,
                'formations' => $formations,
    
                'charteActive' => $this->getParametreService()->getValeurForParametre(CharteParametres::TYPE, CharteParametres::CHARTE_ACTIVE),
            ]);
        }
    
        public function mesAgentsAction(): ViewModel
        {
            $user = $this->getUserService()->getConnectedUser();
            $role = $this->getUserService()->getConnectedRole();
            $agent = $this->getAgentService()->getAgentByUser($user);
    
            $agents = [];
            if ($role->getRoleId() === RolesProvider::ROLE_VALIDATEUR) $agents = array_map(function (AgentValidateur $a) {
                return $a->getAgent();
            }, $this->getAgentValidateurService()->getAgentsValidateursByValidateur($agent));
    
            $inscriptions = $this->getInscriptionService()->getInscriptionsByAgents($agents, (new DateTime())->format('Y'));
            // filtrer les inscriptions ici de demande indivuelle
            $inscriptions = array_filter($inscriptions, function (Inscription $inscription) {
               return empty($inscription->getSession()->getDemandesExternes());
            });
            $inscriptionsEnAttente = array_filter($inscriptions, function (Inscription $inscription) {
                return ($inscription->isEtatActif(InscriptionEtats::ETAT_DEMANDE) and $inscription->getSession()->isEtatActif(SessionEtats::ETAT_INSCRIPTION_OUVERTE));
            });
    
            $demandes = $this->getDemandeExterneService()->getDemandesExternesByAgents($agents);
            $demandesEnAttente = array_filter($demandes, function (DemandeExterne $demande) {
                return $demande->isEtatActif(DemandeExterneEtats::ETAT_VALIDATION_AGENT);
            });
    
    
            return new ViewModel([
                'user' => $user,
                'role' => $role,
                'agents' => $agents,
    
                'inscriptions' => $inscriptions,
                'inscriptionsEnAttente' => $inscriptionsEnAttente,
                'demandes' => $demandes,
                'demandesEnAttente' => $demandesEnAttente,
            ]);
        }
    
        public function listerMesAgentsAction(): ViewModel
        {
            $user = $this->getUserService()->getConnectedUser();
            $role = $this->getUserService()->getConnectedRole();
            $agent = $this->getAgentService()->getAgentByUser($user);
    
            $agents = [];
            if ($role->getRoleId() === RolesProvider::ROLE_VALIDATEUR)
                $agents = array_map(
                    function (AgentValidateur $a) {
                        return $a->getAgent();
                    },
                    $this->getAgentValidateurService()->getAgentsValidateursByValidateur($agent));
    
            usort($agents, function (Agent $a, Agent $b) {
                $aaa = $a->getNomUsuel() . " " . $a->getPrenom() . " " . $a->getId();
                $bbb = $b->getNomUsuel() . " " . $b->getPrenom() . " " . $b->getId();
                return $aaa <=> $bbb;
            });
            return new ViewModel([
                'title' => "Liste des agents dont je suis responsable",
                'user' => $user,
                'role' => $role,
                'agents' => $agents,
            ]);
        }
    
        public function extraireInscriptionsAction(): CsvModel
        {
            $user = $this->getUserService()->getConnectedUser();
            $role = $this->getUserService()->getConnectedRole();
            $agent = $this->getAgentService()->getAgentByUser($user);
    
            $agents = [];
            if ($role->getRoleId() === RolesProvider::ROLE_VALIDATEUR)
                $agents = array_map(
                    function (AgentValidateur $a) {
                        return $a->getAgent();
                    },
                    $this->getAgentValidateurService()->getAgentsValidateursByValidateur($agent));
    
            $inscriptions = $this->getInscriptionService()->getInscriptionsByAgents($agents);
            $headers = ["annee", "prenom", "nom", "action de formation", "session", "etat de la session", "etat de l'inscription", "liste", "duree", "presence"];
            $records = [];
            foreach ($inscriptions as $inscription) {
                $records[] = [
                    "annee" => $inscription->getSession()->getAnnee(),
                    "prenom" => $inscription->getAgent()->getPrenom(),
                    "nom" => $inscription->getAgent()->getNomUsuel(),
                    "action de formation" => $inscription->getSession()->getFormation()->getLibelle(),
                    "session" => $inscription->getSession()->getPeriode(),
                    "etat de la session" => $inscription->getSession()->getEtatActif()->getType()->getLibelle(),
                    "etat de l'inscription" => $inscription->getEtatActif()->getType()->getLibelle(),
                    "liste" => ($inscription->getListe()??"Non classée"),
                    "duree" => $inscription->getSession()->getDuree(),
                    "presence" => $inscription->getDureePresence(),
                ];
            }
    
            $date = (new DateTime())->format('Ymd-His');
            $filename="export_mesformations_inscriptions_".$date.".csv";
            $CSV = new CsvModel();
            $CSV->setDelimiter(';');
            $CSV->setEnclosure('"');
            $CSV->setHeader($headers);
            $CSV->setData($records);
            $CSV->setFilename($filename);
            return $CSV;
        }
    
        public function extraireDemandesAction(): CsvModel
        {
            $user = $this->getUserService()->getConnectedUser();
            $role = $this->getUserService()->getConnectedRole();
            $agent = $this->getAgentService()->getAgentByUser($user);
    
            $agents = [];
            if ($role->getRoleId() === RolesProvider::ROLE_VALIDATEUR)
                $agents = array_map(
                    function (AgentValidateur $a) {
                        return $a->getAgent();
                    },
                    $this->getAgentValidateurService()->getAgentsValidateursByValidateur($agent));
    
            $demandes = $this->getDemandeExterneService()->getDemandesExternesByAgents($agents);
            $headers = ["annee", "prenom", "nom", "action de formation", "date", "organisme", "lieu", "montant", "etat de la demande"];
            $records = [];
            foreach ($demandes as $demande) {
                $records[] = [
                    "annee" => $demande->getAnnee(),
                    "prenom" => $demande->getAgent()->getPrenom(),
                    "nom" => $demande->getAgent()->getNomUsuel(),
                    "action de formation" => $demande->getLibelle(),
                    "date" => $demande->getPeriode(),
                    "organisme" => $demande->getOrganisme(),
                    "lieu" => $demande->getLieu(),
                    "montant" => $demande->getMontant(),
                    "etat de la demande" => $demande->getEtatActif()->getTypeLibelle(),
                ];
            }
    
            $date = (new DateTime())->format('Ymd-His');
            $filename="export_mesformations_inscriptions_".$date.".csv";
            $CSV = new CsvModel();
            $CSV->setDelimiter(';');
            $CSV->setEnclosure('"');
            $CSV->setHeader($headers);
            $CSV->setData($records);
            $CSV->setFilename($filename);
            return $CSV;
        }
    
        public function historiqueAction(): ViewModel
        {
            $agent = $this->getAgentService()->getRequestedAgent($this);
            $inscriptions = $this->getInscriptionService()->getInscriptionsByAgent($agent);
    
            $inscriptions = array_filter($inscriptions, function (Inscription $a) {
                return
                    $a->isEtatActif(InscriptionEtats::ETAT_VALIDER_DRH) AND $a->getSession()->isEtatActif(SessionEtats::ETAT_CLOTURE_INSTANCE);
            });
    
            return new ViewModel([
                'title' => "Historique des formations de " . $agent->getDenomination(true),
                'agent' => $agent,
                'inscriptions' => $inscriptions,
            ]);
        }
    
        public function rechercherAction(): JsonModel
        {
            if (($term = $this->params()->fromQuery('term'))) {
                $agents = $this->getAgentService()->getAgentsByTerm($term);
                $result = $this->getAgentService()->formatAgentJSON($agents);
                return new JsonModel($result);
            }
            exit;
        }
    
        public function rechercherLargeAction(): JsonModel
        {
            if (($term = $this->params()->fromQuery('term'))) {
                $agents = $this->getAgentService()->getAgentsLargeByTerm($term);
                $result = $this->getAgentService()->formatAgentJSON($agents);
                return new JsonModel($result);
            }
            exit;
        }
    
    }