3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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
39 class CRM_Bridge_OG_Drupal
{
42 * @param array $params
45 public static function nodeapi(&$params, $op) {
47 $transaction = new CRM_Core_Transaction();
49 // first create or update the CiviCRM group
50 $groupParams = $params;
51 $groupParams['source'] = CRM_Bridge_OG_Utils
::ogSyncName($params['og_id']);
52 $groupParams['group_type'] = array('2' => 1);
53 self
::updateCiviGroup($groupParams, $op);
55 if (CRM_Bridge_OG_Utils
::aclEnabled()) {
56 // next create or update the CiviCRM ACL group
58 $aclParams['name'] = $aclParams['title'] = "{$aclParams['name']}: Administrator";
59 $aclParams['source'] = CRM_Bridge_OG_Utils
::ogSyncACLName($params['og_id']);
60 $aclParams['group_type'] = array('1');
61 self
::updateCiviGroup($aclParams, $op);
63 $aclParams['acl_group_id'] = $aclParams['group_id'];
64 $aclParams['civicrm_group_id'] = $groupParams['group_id'];
66 self
::updateCiviACLTables($aclParams, $op);
69 $transaction->commit();
73 * @param array $params
75 * @param null $groupType
77 public static function updateCiviGroup(&$params, $op, $groupType = NULL) {
79 $params['version'] = 3;
80 $params['id'] = CRM_Bridge_OG_Utils
::groupID($params['source'], $params['title'], $abort);
84 $params['group_type'] = $groupType;
87 $group = civicrm_api('group', 'create', $params);
88 if (!civicrm_error($group)) {
89 $params['group_id'] = $group['id'];
93 // do this only if we have a valid id
95 CRM_Contact_BAO_Group
::discard($params['id']);
96 $params['group_id'] = $params['id'];
103 * @param array $aclParams
106 public static function updateCiviACLTables($aclParams, $op) {
107 if ($op == 'delete') {
108 self
::updateCiviACL($aclParams, $op);
109 self
::updateCiviACLEntityRole($aclParams, $op);
110 self
::updateCiviACLRole($aclParams, $op);
113 self
::updateCiviACLRole($aclParams, $op);
114 self
::updateCiviACLEntityRole($aclParams, $op);
115 self
::updateCiviACL($aclParams, $op);
120 * @param array $params
123 public static function updateCiviACLRole(&$params, $op) {
125 $optionGroupID = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionGroup',
131 $dao = new CRM_Core_DAO_OptionValue();
132 $dao->option_group_id
= $optionGroupID;
133 $dao->description
= $params['source'];
135 if ($op == 'delete') {
140 $dao->label
= $params['title'];
143 $weightParams = array('option_group_id' => $optionGroupID);
144 $dao->weight
= CRM_Utils_Weight
::getDefaultWeight('CRM_Core_DAO_OptionValue',
147 $dao->value
= CRM_Utils_Weight
::getDefaultWeight('CRM_Core_DAO_OptionValue',
154 FROM civicrm_option_value v
155 WHERE v.option_group_id = %1
156 AND v.description = %2
158 $queryParams = array(
159 1 => array($optionGroupID, 'Integer'),
160 2 => array($params['source'], 'String'),
162 $dao->id
= CRM_Core_DAO
::singleValueQuery($query, $queryParams);
164 $params['acl_role_id'] = $dao->value
;
168 * @param array $params
171 public static function updateCiviACLEntityRole(&$params, $op) {
172 $dao = new CRM_ACL_DAO_EntityRole();
174 $dao->entity_table
= 'civicrm_group';
175 $dao->entity_id
= $params['acl_group_id'];
176 if ($op == 'delete') {
181 $dao->acl_role_id
= $params['acl_role_id'];
184 $dao->is_active
= TRUE;
186 $params['acl_entity_role_id'] = $dao->id
;
190 * @param array $params
193 public static function updateCiviACL(&$params, $op) {
194 $dao = new CRM_ACL_DAO_ACL();
196 $dao->object_table
= 'civicrm_saved_search';
197 $dao->object_id
= $params['civicrm_group_id'];
199 if ($op == 'delete') {
206 $dao->entity_table
= 'civicrm_acl_role';
207 $dao->entity_id
= $params['acl_role_id'];
208 $dao->operation
= 'Edit';
210 $dao->is_active
= TRUE;
212 $params['acl_id'] = $dao->id
;
216 * @param array $params
221 public static function og(&$params, $op) {
223 $contactID = CRM_Bridge_OG_Utils
::contactID($params['uf_id']);
225 CRM_Core_Error
::fatal();
228 // get the group id of this OG
229 $groupID = CRM_Bridge_OG_Utils
::groupID(CRM_Bridge_OG_Utils
::ogSyncName($params['og_id']),
233 $groupParams = array(
234 'contact_id' => $contactID,
235 'group_id' => $groupID,
240 $groupParams['status'] = $params['is_active'] ?
'Added' : 'Pending';
241 civicrm_api('GroupContact', 'Create', $groupParams);
244 $groupParams['status'] = 'Removed';
245 civicrm_api('GroupContact', 'Delete', $groupParams);
248 if (CRM_Bridge_OG_Utils
::aclEnabled() &&
249 $params['is_admin'] !== NULL
251 // get the group ID of the acl group
252 $groupID = CRM_Bridge_OG_Utils
::groupID(CRM_Bridge_OG_Utils
::ogSyncACLName($params['og_id']),
256 $groupParams = array(
257 'contact_id' => $contactID,
258 'group_id' => $groupID,
259 'status' => $params['is_admin'] ?
'Added' : 'Removed',
263 if ($params['is_admin']) {
264 civicrm_api('GroupContact', 'Create', $groupParams);
267 civicrm_api('GroupContact', 'Delete', $groupParams);