23eed7dfce79372f8ff683297cbf24dfcb05fefc
[civicrm-core.git] / api / v3 / Generic / Getunique.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28 /**
29 * @package CiviCRM_APIv3
30 */
31
32 /**
33 * Generic api wrapper used to get all unique fields for a given entity.
34 *
35 * @param array $apiRequest
36 *
37 * @return mixed
38 */
39 function civicrm_api3_generic_getunique($apiRequest) {
40 $entity = _civicrm_api_get_entity_name_from_camel($apiRequest['entity']);
41 $uniqueFields = array();
42
43 $dao = _civicrm_api3_get_DAO($entity);
44 $uFields = $dao::indices();
45
46 foreach ($uFields as $fieldKey => $field) {
47 if (!isset($field['unique']) || !$field['unique']) {
48 continue;
49 }
50 $uniqueFields[$fieldKey] = $field['field'];
51 }
52
53 return civicrm_api3_create_success($uniqueFields);
54 }