| 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 | |
| 12 | namespace Civi\Api4\Query; |
| 13 | |
| 14 | /** |
| 15 | * Sql function |
| 16 | */ |
| 17 | class SqlFunctionGROUP_CONCAT extends SqlFunction { |
| 18 | |
| 19 | public $supportsExpansion = TRUE; |
| 20 | |
| 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, |
| 42 | // @see self::formatOutput() |
| 43 | 'api_default' => [ |
| 44 | 'expr' => ['"' . \CRM_Core_DAO::VALUE_SEPARATOR . '"'], |
| 45 | ], |
| 46 | ], |
| 47 | ]; |
| 48 | |
| 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 | |
| 64 | /** |
| 65 | * @return string |
| 66 | */ |
| 67 | public static function getTitle(): string { |
| 68 | return ts('List'); |
| 69 | } |
| 70 | |
| 71 | } |