4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.3 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
30 * new version of civicrm apis. See blog post at
31 * http://civicrm.org/node/131
33 * @package CiviCRM_APIv3
34 * @subpackage API_Contact
35 * @copyright CiviCRM LLC (c) 2004-2013
36 * $Id: Contact.php 30415 2010-10-29 12:02:47Z shot $
41 * Function to create relationship type
43 * @param array $params Associative array of property name/value pairs to insert in new relationship type.
45 * @return Newly created Relationship_type object
46 * {@getfields RelationshipType_create}
48 * {@schema Contact/RelationshipType.xml}
50 function civicrm_api3_relationship_type_create($params) {
52 if (!isset($params['label_a_b'])) {
54 $params['label_a_b'] = $params['name_a_b'];
57 if (!isset($params['label_b_a'])) {
59 $params['label_b_a'] = $params['name_b_a'];
63 if (isset($params['id']) && !CRM_Utils_Rule
::integer($params['id'])) {
64 return civicrm_api3_create_error('Invalid value for relationship type ID');
67 $ids['relationshipType'] = CRM_Utils_Array
::value('id', $params);
70 $relationType = new CRM_Contact_BAO_RelationshipType();
71 $relationType = CRM_Contact_BAO_RelationshipType
::add($params, $ids);
75 _civicrm_api3_object_to_array($relationType, $relType[$relationType->id
]);
77 return civicrm_api3_create_success($relType, $params, 'relationship_type', 'create', $relationType);
81 * Adjust Metadata for Create action
83 * The metadata is used for setting defaults, documentation & validation
84 * @param array $params array or parameters determined by getfields
86 function _civicrm_api3_relationship_type_create_spec(&$params) {
87 $params['contact_type_a']['api.required'] = 1;
88 $params['contact_type_b']['api.required'] = 1;
89 $params['name_a_b']['api.required'] = 1;
90 $params['name_b_a']['api.required'] = 1;
94 * Function to get all relationship type
95 * retruns An array of Relationship_type
97 * {@getfields RelationshipType_get}
98 * @example RelationshipTypeGet.php
100 function civicrm_api3_relationship_type_get($params) {
102 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__
), $params);
106 * Delete a relationship type delete
108 * @param id of relationship type $id
110 * @return array API Result Array
111 * {@getfields RelationshipType_delete}
115 function civicrm_api3_relationship_type_delete($params) {
117 if ($params['id'] != NULL && !CRM_Utils_Rule
::integer($params['id'])) {
118 return civicrm_api3_create_error('Invalid value for relationship type ID');
121 $relationTypeBAO = new CRM_Contact_BAO_RelationshipType();
122 $result = $relationTypeBAO->del($params['id']);
124 return civicrm_api3_create_error('Could not delete relationship type');
126 return civicrm_api3_create_success($result, $params, 'relationship_type', 'delete', $relationTypeBAO);