3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
21 class CRM_Bridge_OG_Drupal
{
24 * @param array $params
27 public static function nodeapi(&$params, $op) {
29 $transaction = new CRM_Core_Transaction();
31 // first create or update the CiviCRM group
32 $groupParams = $params;
33 $groupParams['source'] = CRM_Bridge_OG_Utils
::ogSyncName($params['og_id']);
34 $groupParams['group_type'] = ['2' => 1];
35 self
::updateCiviGroup($groupParams, $op);
37 if (CRM_Bridge_OG_Utils
::aclEnabled()) {
38 // next create or update the CiviCRM ACL group
40 $aclParams['name'] = $aclParams['title'] = "{$aclParams['name']}: Administrator";
41 $aclParams['source'] = CRM_Bridge_OG_Utils
::ogSyncACLName($params['og_id']);
42 $aclParams['group_type'] = ['1'];
43 self
::updateCiviGroup($aclParams, $op);
45 $aclParams['acl_group_id'] = $aclParams['group_id'];
46 $aclParams['civicrm_group_id'] = $groupParams['group_id'];
48 self
::updateCiviACLTables($aclParams, $op);
51 $transaction->commit();
55 * @param array $params
57 * @param null $groupType
59 public static function updateCiviGroup(&$params, $op, $groupType = NULL) {
61 $params['version'] = 3;
62 $params['id'] = CRM_Bridge_OG_Utils
::groupID($params['source'], $params['title'], $abort);
66 $params['group_type'] = $groupType;
69 $group = civicrm_api('group', 'create', $params);
70 if (!civicrm_error($group)) {
71 $params['group_id'] = $group['id'];
75 // do this only if we have a valid id
77 CRM_Contact_BAO_Group
::discard($params['id']);
78 $params['group_id'] = $params['id'];
85 * @param array $aclParams
88 public static function updateCiviACLTables($aclParams, $op) {
89 if ($op == 'delete') {
90 self
::updateCiviACL($aclParams, $op);
91 self
::updateCiviACLEntityRole($aclParams, $op);
92 self
::updateCiviACLRole($aclParams, $op);
95 self
::updateCiviACLRole($aclParams, $op);
96 self
::updateCiviACLEntityRole($aclParams, $op);
97 self
::updateCiviACL($aclParams, $op);
102 * @param array $params
105 public static function updateCiviACLRole(&$params, $op) {
107 $optionGroupID = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionGroup',
113 $dao = new CRM_Core_DAO_OptionValue();
114 $dao->option_group_id
= $optionGroupID;
115 $dao->description
= $params['source'];
117 if ($op == 'delete') {
122 $dao->label
= $params['title'];
125 $weightParams = ['option_group_id' => $optionGroupID];
126 $dao->weight
= CRM_Utils_Weight
::getDefaultWeight('CRM_Core_DAO_OptionValue',
129 $dao->value
= CRM_Utils_Weight
::getDefaultWeight('CRM_Core_DAO_OptionValue',
136 FROM civicrm_option_value v
137 WHERE v.option_group_id = %1
138 AND v.description = %2
141 1 => [$optionGroupID, 'Integer'],
142 2 => [$params['source'], 'String'],
144 $dao->id
= CRM_Core_DAO
::singleValueQuery($query, $queryParams);
146 $params['acl_role_id'] = $dao->value
;
150 * @param array $params
153 public static function updateCiviACLEntityRole(&$params, $op) {
154 $dao = new CRM_ACL_DAO_EntityRole();
156 $dao->entity_table
= 'civicrm_group';
157 $dao->entity_id
= $params['acl_group_id'];
158 if ($op == 'delete') {
163 $dao->acl_role_id
= $params['acl_role_id'];
166 $dao->is_active
= TRUE;
168 $params['acl_entity_role_id'] = $dao->id
;
172 * @param array $params
175 public static function updateCiviACL(&$params, $op) {
176 $dao = new CRM_ACL_DAO_ACL();
178 $dao->object_table
= 'civicrm_saved_search';
179 $dao->object_id
= $params['civicrm_group_id'];
181 if ($op == 'delete') {
188 $dao->entity_table
= 'civicrm_acl_role';
189 $dao->entity_id
= $params['acl_role_id'];
190 $dao->operation
= 'Edit';
192 $dao->is_active
= TRUE;
194 $params['acl_id'] = $dao->id
;
198 * @param array $params
203 public static function og(&$params, $op) {
205 $contactID = CRM_Bridge_OG_Utils
::contactID($params['uf_id']);
207 CRM_Core_Error
::fatal();
210 // get the group id of this OG
211 $groupID = CRM_Bridge_OG_Utils
::groupID(CRM_Bridge_OG_Utils
::ogSyncName($params['og_id']),
216 'contact_id' => $contactID,
217 'group_id' => $groupID,
222 $groupParams['status'] = $params['is_active'] ?
'Added' : 'Pending';
223 civicrm_api('GroupContact', 'Create', $groupParams);
226 $groupParams['status'] = 'Removed';
227 civicrm_api('GroupContact', 'Delete', $groupParams);
230 if (CRM_Bridge_OG_Utils
::aclEnabled() &&
231 $params['is_admin'] !== NULL
233 // get the group ID of the acl group
234 $groupID = CRM_Bridge_OG_Utils
::groupID(CRM_Bridge_OG_Utils
::ogSyncACLName($params['og_id']),
239 'contact_id' => $contactID,
240 'group_id' => $groupID,
241 'status' => $params['is_admin'] ?
'Added' : 'Removed',
245 if ($params['is_admin']) {
246 civicrm_api('GroupContact', 'Create', $groupParams);
249 civicrm_api('GroupContact', 'Delete', $groupParams);