Merge pull request #17656 from civicrm/5.27
[civicrm-core.git] / api / v3 / RelationshipType.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 * This api exposes CiviCRM relationship types.
14 *
15 * @package CiviCRM_APIv3
16 */
17
18 /**
19 * Create relationship type.
20 *
21 * @param array $params
22 * Array per getfields metadata.
23 *
24 * @return array
25 */
26 function civicrm_api3_relationship_type_create($params) {
27
28 // @todo should we when id is empty?
29 if (!isset($params['label_a_b']) && !empty($params['name_a_b'])) {
30 $params['label_a_b'] = $params['name_a_b'];
31 }
32
33 if (!isset($params['label_b_a']) && !empty($params['name_b_a'])) {
34 $params['label_b_a'] = $params['name_b_a'];
35 }
36
37 return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'RelationshipType');
38 }
39
40 /**
41 * Adjust Metadata for Create action.
42 *
43 * The metadata is used for setting defaults, documentation & validation.
44 *
45 * @param array $params
46 * Array of parameters determined by getfields.
47 */
48 function _civicrm_api3_relationship_type_create_spec(&$params) {
49 $params['name_a_b']['api.required'] = 1;
50 $params['name_b_a']['api.required'] = 1;
51 $params['is_active']['api.default'] = 1;
52 }
53
54 /**
55 * Get all relationship types.
56 *
57 * @param array $params
58 *
59 * @return array
60 */
61 function civicrm_api3_relationship_type_get($params) {
62 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
63 }
64
65 /**
66 * Delete a relationship type.
67 *
68 * @param array $params
69 *
70 * @return array
71 * API Result Array
72 */
73 function civicrm_api3_relationship_type_delete($params) {
74 return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
75 }
76
77 /**
78 * Get list defaults for relationship types.
79 *
80 * @see _civicrm_api3_generic_getlist_defaults
81 *
82 * @param array $request
83 *
84 * @return array
85 */
86 function _civicrm_api3_relationship_type_getlist_defaults($request) {
87 return [
88 'label_field' => 'label_a_b',
89 'search_field' => 'label_a_b',
90 ];
91 }