From 11a8448b0ae0c61fda3e18819654e1c9bbc806ae Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Mon, 18 Sep 2023 16:59:33 +0200 Subject: [PATCH] Improve LSldapObject::getDisplayValue() method to match with getValue() method's parameters --- src/includes/class/class.LSldapObject.php | 31 +++++++++++++---------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/includes/class/class.LSldapObject.php b/src/includes/class/class.LSldapObject.php index 0ad16203..23ae8483 100644 --- a/src/includes/class/class.LSldapObject.php +++ b/src/includes/class/class.LSldapObject.php @@ -1079,24 +1079,29 @@ class LSldapObject extends LSlog_staticLoggerClass { } /** - * Retourne une valeur d'affichage de l'objet + * Return an objet displayed value + * + * The value returned depends of the $val parameter. If the requested value is unknown, the returned value + * will be $default (default: a space caracter = ' '). + * + * Supported values: + * - [attribute name] : the displayed value of the corresponding attribute * * @author Benjamin Renard * - * @param string $val Le nom de la valeur demandee + * @param string $val The requested value + * @param boolean $first If true and the result is an array, return only the first value (optional, default: false) + * @param string $default Default value if unknown (optional, default: a space caracter = ' ') * - * @return string la valeur demandee ou ' ' si celle-ci est inconnue. + * @return mixed The requested value or $default if unknown */ - public function getDisplayValue($val) { - if(isset($this -> attrs[$val])){ - if (method_exists($this -> attrs[$val],'getDisplayValue')) - return $this -> attrs[$val] -> getDisplayValue(); - else - return ' '; - } - else { - return $this -> getValue($val); - } + public function getDisplayValue($val, $first=false, $default=' ') { + $return = $default; + if(isset($this -> attrs[$val]) && method_exists($this -> attrs[$val], 'getDisplayValue')) + $return = ensureIsArray($this -> attrs[$val] -> getDisplayValue()); + if (is_array($return) && $first) + $return = (count($return) >= 1?$return[0]:null); + return $return; } /**