Commit 1a026e93 authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

[Fix] : ajout d'une garde pour les campagnes null sur les pages des structures (bug AMU)

parent 1da382a2
Loading
Loading
Loading
Loading
+9 −0
Changes for documentation/release/3.2.3.md: 9 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -9,11 +9,20 @@ Version 3.2.3 (XX/XX/2023)
- Ajout d'un tri des structures dans le calcul des chaînes hiérarchiques (type de structure puis libellé de la structure)et ajout du *data-live-search*
- [Fix] : gestion du cas où l'hydrator des campagnes renvoie *faux* à la création de date
- Réouverture de la modification des fiches de poste aux resposansable de structures
- [Fix] : ajout d'une garde pour les campagnes null sur les pages des structures (bug AMU)

Modification en BD
---

```postgresql
-- nouveaux parametres 
INSERT INTO unicaen_parametre_parametre(CATEGORIE_ID, CODE, LIBELLE, DESCRIPTION, VALEURS_POSSIBLES, VALEUR, ORDRE)
WITH d(CODE, LIBELLE, DESCRIPTION, VALEURS_POSSIBLES, VALEUR, ORDRE) AS (
    SELECT 'TEMOIN_AFFECTATION','Liste des temoins à considerer pour les affectations',null,'String',null, 100
)
SELECT cp.id, d.CODE, d.LIBELLE, d.DESCRIPTION, d.VALEURS_POSSIBLES, d.VALEUR, d.ORDRE
FROM d
JOIN unicaen_parametre_categorie cp ON cp.CODE = 'STRUCTURE';
```

Evolution des librairies 
+8 −4
Changes for module/Application/src/Application/Entity/Db/Agent.php: 8 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -161,10 +161,12 @@ class Agent implements
    }

    /** @return AgentAffectation[] */
    public function getAffectationsActifs(?DateTime $date = null) : array
    public function getAffectationsActifs(?DateTime $date = null, ?array $structures = null) : array
    {
        if ($date === null) $date = (new DateTime());
        return $this->getAffectations($date);
        $affectations =  $this->getAffectations($date);
        if ($structures !== null) $affectations = array_filter($affectations, function (AgentAffectation $a) use ($structures) { return in_array($a->getStructure(), $structures);});
        return $affectations;
    }

    /** @return AgentAffectation */ //TODO A reecrire car peut être multiple ...
@@ -251,10 +253,12 @@ class Agent implements
    }

    /** @return AgentStatut[] */
    public function getStatutsActifs(?DateTime $date = null) : array
    public function getStatutsActifs(?DateTime $date = null, ?Structure $structure = null) : array
    {
        if ($date === null) $date = (new DateTime());
        return $this->getStatuts($date);
        $statuts = $this->getStatuts($date);
        if ($structure) $statuts = array_filter($statuts, function (AgentStatut $a) use ($structure) { return $a->getStructure() === $structure;});
        return $statuts;
    }

    /** Autres accesseurs *********************************************************************************************/
+18 −0
Changes for module/Application/src/Application/Entity/Db/AgentAffectation.php: 18 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ namespace Application\Entity\Db;
use Application\Entity\Db\Interfaces\HasPeriodeInterface;
use Application\Entity\Db\Traits\DbImportableAwareTrait;
use Application\Entity\Db\Traits\HasPeriodeTrait;
use RuntimeException;
use Structure\Entity\Db\Structure;

