From c87f6096109b9f60aff2ced4efd9ae497df94161 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Fri, 11 Jun 2021 16:36:19 +0200 Subject: [PATCH] LSformElement_supannLabeledValue: improve API mode --- ...class.LSformElement_supannLabeledValue.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/includes/class/class.LSformElement_supannLabeledValue.php b/src/includes/class/class.LSformElement_supannLabeledValue.php index 937005a6..01c4beca 100644 --- a/src/includes/class/class.LSformElement_supannLabeledValue.php +++ b/src/includes/class/class.LSformElement_supannLabeledValue.php @@ -209,4 +209,27 @@ class LSformElement_supannLabeledValue extends LSformElement { return $retval; } + /** + * Retreive value as return in API response + * + * @param[in] $details boolean If true, returned values will contain details if this field type + * support it (optional, default: false) + * + * @retval mixed API value(s) or null/empty array if no value + */ + public function getApiValue($details=false) { + $values = array(); + foreach(ensureIsArray($this -> values) as $value) { + $decodedValue = $this -> parseValue($value); + if (is_array($decodedValue)) { + $values[] = ($details?$decodedValue:$decodedValue['value']); + } + } + if ($this -> isMultiple()) { + return $values; + } + if (!$values) + return null; + return $values[0]; + } }