3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
12 namespace Civi\Api4\Query
;
17 class SqlFunctionGROUP_CONCAT
extends SqlFunction
{
19 public $supportsExpansion = TRUE;
21 protected static $category = self
::CATEGORY_AGGREGATE
;
23 protected static function params(): array {
26 'flag_before' => ['DISTINCT' => ts('Distinct')],
28 'must_be' => ['SqlField', 'SqlFunction'],
32 'prefix' => 'ORDER BY',
34 'flag_after' => ['ASC' => ts('Ascending'), 'DESC' => ts('Descending')],
35 'must_be' => ['SqlField'],
39 'prefix' => 'SEPARATOR',
41 'must_be' => ['SqlString'],
43 // @see self::formatOutput()
45 'expr' => ['"' . \CRM_Core_DAO
::VALUE_SEPARATOR
. '"'],
52 * Reformat result as array if using default separator
54 * @see \Civi\Api4\Utils\FormattingUtil::formatOutputValues
55 * @param string $value
56 * @param string $dataType
57 * @return string|array
59 public function formatOutputValue($value, &$dataType) {
60 $exprArgs = $this->getArgs();
61 // By default, values are split into an array and formatted according to the field's dataType
62 if (isset($exprArgs[2]['expr'][0]->expr
) && $exprArgs[2]['expr'][0]->expr
=== \CRM_Core_DAO
::VALUE_SEPARATOR
) {
63 $value = explode(\CRM_Core_DAO
::VALUE_SEPARATOR
, $value);
64 // If the first expression is another sqlFunction, allow it to control the dataType
65 if ($exprArgs[0]['expr'][0] instanceof SqlFunction
) {
66 $exprArgs[0]['expr'][0]->formatOutputValue(NULL, $dataType);
69 // If using custom separator, preserve raw string
79 public static function getTitle(): string {