Skip to content
Snippets Groups Projects
Commit ae22c2b8 authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Factorisation

parent 921fc740
Branches
Tags
No related merge requests found
......@@ -61,9 +61,9 @@ class DemandeExterneController extends AbstractActionController
use SelectionGestionnaireFormAwareTrait;
use UploadFormAwareTrait;
public function indexAction(): ViewModel
public function traiterParamsFromQueries(array $fromQueries, array $etatsListe): array
{
$fromQueries = $this->params()->fromQuery();
$params = [
'agent' => $this->getAgentService()->getAgent($fromQueries['agent-filtre']['id'] ?? null),
'organisme' => $fromQueries['organisme']['id'] ?? null,
......@@ -81,9 +81,17 @@ class DemandeExterneController extends AbstractActionController
}
}
} else {
$params['etats'] = DemandeExterneEtats::ETATS_OUVERTS;
$params['etats'] = $etatsListe;
$params['historise'] = 0;
$params['annee'] = (new DateTime())->format('Y');
}
return $params;
}
public function indexAction(): ViewModel
{
$params = $this->traiterParamsFromQueries($this->params()->fromQuery(), DemandeExterneEtats::ETATS_OUVERTS);
$demandes = $this->getDemandeExterneService()->getDemandesExternesWithFiltre($params);
$etats = $this->getEtatTypeService()->getEtatsTypesByCategorieCode(DemandeExterneEtats::TYPE);
......@@ -100,17 +108,9 @@ class DemandeExterneController extends AbstractActionController
public function indexTransformationAction(): ViewModel
{
$fromQueries = $this->params()->fromQuery();
$params = [
'agent' => $this->getAgentService()->getAgent($fromQueries['agent-filtre']['id'] ?? null),
'organisme' => $fromQueries['organisme']['id'] ?? null,
'etat' => $this->getEtatTypeService()->getEtatType((isset($fromQueries['etat']) && trim($fromQueries['etat']) !== '') ? trim($fromQueries['etat']) : null),
'historise' => $fromQueries['historise'] ?? null,
'annee' => $fromQueries['annee'] ?? null,
];
$params['etats'] = [DemandeExterneEtats::ETAT_TERMINEE];
$params = $this->traiterParamsFromQueries($this->params()->fromQuery(), [DemandeExterneEtats::ETAT_TERMINEE]);
$demandes = $this->getDemandeExterneService()->getDemandesExternesWithFiltre($params);
$demandes = array_filter($demandes, function (DemandeExterne $demande) { return $demande->getInscription() === null;});
$etats = [$this->getEtatTypeService()->getEtatTypeByCode(DemandeExterneEtats::ETAT_TERMINEE)];
......@@ -123,6 +123,33 @@ class DemandeExterneController extends AbstractActionController
]);
}
public function parapheurAction(): ViewModel
{
$plafond1 = $this->getParametreService()->getValeurForParametre(DemandeExterneParametres::TYPE, DemandeExterneParametres::PLAFOND_DRH);
$plafond2 = $this->getParametreService()->getValeurForParametre(DemandeExterneParametres::TYPE, DemandeExterneParametres::PLAFOND_DGS);
$etats = [
$this->getEtatTypeService()->getEtatTypeByCode(DemandeExterneEtats::ETAT_VALIDATION_GESTIONNAIRE,DemandeExterneEtats::TYPE),
$this->getEtatTypeService()->getEtatTypeByCode(DemandeExterneEtats::ETAT_VALIDATION_RESPONSABLE,DemandeExterneEtats::TYPE),
$this->getEtatTypeService()->getEtatTypeByCode(DemandeExterneEtats::ETAT_VALIDATION_DRH,DemandeExterneEtats::TYPE),
$this->getEtatTypeService()->getEtatTypeByCode(DemandeExterneEtats::ETAT_VALIDATION_DGS,DemandeExterneEtats::TYPE),
];
$params = $this->traiterParamsFromQueries($this->params()->fromQuery(), array_map(function (EtatType $etat) {return $etat->getCode();}, $etats));
$demandes = $this->getDemandeExterneService()->getDemandesExternesWithFiltre($params);
$gestionnaires = $this->getUserService()->getUtilisateursByRoleIdAsOptions(FormationRoles::GESTIONNAIRE_FORMATION);
return new ViewModel([
'plafond1' => $plafond1,
'plafond2' => $plafond2,
'demandes' => $demandes,
'etats' => $etats,
'params' => $params,
'gestionnaires' => $gestionnaires,
]);
}
public function afficherAction(): ViewModel
{
$demande = $this->getDemandeExterneService()->getRequestedDemandeExterne($this);
......@@ -691,54 +718,7 @@ class DemandeExterneController extends AbstractActionController
}
/** GESTION DES DEMANDES *************************************************************************/
public function parapheurAction(): ViewModel
{
$plafond1 = $this->getParametreService()->getValeurForParametre(DemandeExterneParametres::TYPE, DemandeExterneParametres::PLAFOND_DRH);
$plafond2 = $this->getParametreService()->getValeurForParametre(DemandeExterneParametres::TYPE, DemandeExterneParametres::PLAFOND_DGS);
$etats = [
$this->getEtatTypeService()->getEtatTypeByCode(DemandeExterneEtats::ETAT_VALIDATION_GESTIONNAIRE,DemandeExterneEtats::TYPE),
$this->getEtatTypeService()->getEtatTypeByCode(DemandeExterneEtats::ETAT_VALIDATION_RESPONSABLE,DemandeExterneEtats::TYPE),
$this->getEtatTypeService()->getEtatTypeByCode(DemandeExterneEtats::ETAT_VALIDATION_DRH,DemandeExterneEtats::TYPE),
$this->getEtatTypeService()->getEtatTypeByCode(DemandeExterneEtats::ETAT_VALIDATION_DGS,DemandeExterneEtats::TYPE),
];
$fromQueries = $this->params()->fromQuery();
$params = [
'agent' => $this->getAgentService()->getAgent($fromQueries['agent-filtre']['id'] ?? null),
'organisme' => $fromQueries['organisme']['id'] ?? null,
'etat' => $this->getEtatTypeService()->getEtatType((isset($fromQueries['etat']) && trim($fromQueries['etat']) !== '') ? trim($fromQueries['etat']) : null),
'historise' => $fromQueries['historise'] ?? null,
'annee' => $fromQueries['annee'] ?? null,
'agent-filtre[id]' => $fromQueries['agent-filtre']['id']??null,
];
$liste = $this->getRequest()->getUri()->getQuery();
if ($liste and $liste !== '') {
$liste = explode('&', $liste);
foreach ($liste as $item) {
[$key, $value] = explode('=', $item);
if ($key === "gestionnaires" or $key === "etats") {
$params[$key][] = $value;
}
}
} else {
$params['etats'] = array_map(function (EtatType $etat) {return $etat->getCode();}, $etats);
$params['historise'] = 0;
}
$demandes = $this->getDemandeExterneService()->getDemandesExternesWithFiltre($params);
$gestionnaires = $this->getUserService()->getUtilisateursByRoleIdAsOptions(FormationRoles::GESTIONNAIRE_FORMATION);
return new ViewModel([
'plafond1' => $plafond1,
'plafond2' => $plafond2,
'demandes' => $demandes,
'etats' => $etats,
'params' => $params,
'gestionnaires' => $gestionnaires,
]);
}
public function gererAction(): ViewModel
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment