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
{
39 static function nodeapi(&$params, $op) {
41 $transaction = new CRM_Core_Transaction();
43 // first create or update the CiviCRM group
44 $groupParams = $params;
45 $groupParams['source'] = CRM_Bridge_OG_Utils
::ogSyncName($params['og_id']);
46 $groupParams['group_type'] = array('2' => 1);
47 self
::updateCiviGroup($groupParams, $op);
49 if (CRM_Bridge_OG_Utils
::aclEnabled()) {
50 // next create or update the CiviCRM ACL group
52 $aclParams['name'] = $aclParams['title'] = "{$aclParams['name']}: Administrator";
53 $aclParams['source'] = CRM_Bridge_OG_Utils
::ogSyncACLName($params['og_id']);
54 $aclParams['group_type'] = array('1');
55 self
::updateCiviGroup($aclParams, $op);
57 $aclParams['acl_group_id'] = $aclParams['group_id'];
58 $aclParams['civicrm_group_id'] = $groupParams['group_id'];
60 self
::updateCiviACLTables($aclParams, $op);
63 $transaction->commit();
66 static function updateCiviGroup(&$params, $op, $groupType = NULL) {
68 $params['version'] = 3;
69 $params['id'] = CRM_Bridge_OG_Utils
::groupID($params['source'], $params['title'], $abort);
73 $params['group_type'] = $groupType;
76 $group = civicrm_api('group', 'create', $params);
77 if (!civicrm_error($group)) {
78 $params['group_id'] = $group['id'];
82 // do this only if we have a valid id
84 CRM_Contact_BAO_Group
::discard($params['id']);
85 $params['group_id'] = $params['id'];
91 static function updateCiviACLTables($aclParams, $op) {
92 if ($op == 'delete') {
93 self
::updateCiviACL($aclParams, $op);
94 self
::updateCiviACLEntityRole($aclParams, $op);
95 self
::updateCiviACLRole($aclParams, $op);
98 self
::updateCiviACLRole($aclParams, $op);
99 self
::updateCiviACLEntityRole($aclParams, $op);
100 self
::updateCiviACL($aclParams, $op);
104 static function updateCiviACLRole(&$params, $op) {
106 $optionGroupID = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionGroup',
112 $dao = new CRM_Core_DAO_OptionValue();
113 $dao->option_group_id
= $optionGroupID;
114 $dao->description
= $params['source'];
116 if ($op == 'delete') {
121 $dao->label
= $params['title'];
124 $weightParams = array('option_group_id' => $optionGroupID);
125 $dao->weight
= CRM_Utils_Weight
::getDefaultWeight('CRM_Core_DAO_OptionValue',
128 $dao->value
= CRM_Utils_Weight
::getDefaultWeight('CRM_Core_DAO_OptionValue',
135 FROM civicrm_option_value v
136 WHERE v.option_group_id = %1
137 AND v.description = %2
139 $queryParams = array(1 => array($optionGroupID, 'Integer'),
140 2 => array($params['source'], 'String'),
142 $dao->id
= CRM_Core_DAO
::singleValueQuery($query, $queryParams);
144 $params['acl_role_id'] = $dao->value
;
147 static function updateCiviACLEntityRole(&$params, $op) {
148 $dao = new CRM_ACL_DAO_EntityRole();
150 $dao->entity_table
= 'civicrm_group';
151 $dao->entity_id
= $params['acl_group_id'];
152 if ($op == 'delete') {
157 $dao->acl_role_id
= $params['acl_role_id'];
160 $dao->is_active
= TRUE;
162 $params['acl_entity_role_id'] = $dao->id
;
165 static function updateCiviACL(&$params, $op) {
166 $dao = new CRM_ACL_DAO_ACL();
168 $dao->object_table
= 'civicrm_saved_search';
169 $dao->object_id
= $params['civicrm_group_id'];
171 if ($op == 'delete') {
178 $dao->entity_table
= 'civicrm_acl_role';
179 $dao->entity_id
= $params['acl_role_id'];
180 $dao->operation
= 'Edit';
182 $dao->is_active
= TRUE;
184 $params['acl_id'] = $dao->id
;
187 static function og(&$params, $op) {
189 $contactID = CRM_Bridge_OG_Utils
::contactID($params['uf_id']);
191 CRM_Core_Error
::fatal();
194 // get the group id of this OG
195 $groupID = CRM_Bridge_OG_Utils
::groupID(CRM_Bridge_OG_Utils
::ogSyncName($params['og_id']),
199 $groupParams = array(
200 'contact_id' => $contactID,
201 'group_id' => $groupID,
206 $groupParams['status'] = $params['is_active'] ?
'Added' : 'Pending';
207 civicrm_api('GroupContact', 'Create', $groupParams);
210 $groupParams['status'] = 'Removed';
211 civicrm_api('GroupContact', 'Delete', $groupParams);
214 if (CRM_Bridge_OG_Utils
::aclEnabled() &&
215 $params['is_admin'] !== NULL
217 // get the group ID of the acl group
218 $groupID = CRM_Bridge_OG_Utils
::groupID(CRM_Bridge_OG_Utils
::ogSyncACLName($params['og_id']),
222 $groupParams = array(
223 'contact_id' => $contactID,
224 'group_id' => $groupID,
225 'status' => $params['is_admin'] ?
'Added' : 'Removed',
229 if ($params['is_admin']) {
230 civicrm_api('GroupContact', 'Create', $groupParams);
233 civicrm_api('GroupContact', 'Delete', $groupParams);