Merge pull request #19307 from eileenmcnaughton/534
[civicrm-core.git] / api / v3 / GroupOrganization.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * This api exposes the relationships between organizations and CiviCRM groups.
14 *
15 * @package CiviCRM_APIv3
16 */
17
18 /**
19 * Get group organization record/s.
20 *
21 * @param array $params
22 * Name value pair of contact information.
23 *
24 * @return array
25 * list of groups, given contact subscribed to
26 */
27 function civicrm_api3_group_organization_get($params) {
28 return _civicrm_api3_basic_get('CRM_Contact_DAO_GroupOrganization', $params);
29 }
30
31 /**
32 * Create group organization record.
33 *
34 * @param array $params
35 * Array.
36 *
37 * @return array
38 */
39 function civicrm_api3_group_organization_create($params) {
40
41 return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'GroupOrganization');
42 }
43
44 /**
45 * Adjust Metadata for Create action.
46 *
47 * The metadata is used for setting defaults, documentation & validation.
48 *
49 * @param array $params
50 * Array of parameters determined by getfields.
51 */
52 function _civicrm_api3_group_organization_create_spec(&$params) {
53 $params['organization_id']['api.required'] = 1;
54 $params['group_id']['api.required'] = 1;
55 }
56
57 /**
58 * Deletes an existing Group Organization.
59 *
60 * This API is used for deleting a Group Organization
61 *
62 * @param array $params
63 * With 'id' = ID of the Group Organization to be deleted.
64 *
65 * @return array
66 * API Result
67 */
68 function civicrm_api3_group_organization_delete($params) {
69
70 $result = CRM_Contact_BAO_GroupOrganization::deleteGroupOrganization($params['id']);
71 return $result ? civicrm_api3_create_success('Deleted Group Organization successfully') : civicrm_api3_create_error('Could not delete Group Organization');
72 }