From 0063bdffa6a2a682433eb1b8e65696755b7120c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20L=C3=A9cluse?= <laurent.lecluse@unicaen.fr> Date: Fri, 20 Dec 2019 16:43:36 +0100 Subject: [PATCH] =?UTF-8?q?Posibilit=C3=A9=20e=20ne=20retourner=20qu'une?= =?UTF-8?q?=20seule=20valeur=20si=20on=20est=20s=C3=BBr=20que=20jamais=20o?= =?UTF-8?q?n=20n'aura=20besoin=20d'un=20tableau?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/UnicaenApp/Entity/Ldap/AbstractEntity.php | 18 ++++++++++++++++++ src/UnicaenApp/Entity/Ldap/People.php | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/UnicaenApp/Entity/Ldap/AbstractEntity.php b/src/UnicaenApp/Entity/Ldap/AbstractEntity.php index cfc48efd..fcce80c1 100644 --- a/src/UnicaenApp/Entity/Ldap/AbstractEntity.php +++ b/src/UnicaenApp/Entity/Ldap/AbstractEntity.php @@ -52,6 +52,24 @@ abstract class AbstractEntity * @return self */ abstract public function setData(array $data = array()); + + + + /** + * Prend un attribut LDAP en entrée. Si l'atribut a plusieurs valeurs on n'en prend qu'une seule + * + * @param $value + * + * @return mixed + */ + protected function uniqueValue($value) + { + if (is_array($value) && isset($value[0])){ + return $value[0]; + } + + return $value; + } /** * Simplifie le format d'une valeur d'un attribut. diff --git a/src/UnicaenApp/Entity/Ldap/People.php b/src/UnicaenApp/Entity/Ldap/People.php index f9411ca0..0d5f4d4e 100644 --- a/src/UnicaenApp/Entity/Ldap/People.php +++ b/src/UnicaenApp/Entity/Ldap/People.php @@ -69,8 +69,8 @@ class People extends AbstractEntity $this->dn = $this->processDataValue('dn', true); $this->cn = $this->processDataValue('cn'); $this->datedenaissance = $this->processDataValue('datedenaissance'); - $this->displayname = $this->processDataValue('displayname'); - $this->givenname = $this->processDataValue('givenname'); + $this->displayname = $this->uniqueValue($this->processDataValue('displayname')); + $this->givenname = $this->uniqueValue($this->processDataValue('givenname')); $this->mail = $this->processDataValue('mail'); $this->postaladdress = $this->processDataValue('postaladdress'); $this->sexe = $this->processDataValue('sexe'); -- GitLab