Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | // $Id$ | |
3 | ||
4 | /* | |
5 | +--------------------------------------------------------------------+ | |
6 | | CiviCRM version 4.3 | | |
7 | +--------------------------------------------------------------------+ | |
8 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
9 | +--------------------------------------------------------------------+ | |
10 | | This file is a part of CiviCRM. | | |
11 | | | | |
12 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
13 | | under the terms of the GNU Affero General Public License | | |
14 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
15 | | | | |
16 | | CiviCRM is distributed in the hope that it will be useful, but | | |
17 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
18 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
19 | | See the GNU Affero General Public License for more details. | | |
20 | | | | |
21 | | You should have received a copy of the GNU Affero General Public | | |
22 | | License and the CiviCRM Licensing Exception along | | |
23 | | with this program; if not, contact CiviCRM LLC | | |
24 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
25 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
26 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
27 | +--------------------------------------------------------------------+ | |
28 | */ | |
29 | ||
30 | /** | |
31 | * new version of civicrm apis. See blog post at | |
32 | * http://civicrm.org/node/131 | |
33 | * | |
34 | * @package CiviCRM_APIv3 | |
35 | * @subpackage API_Contact | |
36 | * @copyright CiviCRM LLC (c) 2004-2013 | |
37 | * $Id: Contact.php 30415 2010-10-29 12:02:47Z shot $ | |
38 | * | |
39 | */ | |
40 | ||
6a488035 TO |
41 | /** |
42 | * Function to create relationship type | |
43 | * | |
44 | * @param array $params Associative array of property name/value pairs to insert in new relationship type. | |
45 | * | |
46 | * @return Newly created Relationship_type object | |
47 | * {@getfields RelationshipType_create} | |
48 | * @access public | |
49 | * {@schema Contact/RelationshipType.xml} | |
50 | */ | |
51 | function civicrm_api3_relationship_type_create($params) { | |
52 | ||
53 | if (!isset($params['label_a_b'])) { | |
54 | ||
55 | $params['label_a_b'] = $params['name_a_b']; | |
56 | } | |
57 | ||
58 | if (!isset($params['label_b_a'])) { | |
59 | ||
60 | $params['label_b_a'] = $params['name_b_a']; | |
61 | } | |
62 | ||
6a488035 TO |
63 | $ids = array(); |
64 | if (isset($params['id']) && !CRM_Utils_Rule::integer($params['id'])) { | |
65 | return civicrm_api3_create_error('Invalid value for relationship type ID'); | |
66 | } | |
67 | else { | |
68 | $ids['relationshipType'] = CRM_Utils_Array::value('id', $params); | |
69 | } | |
70 | ||
71 | $relationType = new CRM_Contact_BAO_RelationshipType(); | |
72 | $relationType = CRM_Contact_BAO_RelationshipType::add($params, $ids); | |
73 | ||
74 | $relType = array(); | |
75 | ||
76 | _civicrm_api3_object_to_array($relationType, $relType[$relationType->id]); | |
77 | ||
78 | return civicrm_api3_create_success($relType, $params, 'relationship_type', 'create', $relationType); | |
79 | } | |
11e09c59 TO |
80 | |
81 | /** | |
6a488035 TO |
82 | * Adjust Metadata for Create action |
83 | * | |
84 | * The metadata is used for setting defaults, documentation & validation | |
85 | * @param array $params 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 | } | |
93 | ||
94 | /** | |
95 | * Function to get all relationship type | |
96 | * retruns An array of Relationship_type | |
97 | * @access public | |
98 | * {@getfields RelationshipType_get} | |
99 | * @example RelationshipTypeGet.php | |
100 | */ | |
101 | function civicrm_api3_relationship_type_get($params) { | |
102 | ||
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 API Result Array | |
112 | * {@getfields RelationshipType_delete} | |
113 | * @static void | |
114 | * @access public | |
115 | */ | |
116 | function civicrm_api3_relationship_type_delete($params) { | |
117 | ||
6a488035 TO |
118 | if ($params['id'] != NULL && !CRM_Utils_Rule::integer($params['id'])) { |
119 | return civicrm_api3_create_error('Invalid value for relationship type ID'); | |
120 | } | |
121 | ||
122 | $relationTypeBAO = new CRM_Contact_BAO_RelationshipType(); | |
123 | $result = $relationTypeBAO->del($params['id']); | |
124 | if (!$result) { | |
125 | return civicrm_api3_create_error('Could not delete relationship type'); | |
126 | } | |
127 | return civicrm_api3_create_success($result, $params, 'relationship_type', 'delete', $relationTypeBAO); | |
128 | } | |
129 |