Merge pull request #17840 from seamuslee001/5272_rns
[civicrm-core.git] / api / v3 / RelationshipType.php
CommitLineData
6a488035 1<?php
6a488035
TO
2/*
3 +--------------------------------------------------------------------+
a30c801b 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
a30c801b
TO
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 |
6a488035
TO
9 +--------------------------------------------------------------------+
10 */
11
12/**
c28e1768 13 * This api exposes CiviCRM relationship types.
6a488035
TO
14 *
15 * @package CiviCRM_APIv3
6a488035
TO
16 */
17
6a488035 18/**
9d32e6f7 19 * Create relationship type.
6a488035 20 *
cf470720 21 * @param array $params
2e66abf8 22 * Array per getfields metadata.
6a488035 23 *
72b3a70c 24 * @return array
6a488035
TO
25 */
26function civicrm_api3_relationship_type_create($params) {
27
0782c7b9 28 // @todo should we when id is empty?
29 if (!isset($params['label_a_b']) && !empty($params['name_a_b'])) {
6a488035
TO
30 $params['label_a_b'] = $params['name_a_b'];
31 }
32
0782c7b9 33 if (!isset($params['label_b_a']) && !empty($params['name_b_a'])) {
6a488035
TO
34 $params['label_b_a'] = $params['name_b_a'];
35 }
36
0782c7b9 37 return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'RelationshipType');
6a488035 38}
11e09c59
TO
39
40/**
0aa0303c
EM
41 * Adjust Metadata for Create action.
42 *
43 * The metadata is used for setting defaults, documentation & validation.
1c88e578 44 *
cf470720 45 * @param array $params
b081365f 46 * Array of parameters determined by getfields.
6a488035
TO
47 */
48function _civicrm_api3_relationship_type_create_spec(&$params) {
6a488035
TO
49 $params['name_a_b']['api.required'] = 1;
50 $params['name_b_a']['api.required'] = 1;
4471f8ca 51 $params['is_active']['api.default'] = 1;
6a488035
TO
52}
53
54/**
9d32e6f7
EM
55 * Get all relationship types.
56 *
d0997921 57 * @param array $params
d1b0d05e 58 *
645ee340 59 * @return array
6a488035
TO
60 */
61function civicrm_api3_relationship_type_get($params) {
6a488035
TO
62 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
63}
64
65/**
9d32e6f7 66 * Delete a relationship type.
6a488035 67 *
488e7aba 68 * @param array $params
6a488035 69 *
a6c01b45 70 * @return array
72b3a70c 71 * API Result Array
6a488035
TO
72 */
73function civicrm_api3_relationship_type_delete($params) {
b2402735 74 return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
6a488035 75}
bc255d1d
CW
76
77/**
9d32e6f7
EM
78 * Get list defaults for relationship types.
79 *
bc255d1d
CW
80 * @see _civicrm_api3_generic_getlist_defaults
81 *
82 * @param array $request
dc64d047 83 *
bc255d1d
CW
84 * @return array
85 */
86function _civicrm_api3_relationship_type_getlist_defaults($request) {
cf8f0fff 87 return [
bc255d1d
CW
88 'label_field' => 'label_a_b',
89 'search_field' => 'label_a_b',
cf8f0fff 90 ];
cbcb7579 91}