-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added civirules action for adding and removing contacts from a protec…
…ted group.
- Loading branch information
1 parent
b3a70c7
commit c02caaa
Showing
6 changed files
with
149 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
), | ||
), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters