INFRA-132 - Fix @static docblock tag
[civicrm-core.git] / api / v3 / RelationshipType.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 * new version of civicrm apis. See blog post at
30 * http://civicrm.org/node/131
31 *
32 * @package CiviCRM_APIv3
33 * @subpackage API_Contact
34 * @copyright CiviCRM LLC (c) 2004-2014
35 * $Id: Contact.php 30415 2010-10-29 12:02:47Z shot $
36 *
37 */
38
39 /**
40 * create relationship type
41 *
42 * @param array $params
43 * Associative array of property name/value pairs to insert in new relationship type.
44 *
45 * @return array
46 * {@getfields RelationshipType_create}
47 * @access public
48 * {@schema Contact/RelationshipType.xml}
49 */
50 function civicrm_api3_relationship_type_create($params) {
51
52 if (!isset($params['label_a_b'])) {
53
54 $params['label_a_b'] = $params['name_a_b'];
55 }
56
57 if (!isset($params['label_b_a'])) {
58
59 $params['label_b_a'] = $params['name_b_a'];
60 }
61
62 $ids = array();
63 if (isset($params['id']) && !CRM_Utils_Rule::integer($params['id'])) {
64 return civicrm_api3_create_error('Invalid value for relationship type ID');
65 }
66 else {
67 $ids['relationshipType'] = CRM_Utils_Array::value('id', $params);
68 }
69
70 $relationType = new CRM_Contact_BAO_RelationshipType();
71 $relationType = CRM_Contact_BAO_RelationshipType::add($params, $ids);
72
73 $relType = array();
74
75 _civicrm_api3_object_to_array($relationType, $relType[$relationType->id]);
76
77 return civicrm_api3_create_success($relType, $params, 'relationship_type', 'create', $relationType);
78 }
79
80 /**
81 * Adjust Metadata for Create action
82 *
83 * The metadata is used for setting defaults, documentation & validation
84 * @param array $params
85 * Array or parameters determined by getfields.
86 */
87 function _civicrm_api3_relationship_type_create_spec(&$params) {
88 $params['contact_type_a']['api.required'] = 1;
89 $params['contact_type_b']['api.required'] = 1;
90 $params['name_a_b']['api.required'] = 1;
91 $params['name_b_a']['api.required'] = 1;
92 $params['is_active']['api.default'] = 1;
93 }
94
95 /**
96 * get all relationship type
97 * retruns An array of Relationship_type
98 * @access public
99 * {@getfields RelationshipType_get}
100 * @example RelationshipTypeGet.php
101 */
102 function civicrm_api3_relationship_type_get($params) {
103 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
104 }
105
106 /**
107 * Delete a relationship type delete
108 *
109 * @param id of relationship type $id
110 *
111 * @return array
112 * API Result Array
113 * {@getfields RelationshipType_delete}
114 * @static
115 * @access public
116 */
117 function civicrm_api3_relationship_type_delete($params) {
118 return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
119 }