Merge pull request #19683 from colemanw/searchDisplayFixes
[civicrm-core.git] / api / v3 / Generic / Getunique.php
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 /**
13 * @package CiviCRM_APIv3
14 */
15
16 /**
17 * Generic api wrapper used to get all unique fields for a given entity.
18 *
19 * @param array $apiRequest
20 *
21 * @return mixed
22 */
23 function civicrm_api3_generic_getunique($apiRequest) {
24 $entity = _civicrm_api_get_entity_name_from_camel($apiRequest['entity']);
25 $uniqueFields = [];
26
27 $dao = _civicrm_api3_get_DAO($entity);
28 $uFields = $dao::indices();
29
30 foreach ($uFields as $fieldKey => $field) {
31 if (!isset($field['unique']) || !$field['unique']) {
32 continue;
33 }
34 $uniqueFields[$fieldKey] = $field['field'];
35 }
36
37 return civicrm_api3_create_success($uniqueFields);
38 }