Skip to content
Snippets Groups Projects
Commit 8e78e695 authored by jaapjansma's avatar jaapjansma
Browse files

created a more generic action base class and a generic api action class

parent 10a0af2a
No related branches found
No related tags found
No related merge requests found
......@@ -13,20 +13,12 @@ abstract class CRM_Civirules_Action {
protected $action = array();
/**
* Method to get the api entity to process in this CiviRule action
*
* @access protected
* @abstract
*/
protected abstract function getApiEntity();
/**
* Method to get the api action to process in this CiviRule action
* Process the action
*
* @access protected
* @abstract
* @param CRM_Civirules_EventData_EventData $eventData
* @access public
*/
protected abstract function getApiAction();
abstract public function processAction(CRM_Civirules_EventData_EventData $eventData);
/**
* Method to set RuleActionData
......@@ -51,52 +43,6 @@ abstract class CRM_Civirules_Action {
$this->action = $action;
}
/**
* Returns an array with parameters used for processing an action
*
* @param array $parameters
* @param CRM_Civirules_EventData_EventData $eventData
* @return array
* @access protected
*/
protected function alterApiParameters($parameters, CRM_Civirules_EventData_EventData $eventData) {
//this method could be overridden in subclasses to alter parameters to meet certain criteria
return $parameters;
}
/**
* Process the action
*
* @param CRM_Civirules_EventData_EventData $eventData
* @access public
*/
public function processAction(CRM_Civirules_EventData_EventData $eventData) {
$entity = $this->getApiEntity();
$action = $this->getApiAction();
$params = $this->getActionParameters();
//alter parameters by subclass
$params = $this->alterApiParameters($params, $eventData);
//execute the action
$this->executeApiAction($entity, $action, $params);
}
/**
* Executes the action
*
* This method could be overridden if needed
*
* @param $entity
* @param $action
* @param $parameters
* @access protected
*/
protected function executeApiAction($entity, $action, $parameters) {
civicrm_api3($entity, $action, $parameters);
}
/**
* Convert parameters to an array of parameters
*
......
<?php
abstract class CRM_CivirulesActions_Generic_Api extends CRM_Civirules_Action {
/**
* Method to get the api entity to process in this CiviRule action
*
* @access protected
* @abstract
*/
protected abstract function getApiEntity();
/**
* Method to get the api action to process in this CiviRule action
*
* @access protected
* @abstract
*/
protected abstract function getApiAction();
/**
* Returns an array with parameters used for processing an action
*
* @param array $parameters
* @param CRM_Civirules_EventData_EventData $eventData
* @return array
* @access protected
*/
protected function alterApiParameters($parameters, CRM_Civirules_EventData_EventData $eventData) {
//this method could be overridden in subclasses to alter parameters to meet certain criteria
return $parameters;
}
/**
* Process the action
*
* @param CRM_Civirules_EventData_EventData $eventData
* @access public
*/
public function processAction(CRM_Civirules_EventData_EventData $eventData) {
$entity = $this->getApiEntity();
$action = $this->getApiAction();
$params = $this->getActionParameters();
//alter parameters by subclass
$params = $this->alterApiParameters($params, $eventData);
//execute the action
$this->executeApiAction($entity, $action, $params);
}
/**
* Executes the action
*
* This method could be overridden if needed
*
* @param $entity
* @param $action
* @param $parameters
* @access protected
*/
protected function executeApiAction($entity, $action, $parameters) {
civicrm_api3($entity, $action, $parameters);
}
}
\ No newline at end of file
......@@ -6,7 +6,7 @@
* @license AGPL-3.0
*/
class CRM_CivirulesActions_GroupContact extends CRM_Civirules_Action {
class CRM_CivirulesActions_GroupContact extends CRM_CivirulesActions_Generic_Api {
/**
* Returns an array with parameters used for processing an action
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment