3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
37 class CRM_Bridge_OG_Drupal
{
43 static function nodeapi(&$params, $op) {
45 $transaction = new CRM_Core_Transaction();
47 // first create or update the CiviCRM group
48 $groupParams = $params;
49 $groupParams['source'] = CRM_Bridge_OG_Utils
::ogSyncName($params['og_id']);
50 $groupParams['group_type'] = array('2' => 1);
51 self
::updateCiviGroup($groupParams, $op);
53 if (CRM_Bridge_OG_Utils
::aclEnabled()) {
54 // next create or update the CiviCRM ACL group
56 $aclParams['name'] = $aclParams['title'] = "{$aclParams['name']}: Administrator";
57 $aclParams['source'] = CRM_Bridge_OG_Utils
::ogSyncACLName($params['og_id']);
58 $aclParams['group_type'] = array('1');
59 self
::updateCiviGroup($aclParams, $op);
61 $aclParams['acl_group_id'] = $aclParams['group_id'];
62 $aclParams['civicrm_group_id'] = $groupParams['group_id'];
64 self
::updateCiviACLTables($aclParams, $op);
67 $transaction->commit();
73 * @param null $groupType
75 static function updateCiviGroup(&$params, $op, $groupType = NULL) {
77 $params['version'] = 3;
78 $params['id'] = CRM_Bridge_OG_Utils
::groupID($params['source'], $params['title'], $abort);
82 $params['group_type'] = $groupType;
85 $group = civicrm_api('group', 'create', $params);
86 if (!civicrm_error($group)) {
87 $params['group_id'] = $group['id'];
91 // do this only if we have a valid id
93 CRM_Contact_BAO_Group
::discard($params['id']);
94 $params['group_id'] = $params['id'];
104 static function updateCiviACLTables($aclParams, $op) {
105 if ($op == 'delete') {
106 self
::updateCiviACL($aclParams, $op);
107 self
::updateCiviACLEntityRole($aclParams, $op);
108 self
::updateCiviACLRole($aclParams, $op);
111 self
::updateCiviACLRole($aclParams, $op);
112 self
::updateCiviACLEntityRole($aclParams, $op);
113 self
::updateCiviACL($aclParams, $op);
121 static function updateCiviACLRole(&$params, $op) {
123 $optionGroupID = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionGroup',
129 $dao = new CRM_Core_DAO_OptionValue();
130 $dao->option_group_id
= $optionGroupID;
131 $dao->description
= $params['source'];
133 if ($op == 'delete') {
138 $dao->label
= $params['title'];
141 $weightParams = array('option_group_id' => $optionGroupID);
142 $dao->weight
= CRM_Utils_Weight
::getDefaultWeight('CRM_Core_DAO_OptionValue',
145 $dao->value
= CRM_Utils_Weight
::getDefaultWeight('CRM_Core_DAO_OptionValue',
152 FROM civicrm_option_value v
153 WHERE v.option_group_id = %1
154 AND v.description = %2
156 $queryParams = array(1 => array($optionGroupID, 'Integer'),
157 2 => array($params['source'], 'String'),
159 $dao->id
= CRM_Core_DAO
::singleValueQuery($query, $queryParams);
161 $params['acl_role_id'] = $dao->value
;
168 static function updateCiviACLEntityRole(&$params, $op) {
169 $dao = new CRM_ACL_DAO_EntityRole();
171 $dao->entity_table
= 'civicrm_group';
172 $dao->entity_id
= $params['acl_group_id'];
173 if ($op == 'delete') {
178 $dao->acl_role_id
= $params['acl_role_id'];
181 $dao->is_active
= TRUE;
183 $params['acl_entity_role_id'] = $dao->id
;
190 static function updateCiviACL(&$params, $op) {
191 $dao = new CRM_ACL_DAO_ACL();
193 $dao->object_table
= 'civicrm_saved_search';
194 $dao->object_id
= $params['civicrm_group_id'];
196 if ($op == 'delete') {
203 $dao->entity_table
= 'civicrm_acl_role';
204 $dao->entity_id
= $params['acl_role_id'];
205 $dao->operation
= 'Edit';
207 $dao->is_active
= TRUE;
209 $params['acl_id'] = $dao->id
;
218 static function og(&$params, $op) {
220 $contactID = CRM_Bridge_OG_Utils
::contactID($params['uf_id']);
222 CRM_Core_Error
::fatal();
225 // get the group id of this OG
226 $groupID = CRM_Bridge_OG_Utils
::groupID(CRM_Bridge_OG_Utils
::ogSyncName($params['og_id']),
230 $groupParams = array(
231 'contact_id' => $contactID,
232 'group_id' => $groupID,
237 $groupParams['status'] = $params['is_active'] ?
'Added' : 'Pending';
238 civicrm_api('GroupContact', 'Create', $groupParams);
241 $groupParams['status'] = 'Removed';
242 civicrm_api('GroupContact', 'Delete', $groupParams);
245 if (CRM_Bridge_OG_Utils
::aclEnabled() &&
246 $params['is_admin'] !== NULL
248 // get the group ID of the acl group
249 $groupID = CRM_Bridge_OG_Utils
::groupID(CRM_Bridge_OG_Utils
::ogSyncACLName($params['og_id']),
253 $groupParams = array(
254 'contact_id' => $contactID,
255 'group_id' => $groupID,
256 'status' => $params['is_admin'] ?
'Added' : 'Removed',
260 if ($params['is_admin']) {
261 civicrm_api('GroupContact', 'Create', $groupParams);
264 civicrm_api('GroupContact', 'Delete', $groupParams);