INFRA-132 - Fix spacing of @return tag in comments
[civicrm-core.git] / api / v3 / RelationshipType.php
CommitLineData
6a488035 1<?php
6a488035
TO
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
6a488035 5 +--------------------------------------------------------------------+
731a0992 6 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
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
731a0992 34 * @copyright CiviCRM LLC (c) 2004-2014
6a488035
TO
35 * $Id: Contact.php 30415 2010-10-29 12:02:47Z shot $
36 *
37 */
38
6a488035 39/**
c490a46a 40 * create relationship type
6a488035 41 *
cf470720
TO
42 * @param array $params
43 * Associative array of property name/value pairs to insert in new relationship type.
6a488035
TO
44 *
45 * @return Newly created Relationship_type object
46 * {@getfields RelationshipType_create}
47 * @access public
48 * {@schema Contact/RelationshipType.xml}
49 */
50function 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
6a488035
TO
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}
11e09c59
TO
79
80/**
6a488035 81 * Adjust Metadata for Create action
1c88e578 82 *
6a488035 83 * The metadata is used for setting defaults, documentation & validation
cf470720
TO
84 * @param array $params
85 * Array or parameters determined by getfields.
6a488035
TO
86 */
87function _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;
4471f8ca 92 $params['is_active']['api.default'] = 1;
6a488035
TO
93}
94
95/**
c490a46a 96 * get all relationship type
6a488035
TO
97 * retruns An array of Relationship_type
98 * @access public
99 * {@getfields RelationshipType_get}
100 * @example RelationshipTypeGet.php
101 */
102function civicrm_api3_relationship_type_get($params) {
6a488035
TO
103 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
104}
105
106/**
107 * Delete a relationship type delete
108 *
cf470720 109 * @param id of relationship type $id
6a488035 110 *
a6c01b45
CW
111 * @return array
112 * API Result Array
6a488035
TO
113 * {@getfields RelationshipType_delete}
114 * @static void
115 * @access public
116 */
117function civicrm_api3_relationship_type_delete($params) {
b2402735 118 return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
6a488035 119}