APIv4 Search: Improve GROUP_CONCAT with :label prefix
[civicrm-core.git] / Civi / Api4 / Query / SqlFunctionGROUP_CONCAT.php
CommitLineData
e7f6def6
CW
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 +--------------------------------------------------------------------+
10 */
11
12namespace Civi\Api4\Query;
13
14/**
15 * Sql function
16 */
17class SqlFunctionGROUP_CONCAT extends SqlFunction {
18
7ce7b1cd
CW
19 public $supportsExpansion = TRUE;
20
e7f6def6
CW
21 protected static $category = self::CATEGORY_AGGREGATE;
22
23 protected static $params = [
24 [
25 'prefix' => ['', 'DISTINCT', 'ALL'],
26 'expr' => 1,
27 'must_be' => ['SqlField'],
28 'optional' => FALSE,
29 ],
30 [
31 'prefix' => ['ORDER BY'],
32 'expr' => 1,
33 'suffix' => ['', 'ASC', 'DESC'],
34 'must_be' => ['SqlField'],
35 'optional' => TRUE,
36 ],
37 [
38 'prefix' => ['SEPARATOR'],
39 'expr' => 1,
40 'must_be' => ['SqlString'],
41 'optional' => TRUE,
7ce7b1cd
CW
42 // @see self::formatOutput()
43 'api_default' => [
44 'expr' => ['"' . \CRM_Core_DAO::VALUE_SEPARATOR . '"'],
45 ],
e7f6def6
CW
46 ],
47 ];
48
7ce7b1cd
CW
49 /**
50 * Reformat result as array if using default separator
51 *
52 * @see \Civi\Api4\Utils\FormattingUtil::formatOutputValues
53 * @param string $value
54 * @return string|array
55 */
56 public function formatOutputValue($value) {
57 $exprArgs = $this->getArgs();
58 if (!$exprArgs[2]['prefix']) {
59 $value = explode(\CRM_Core_DAO::VALUE_SEPARATOR, $value);
60 }
61 return $value;
62 }
63
9cae8a07
CW
64 /**
65 * @return string
66 */
67 public static function getTitle(): string {
68 return ts('List');
69 }
70
e7f6def6 71}