Commit 85a6da8b authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Changement du type de la colonne ROLE.ORDRE_AFFICHAGE en varchar2 pour...

Changement du type de la colonne ROLE.ORDRE_AFFICHAGE en varchar2 pour faciliter le tri des acteurs par rôle,nom,prénom par exemple.
Utilisation de cette colonne pour trier aussi les IndividuRole.
parent 4fc75c31
Loading
Loading
Loading
Loading
+10 −21
Changes for module/Application/src/Application/Entity/Db/Acteur.php: 10 added lines, 21 removed lines.
Original line number Diff line number Diff line
@@ -65,30 +65,19 @@ class Acteur implements HistoriqueAwareInterface, ResourceInterface
    private $etablissement;

    /**
     * Fonction de callback à utiliser pour trier une collection d'acteurs
     * selon leur rôle.
     * Retourne la fonction de callback à utiliser pour trier une collection d'entités Acteur selon leur rôle.
     * @see usort()
     *
     * @param Acteur $a1
     * @param Acteur $a2
     * @return int
     * @return callable
     */
    static public function cmp(Acteur $a1, Acteur $a2)
    static public function getComparisonFunction()
    {
        $ordres = Role::$ordreSourcesCodes;
        $ordre1 = array_key_exists($a1->getRole()->getSourceCode(), $ordres) ? $ordres[$a1->getRole()->getSourceCode()] : 'zzz';
        $ordre2 = array_key_exists($a2->getRole()->getSourceCode(), $ordres) ? $ordres[$a2->getRole()->getSourceCode()] : 'zzz';

        $nom1 = ($i1 = $a1->getIndividu()) ? $i1->getNomUsuel() . $i1->getPrenom() : '';
        $nom2 = ($i2 = $a2->getIndividu()) ? $i2->getNomUsuel() . $i2->getPrenom() : '';

        $x = $ordre1 . $nom1;
        $y = $ordre2 . $nom2;

        if ($x === $y) {
            return 0;
        }

        return strcmp($x, $y);
        return function(Acteur $a1, Acteur $a2) {
            return strcmp(
                $a1->getRole()->getOrdreAffichage() . $a1->getIndividu()->getNomUsuel() . $a1->getIndividu()->getPrenom(),
                $a2->getRole()->getOrdreAffichage() . $a2->getIndividu()->getNomUsuel() . $a2->getIndividu()->getPrenom()
            );
        };
    }

    /**
+15
Changes for module/Application/src/Application/Entity/Db/IndividuRole.php: 15 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -51,4 +51,19 @@ class IndividuRole
        return $this;
    }

    /**
     * Retourne la fonction de callback à utiliser pour trier une collection d'entités IndividuRole selon le rôle.
     * @see usort()
     *
     * @return callable
     */
    static public function getComparisonFunction()
    {
        return function(IndividuRole $a1, IndividuRole $a2) {
            return strcmp(
                $a1->getRole()->getOrdreAffichage() . $a1->getIndividu()->getNomUsuel() . $a1->getIndividu()->getPrenom(),
                $a2->getRole()->getOrdreAffichage() . $a2->getIndividu()->getNomUsuel() . $a2->getIndividu()->getPrenom()
            );
        };
    }
}
 No newline at end of file
+1 −1
Changes for module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.Role.dcm.xml: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -16,11 +16,11 @@
        <field name="attributionAutomatique" type="boolean" column="ATTRIB_AUTO" nullable="false"/>
        <field name="theseDependant" type="boolean" column="THESE_DEP" nullable="false"/>
        <field name="sourceCode" type="string" column="SOURCE_CODE" length="100" nullable="true"/>
        <field name="ordreAffichage" type="string" column="ORDRE_AFFICHAGE" length="32" nullable="false"/>

        <field name="histoCreation" type="datetime" column="HISTO_CREATION" nullable="false"/>
        <field name="histoDestruction" type="datetime" column="HISTO_DESTRUCTION" nullable="true"/>
        <field name="histoModification" type="datetime" column="HISTO_MODIFICATION" nullable="false"/>
        <field name="ordreAffichage" type="integer" column="ORDRE_AFFICHAGE" nullable="false"/>

        <many-to-one field="typeStructureDependant" target-entity="Application\Entity\Db\TypeStructure">
            <join-columns>
+14 −17
Changes for module/Application/src/Application/Entity/Db/Role.php: 14 added lines, 17 removed lines.
Original line number Diff line number Diff line
@@ -37,14 +37,6 @@ class Role extends AbstractRole
    const ROLE_ID_ECOLE_DOCT = "École doctorale";
    const ROLE_ID_UNITE_RECH = "Unité de recherche";

    static public $ordreSourcesCodes = [
        self::CODE_DIRECTEUR_THESE => 'aa',
        self::CODE_CO_ENCADRANT    => 'ab',
        self::CODE_PRESIDENT_JURY  => 'b',
        self::CODE_MEMBRE_JURY     => 'c',
        self::CODE_RAPPORTEUR_JURY => 'd',
    ];

    /**
     * @var string
     */
@@ -272,7 +264,10 @@ class Role extends AbstractRole
    }

    /**
     * @return int
     * Retourne une chaîne de caractères utilisée pour trier les rôles ;
     * l'astuce consiste à concaténer cette valeur aux autres critères de tri.
     *
     * @return string
     */
    public function getOrdreAffichage()
    {
@@ -280,19 +275,21 @@ class Role extends AbstractRole
    }

    /**
     * @param int $ordreAffichage
     * @return Role
     * @param string $ordreAffichage
     * @return self
     */
    public function setOrdreAffichage($ordreAffichage)
    {
        $this->ordreAffichage = $ordreAffichage;
        $this->ordreAffichage = (string) $ordreAffichage;

        return $this;
    }



    public function __toString() {
        $txt = "" . $this->getLibelle();
        return $txt;
    /**
     * @return string
     */
    public function __toString()
    {
        return $this->getLibelle();
    }
}
 No newline at end of file
+1 −1
Changes for module/Application/src/Application/Entity/Db/These.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -741,7 +741,7 @@ class These implements HistoriqueAwareInterface, ResourceInterface
    {
        $acteurs = $this->getActeurs()->toArray();

        usort($acteurs, $callable ?: [Acteur::class, 'cmp']);
        usort($acteurs, $callable ?: Acteur::getComparisonFunction());

        return new ArrayCollection($acteurs);
    }
Loading