Skip to content

Commit

Permalink
update to 4.6 (without apiWrapper)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikHommel committed Oct 24, 2016
2 parents cd5170f + c02caaa commit 316b7c4
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CRM/Groupprotect/BAO/GroupProtect.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public static function pageRun(&$page) {
}
}


/**
* Method to process civicrm buildForm hook
*
Expand Down Expand Up @@ -148,4 +149,4 @@ public static function groupIsProtected($groupId) {
public static function userProtectPermitted() {
return CRM_Core_Permission::check('manage protected groups');
}
}
}
24 changes: 24 additions & 0 deletions CRM/Groupprotect/CiviRulesActions/Add.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* @author Jaap Jansma (CiviCooP) <jaap.jansma@civicoop.org>
* @license http://www.gnu.org/licenses/agpl-3.0.html
*/

class CRM_Groupprotect_CiviRulesActions_Add extends CRM_CivirulesActions_GroupContact_GroupContact {

/**
* Method to set the api action
*
* @return string
* @access protected
*/
protected function getApiAction() {
return 'create';
}

protected function alterApiParameters($params, CRM_Civirules_TriggerData_TriggerData $triggerData) {
CRM_Groupprotect_BAO_GroupProtect::bypassPermissionCheck();
return parent::alterApiParameters($params, $triggerData);
}

}
56 changes: 56 additions & 0 deletions CRM/Groupprotect/CiviRulesActions/Remove.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

/**
* Class for CiviRules Group Contact remove action.
*
* Adds a user to a group
*
* @author Jaap Jansma (CiviCooP) <jaap.jansma@civicoop.org>
* @license AGPL-3.0
*/

class CRM_Groupprotect_CiviRulesActions_Remove extends CRM_CivirulesActions_GroupContact_GroupContact {

/**
* Method to set the api action
*
* @return string
* @access protected
*/
protected function getApiAction() {
return 'delete';
}

/**
* Process the action
*
* @param CRM_Civirules_TriggerData_TriggerData $triggerData
* @access public
*/
public function processAction(CRM_Civirules_TriggerData_TriggerData $triggerData) {
$entity = $this->getApiEntity();
$action = $this->getApiAction();
$contactId = $triggerData->getContactId();

$action_params = $this->getActionParameters();
$group_ids = array();
if (!empty($action_params['group_id'])) {
$group_ids = array($action_params['group_id']);
} elseif (!empty($action_params['group_ids']) && is_array($action_params['group_ids'])) {
$group_ids = $action_params['group_ids'];
}
foreach($group_ids as $group_id) {
if (CRM_CivirulesConditions_Utils_GroupContact::isContactInGroup($contactId, $group_id)) {
$params = array();
$params['group_id'] = $group_id;

//alter parameters by subclass
$params = $this->alterApiParameters($params, $triggerData);

//execute the action
CRM_Groupprotect_BAO_GroupProtect::bypassPermissionCheck();
$this->executeApiAction($entity, $action, $params);
}
}
}
}
36 changes: 36 additions & 0 deletions CRM/Groupprotect/CiviRulesActions/actions.mgd.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* @author Jaap Jansma (CiviCooP) <jaap.jansma@civicoop.org>
* @license http://www.gnu.org/licenses/agpl-3.0.html
*/

if (_groupprotect_is_civirules_installed()) {
return array (
0 =>
array (
'name' => 'Civirules:Action.AddToProtectedGroup',
'entity' => 'CiviRuleAction',
'params' =>
array (
'version' => 3,
'name' => 'AddToProtectedGroup',
'label' => 'Add to protected group',
'class_name' => 'CRM_Groupprotect_CiviRulesActions_Add',
'is_active' => 1
),
),
1 =>
array (
'name' => 'Civirules:Action.RemoveFromProtectedGroup',
'entity' => 'CiviRuleAction',
'params' =>
array (
'version' => 3,
'name' => 'RemoveFromProtectedGroup',
'label' => 'Remove from protected group',
'class_name' => 'CRM_Groupprotect_CiviRulesActions_Remove',
'is_active' => 1
),
),
);
}
16 changes: 16 additions & 0 deletions groupprotect.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ function groupprotect_civicrm_config(&$config) {
_groupprotect_civix_civicrm_config($config);
}

function _groupprotect_is_civirules_installed() {
$installed = false;
try {
$extensions = civicrm_api3('Extension', 'get');
foreach($extensions['values'] as $ext) {
if ($ext['key'] == 'org.civicoop.civirules' && $ext['status'] == 'installed') {
$installed = true;
}
}
return $installed;
} catch (Exception $e) {
return false;
}
return false;
}

/**
* Implements hook_civicrm_xmlMenu().
*
Expand Down
5 changes: 5 additions & 0 deletions info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@
<url desc="Support">http://www.civicoop.org</url>
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<<<<<<< HEAD
<releaseDate>2016-01-12</releaseDate>
<version>2.0</version>
=======
<releaseDate>2016-10-19</releaseDate>
<version>1.2</version>
>>>>>>> c02caaaa8511581cf03c63e5dd25035805d62cb8
<develStage>beta</develStage>
<compatibility>
<ver>4.6</ver>
Expand Down

0 comments on commit 316b7c4

Please sign in to comment.