5 +--------------------------------------------------------------------+
6 | CiviCRM version 4.3 |
7 +--------------------------------------------------------------------+
8 | Copyright CiviCRM LLC (c) 2004-2013 |
9 +--------------------------------------------------------------------+
10 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * new version of civicrm apis. See blog post at
32 * http://civicrm.org/node/131
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 $
42 * Include common API util functions
44 require_once 'CRM/Contact/BAO/RelationshipType.php';
47 * Function to create relationship type
49 * @param array $params Associative array of property name/value pairs to insert in new relationship type.
51 * @return Newly created Relationship_type object
52 * {@getfields RelationshipType_create}
54 * {@schema Contact/RelationshipType.xml}
56 function civicrm_api3_relationship_type_create($params) {
58 if (!isset($params['label_a_b'])) {
60 $params['label_a_b'] = $params['name_a_b'];
63 if (!isset($params['label_b_a'])) {
65 $params['label_b_a'] = $params['name_b_a'];
68 require_once 'CRM/Utils/Rule.php';
71 if (isset($params['id']) && !CRM_Utils_Rule
::integer($params['id'])) {
72 return civicrm_api3_create_error('Invalid value for relationship type ID');
75 $ids['relationshipType'] = CRM_Utils_Array
::value('id', $params);
78 $relationType = new CRM_Contact_BAO_RelationshipType();
79 $relationType = CRM_Contact_BAO_RelationshipType
::add($params, $ids);
83 _civicrm_api3_object_to_array($relationType, $relType[$relationType->id
]);
85 return civicrm_api3_create_success($relType, $params, 'relationship_type', 'create', $relationType);
89 * Adjust Metadata for Create action
91 * The metadata is used for setting defaults, documentation & validation
92 * @param array $params array or parameters determined by getfields
94 function _civicrm_api3_relationship_type_create_spec(&$params) {
95 $params['contact_type_a']['api.required'] = 1;
96 $params['contact_type_b']['api.required'] = 1;
97 $params['name_a_b']['api.required'] = 1;
98 $params['name_b_a']['api.required'] = 1;
102 * Function to get all relationship type
103 * retruns An array of Relationship_type
105 * {@getfields RelationshipType_get}
106 * @example RelationshipTypeGet.php
108 function civicrm_api3_relationship_type_get($params) {
110 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__
), $params);
114 * Delete a relationship type delete
116 * @param id of relationship type $id
118 * @return array API Result Array
119 * {@getfields RelationshipType_delete}
123 function civicrm_api3_relationship_type_delete($params) {
125 require_once 'CRM/Utils/Rule.php';
126 if ($params['id'] != NULL && !CRM_Utils_Rule
::integer($params['id'])) {
127 return civicrm_api3_create_error('Invalid value for relationship type ID');
130 $relationTypeBAO = new CRM_Contact_BAO_RelationshipType();
131 $result = $relationTypeBAO->del($params['id']);
133 return civicrm_api3_create_error('Could not delete relationship type');
135 return civicrm_api3_create_success($result, $params, 'relationship_type', 'delete', $relationTypeBAO);