/**
@@ -44,6 +45,23 @@ class AgentAffectation implements HasPeriodeInterface {
        return $this->idOrig;
    }

    /** Gestion des témoins ***************************************************************************************/

    const TEMOINS = [
        'principale', 'hierarchique', 'fonctionnelle'
    ];

    public function getTemoin(string $temoin) : bool
    {
        switch ($temoin) {
            case 'principale' : return $this->isPrincipale();
            case 'hierarchique' : return $this->isHierarchique();
            case 'fonctionnelle' : return $this->isFonctionnelle();
            default :
                throw new RuntimeException("Le temoin [" . $temoin . "] est inconnu ou non géré.", 0);
        }
    }

    public function isPrincipale() : bool
    {
        return ($this->principale === 'O');
+28 −0
Changes for module/Application/src/Application/Entity/Db/AgentStatut.php: 28 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ namespace Application\Entity\Db;
use Application\Entity\Db\Interfaces\HasPeriodeInterface;
use Application\Entity\Db\Traits\DbImportableAwareTrait;
use Application\Entity\Db\Traits\HasPeriodeTrait;
use RuntimeException;
use Structure\Entity\Db\Structure;

/**
@@ -15,6 +16,7 @@ class AgentStatut implements HasPeriodeInterface {
    use HasPeriodeTrait;
    use DbImportableAwareTrait;


    /** @var string */
    private $id;
    /** @var string */
@@ -158,6 +160,32 @@ class AgentStatut implements HasPeriodeInterface {
        return $this;
    }

    /** Gestion des témoins ***************************************************************************************/

    const TEMOINS = [
        'cdi', 'cdd', 'titulaire', 'vacataire',
        'enseignant', 'administratif', 'chercheur',
        'detacheIn', 'detacheOut','dispo'
    ];

    public function getTemoin(string $temoin) : bool
    {
        switch ($temoin) {
            case 'cdi' : return $this->isCdi();
            case 'cdd' : return $this->isCdd();
            case 'titulaire' : return $this->isTitulaire();
            case 'vacataire' : return $this->isVacataire();
            case 'enseignant' : return $this->isEnseignant();
            case 'administratif' : return $this->isAdministratif();
            case 'chercheur' : return $this->isChercheur();
            case 'detacheIn' : return $this->isDetacheIn();
            case 'detacheOut' : return $this->isDetacheOut();
            case 'dispo' : return $this->isDispo();
            default :
                throw new RuntimeException("Le temoin [" . $temoin . "] est inconnu ou non géré.", 0);
        }
    }
    
    /**
     * @return bool
     */
+95 −6
Changes for module/Application/src/Application/Service/Agent/AgentService.php: 95 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ use Structure\Entity\Db\StructureResponsable;
use Structure\Service\Structure\StructureServiceAwareTrait;
use UnicaenApp\Exception\RuntimeException;
use UnicaenApp\Service\EntityManagerAwareTrait;
use UnicaenParametre\Entity\Db\Parametre;
use UnicaenParametre\Service\Parametre\ParametreServiceAwareTrait;
use UnicaenUtilisateur\Entity\Db\User;
use UnicaenUtilisateur\Service\User\UserServiceAwareTrait;
@@ -237,13 +238,9 @@ class AgentService {
            ->addSelect('astructure')->join('affectation.structure', 'astructure')
            ->andWhere('affectation.dateFin >= :today OR affectation.dateFin IS NULL')
            ->andWhere('affectation.dateDebut <= :today')
            ->andWhere('affectation.principale = :true')
            ->andWhere('affectation.deleted_on IS NULL')
            //STATUS
            ->addSelect('statut')->leftjoin('agent.statuts', 'statut')
//            ->andWhere('statut.dateFin >= :today OR statut.dateFin IS NULL')
//            ->andWhere('statut.dateDebut <= :today')
            ->andWhere('statut.dispo = :false')
//            ->andWhere('(statut.enseignant = :false AND statut.chercheur = :false AND statut.retraite = :false AND (statut.detacheOut = :false OR (statut.detacheOut = :true AND statut.detacheIn = :true)) AND statut.vacataire = :false)')
            ->andWhere('statut.deleted_on IS NULL')
            //GRADE
@@ -259,8 +256,6 @@ class AgentService {
            ->addSelect('ficheposte')->leftJoin('agent.fiches', 'ficheposte')

            ->setParameter('today', $date)
            ->setParameter('true', 'O')
            ->setParameter('false', 'N')
            ->andWhere('agent.deleted_on IS NULL')

            ->orderBy('agent.nomUsuel, agent.prenom', 'ASC')
@@ -656,4 +651,98 @@ class AgentService {
        }
        return true;
    }

    /**
     * @param Agent[] $agents
     * @param Parametre|null $parametre
     * @param DateTime|null $date
     * @param Structure|null $structure
     * @return Agent[]
     */
    public function filtrerWithStatutTemoin(array $agents, ?Parametre $parametre, ?DateTime $date = null, ?Structure $structure = null) : array
    {
        if ($parametre === null || $parametre->getValeur() === null || $parametre->getValeur() === '') return $agents;
        if ($date === null) $date = new DateTime();

        $listing = explode(";", $parametre->getValeur());
        $on = []; $off = [];
        foreach ($listing as $item) {
            if ($item[0] === '!') $off[] = substr($item,1); else $on[] = $item;
        }

        $result = [];
        foreach ($agents as $agent) {
            $count = [];
            $statuts = $agent->getStatutsActifs($date, $structure);
            foreach ($statuts as $statut) {
                foreach (AgentStatut::TEMOINS as $temoin) {
                    if ($statut->getTemoin($temoin)) {
                        $count[$temoin] = true;
                    }
                }
            }

            $keep = true;
            foreach($on as $temoin) {
                if (!isset($count[$temoin])) {
                    $keep = false ; break;
                }
            }
            foreach($off as $temoin) {
                if (isset($count[$temoin])) {
                    $keep = false ; break;
                }
            }
            if ($keep) $result[] = $agent;
        }

        return $result;
    }

    /**
     * @param Agent[] $agents
     * @param Parametre|null $parametre
     * @param DateTime|null $date
     * @param Structure|null $structure
     * @return Agent[]
     */
    public function filtrerWithAffectationTemoin(array $agents, ?Parametre $parametre, ?DateTime $date = null, ?array $structures = null) : array
    {
        if ($parametre === null || $parametre->getValeur() === null || $parametre->getValeur() === '') return $agents;
        if ($date === null) $date = new DateTime();

        $listing = explode(";", $parametre->getValeur());
        $on = []; $off = [];
        foreach ($listing as $item) {
            if ($item[0] === '!') $off[] = substr($item,1); else $on[] = $item;
        }

        $result = [];
        foreach ($agents as $agent) {
            $count = [];
            $statuts = $agent->getAffectationsActifs($date, $structures);
            foreach ($statuts as $statut) {
                foreach (AgentAffectation::TEMOINS as $temoin) {
                    if ($statut->getTemoin($temoin)) {
                        $count[$temoin] = true;
                    }
                }
            }

            $keep = true;
            foreach($on as $temoin) {
                if (!isset($count[$temoin])) {
                    $keep = false ; break;
                }
            }
            foreach($off as $temoin) {
                if (isset($count[$temoin])) {
                    $keep = false ; break;
                }
            }
            if ($keep) $result[] = $agent;
        }

        return $result;
    }
}
 No newline at end of file
Loading