From 98968ae0783979b3570e30445f1670082b8725a2 Mon Sep 17 00:00:00 2001
From: Jean-Philippe Metivier <jean-philippe.metivier@unicaen.fr>
Date: Thu, 17 Apr 2025 09:52:10 +0200
Subject: [PATCH] ...

---
 src/Octopus/Entity/Db/Individu.php            | 47 +++++++++++++++++--
 .../Service/Individu/IndividuService.php      |  1 -
 2 files changed, 44 insertions(+), 4 deletions(-)

diff --git a/src/Octopus/Entity/Db/Individu.php b/src/Octopus/Entity/Db/Individu.php
index 622212a..4151209 100644
--- a/src/Octopus/Entity/Db/Individu.php
+++ b/src/Octopus/Entity/Db/Individu.php
@@ -5,8 +5,10 @@ namespace Octopus\Entity\Db;
 // TODO prendre les overwrites, normalisés, phonétiques
 use DateTime;
 use Doctrine\Common\Collections\ArrayCollection;
+use UnicaenUtilisateur\Service\RechercheIndividu\RechercheIndividuResultatInterface;
 
-class Individu {
+class Individu implements RechercheIndividuResultatInterface
+{
     /** @var integer */
     private $cIndividuChaine;
     /** @var Source */
@@ -75,6 +77,7 @@ class Individu {
         return $this->cIndividuChaine;
     }
 
+
     /**
      * @return Source
      */
@@ -229,7 +232,7 @@ class Individu {
         if ($active) {
             $affectations = array_filter($affectations, function(IndividuAffectation $a) { return ($a->getDateFin() === null);});
         }
-        usort($affectations, function(IndividuAffectation $a, IndividuAffectation $b) { return $a->getDateDebut() > $b->getDateDebut();});
+        usort($affectations, function(IndividuAffectation $a, IndividuAffectation $b) { return $a->getDateDebut() <=> $b->getDateDebut();});
         return $affectations;
     }
 
@@ -239,7 +242,7 @@ class Individu {
     public function getInscriptions()
     {
         $inscriptions = $this->inscriptions->toArray();
-        usort($inscriptions, function (IndividuInscription $a, IndividuInscription $b) { return $a->getAnnee() > $b->getAnnee();});
+        usort($inscriptions, function (IndividuInscription $a, IndividuInscription $b) { return $a->getAnnee() <=> $b->getAnnee();});
         return $inscriptions;
     }
 
@@ -266,4 +269,42 @@ class Individu {
         }
         return $texte;
     }
+
+    /** Missing ... */
+
+    public function getId()
+    {
+        return $this->cIndividuChaine;
+    }
+
+    public function getEmail(): ?string
+    {
+        $compteActif = null;
+        /** @var IndividuCompte $compte */
+        foreach ($this->comptes as $compte) {
+            if ($compte->getStatut() === 1) {
+                $compteActif = $compte;
+                break;
+            }
+        }
+        return $compteActif->getEmail();
+    }
+
+    public function getUsername(string $attribut = "supannAliasLogin"): string
+    {
+        $compteActif = null;
+        /** @var IndividuCompte $compte */
+        foreach ($this->comptes as $compte) {
+            if ($compte->getStatut() === 1) {
+                $compteActif = $compte;
+                break;
+            }
+        }
+        return $compteActif->getLogin();
+    }
+
+    public function getDisplayname(): string
+    {
+        return $this->prenom_ow.' '.$this->getNomUsage()??$this->getNomFamille();
+    }
 }
\ No newline at end of file
diff --git a/src/Octopus/Service/Individu/IndividuService.php b/src/Octopus/Service/Individu/IndividuService.php
index 9724863..4e6d4ca 100644
--- a/src/Octopus/Service/Individu/IndividuService.php
+++ b/src/Octopus/Service/Individu/IndividuService.php
@@ -94,7 +94,6 @@ class IndividuService {
             ->setParameter('type', 5)
             ->orderBy('individu.nomUsage, individu.prenom')
         ;
-
         $result = $qb->getQuery()->getResult();
         return $result;
     }
-- 
GitLab