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 * File for the CiviCRM APIv2 group contact functions
33 * @package CiviCRM_APIv2
34 * @subpackage API_Group
36 * @copyright CiviCRM LLC (c) 2004-2013
37 * @version $Id: GroupContact.php 21624 2009-06-04 22:02:55Z mover $
42 * Include utility functions
44 require_once 'api/v2/utils.php';
47 * This API will give list of the groups for particular contact
48 * Particualr status can be sent in params array
49 * If no status mentioned in params, by default 'added' will be used
50 * to fetch the records
52 * @param array $params name value pair of contact information
54 * @return array list of groups, given contact subsribed to
56 function civicrm_group_organization_get(&$params) {
57 _civicrm_initialize();
59 if (!is_array($params)) {
60 return civicrm_create_error(ts('Input parameter is not an array'));
64 return civicrm_create_error('No input parameter present');
67 if (!array_key_exists('organization_id', $params) &&
68 !array_key_exists('group_id', $params)
70 return civicrm_create_error(ts('at least one of organization_id or group_id is a required field'));
73 require_once 'CRM/Contact/DAO/GroupOrganization.php';
74 $dao = new CRM_Contact_DAO_GroupOrganization();
75 if (array_key_exists('organization_id', $params)) {
76 $dao->organization_id
= $params['organization_id'];
78 if (array_key_exists('group_id', $params)) {
79 $dao->group_id
= $params['group_id'];
83 _civicrm_object_to_array($dao, $values);
84 return civicrm_create_success($values);
89 * @param <type> $params
93 function civicrm_group_organization_create(&$params) {
95 if (!is_array($params)) {
96 return civicrm_create_error(ts('Input parameter is not an array'));
100 return civicrm_create_error('No input parameter present');
103 if (!array_key_exists('organization_id', $params) ||
104 !array_key_exists('group_id', $params)
106 return civicrm_create_error(ts('organization_id and group_id are required field'));
109 require_once 'CRM/Contact/BAO/GroupOrganization.php';
110 $groupOrgBAO = CRM_Contact_BAO_GroupOrganization
::add($params);
111 if (is_a($groupOrgBAO, 'CRM_Core_Error') ||
is_null($groupOrgBAO)) {
112 return civicrm_create_error("Group Organization can not be created");
114 _civicrm_object_to_array($groupOrgBAO, $values);
115 return civicrm_create_success($values);
119 * Deletes an existing Group Organization
121 * This API is used for deleting a Group Organization
123 * @param Array $params ID of the Group Organization to be deleted
125 * @return null if successfull, array with is_error = 1 otherwise
128 function civicrm_group_organization_remove(&$params) {
129 _civicrm_initialize();
131 if (!is_array($params)) {
132 $error = civicrm_create_error('Input parameter is not an array');
136 if (empty($params)) {
137 return civicrm_create_error('No input parameter present');
140 if (!CRM_Utils_Array
::value('id', $params)) {
141 $error = civicrm_create_error('Invalid or no value for Group Organization ID');
144 require_once 'CRM/Contact/BAO/GroupOrganization.php';
145 $result = CRM_Contact_BAO_GroupOrganization
::delete($params['id']);
146 return $result ?
civicrm_create_success(ts('Deleted Group Organization successfully')) : civicrm_create_error(ts('Could not delete Group Organization'));