From 984f0c4e15511b11009e192ae3f1202be22a524f Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sun, 18 Jul 2021 11:16:20 -0400 Subject: [PATCH] APIv4 - Better handling of output value using GROUP_CONCAT --- Civi/Api4/Query/SqlFunctionCONCAT.php | 13 +++++++++++++ Civi/Api4/Query/SqlFunctionGROUP_CONCAT.php | 6 +++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Civi/Api4/Query/SqlFunctionCONCAT.php b/Civi/Api4/Query/SqlFunctionCONCAT.php index 5dc63348a1..e7d05b88e7 100644 --- a/Civi/Api4/Query/SqlFunctionCONCAT.php +++ b/Civi/Api4/Query/SqlFunctionCONCAT.php @@ -33,4 +33,17 @@ class SqlFunctionCONCAT extends SqlFunction { return ts('Combine'); } + /** + * Prevent reformatting of result + * + * @see \Civi\Api4\Utils\FormattingUtil::formatOutputValues + * @param string $value + * @param string $dataType + * @return string|array + */ + public function formatOutputValue($value, &$dataType) { + $dataType = NULL; + return $value; + } + } diff --git a/Civi/Api4/Query/SqlFunctionGROUP_CONCAT.php b/Civi/Api4/Query/SqlFunctionGROUP_CONCAT.php index 0e0f7525b8..bb39289c0e 100644 --- a/Civi/Api4/Query/SqlFunctionGROUP_CONCAT.php +++ b/Civi/Api4/Query/SqlFunctionGROUP_CONCAT.php @@ -59,9 +59,9 @@ class SqlFunctionGROUP_CONCAT extends SqlFunction { // By default, values are split into an array and formatted according to the field's dataType if (!$exprArgs[2]['prefix']) { $value = explode(\CRM_Core_DAO::VALUE_SEPARATOR, $value); - // If the first expression is another sqlFunction then unset $dataType to preserve raw string - if ($exprArgs[0]['expr'][0] instanceof SqlFunction) { - $dataType = NULL; + // If the first expression is another sqlFunction, allow it to control the dataType + if ($exprArgs[0]['expr'][0] instanceof SqlFunction && is_callable([$exprArgs[0]['expr'][0], 'formatOutputValue'])) { + $exprArgs[0]['expr'][0]->formatOutputValue(NULL, $dataType); } } // If using custom separator, unset $dataType to preserve raw string -- 2.25.1