3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
37 class CRM_Bridge_OG_Drupal
{
40 * @param array $params
43 public 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();
71 * @param array $params
73 * @param null $groupType
75 public 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'];
101 * @param array $aclParams
104 public 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);
118 * @param array $params
121 public 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(
157 1 => array($optionGroupID, 'Integer'),
158 2 => array($params['source'], 'String'),
160 $dao->id
= CRM_Core_DAO
::singleValueQuery($query, $queryParams);
162 $params['acl_role_id'] = $dao->value
;
166 * @param array $params
169 public static function updateCiviACLEntityRole(&$params, $op) {
170 $dao = new CRM_ACL_DAO_EntityRole();
172 $dao->entity_table
= 'civicrm_group';
173 $dao->entity_id
= $params['acl_group_id'];
174 if ($op == 'delete') {
179 $dao->acl_role_id
= $params['acl_role_id'];
182 $dao->is_active
= TRUE;
184 $params['acl_entity_role_id'] = $dao->id
;
188 * @param array $params
191 public static function updateCiviACL(&$params, $op) {
192 $dao = new CRM_ACL_DAO_ACL();
194 $dao->object_table
= 'civicrm_saved_search';
195 $dao->object_id
= $params['civicrm_group_id'];
197 if ($op == 'delete') {
204 $dao->entity_table
= 'civicrm_acl_role';
205 $dao->entity_id
= $params['acl_role_id'];
206 $dao->operation
= 'Edit';
208 $dao->is_active
= TRUE;
210 $params['acl_id'] = $dao->id
;
214 * @param array $params
219 public static function og(&$params, $op) {
221 $contactID = CRM_Bridge_OG_Utils
::contactID($params['uf_id']);
223 CRM_Core_Error
::fatal();
226 // get the group id of this OG
227 $groupID = CRM_Bridge_OG_Utils
::groupID(CRM_Bridge_OG_Utils
::ogSyncName($params['og_id']),
231 $groupParams = array(
232 'contact_id' => $contactID,
233 'group_id' => $groupID,
238 $groupParams['status'] = $params['is_active'] ?
'Added' : 'Pending';
239 civicrm_api('GroupContact', 'Create', $groupParams);
242 $groupParams['status'] = 'Removed';
243 civicrm_api('GroupContact', 'Delete', $groupParams);
246 if (CRM_Bridge_OG_Utils
::aclEnabled() &&
247 $params['is_admin'] !== NULL
249 // get the group ID of the acl group
250 $groupID = CRM_Bridge_OG_Utils
::groupID(CRM_Bridge_OG_Utils
::ogSyncACLName($params['og_id']),
254 $groupParams = array(
255 'contact_id' => $contactID,
256 'group_id' => $groupID,
257 'status' => $params['is_admin'] ?
'Added' : 'Removed',
261 if ($params['is_admin']) {
262 civicrm_api('GroupContact', 'Create', $groupParams);
265 civicrm_api('GroupContact', 'Delete', $groupParams);