Improve LSldapObject::getDisplayValue() method to match with getValue() method's parameters

This commit is contained in:
Benjamin Renard 2023-09-18 16:59:33 +02:00
parent 95f60a534a
commit 11a8448b0a
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC

View file

@ -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 <brenard@easter-eggs.com> * @author Benjamin Renard <brenard@easter-eggs.com>
* *
* @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) { public function getDisplayValue($val, $first=false, $default=' ') {
if(isset($this -> attrs[$val])){ $return = $default;
if (method_exists($this -> attrs[$val],'getDisplayValue')) if(isset($this -> attrs[$val]) && method_exists($this -> attrs[$val], 'getDisplayValue'))
return $this -> attrs[$val] -> getDisplayValue(); $return = ensureIsArray($this -> attrs[$val] -> getDisplayValue());
else if (is_array($return) && $first)
return ' '; $return = (count($return) >= 1?$return[0]:null);
} return $return;
else {
return $this -> getValue($val);
}
} }
/** /**