Skip to content
Snippets Groups Projects
Commit b0f0d1eb authored by Erik Hommel's avatar Erik Hommel
Browse files

cleanup Engine and EditEntity

parent af4383db
Branches
Tags
No related merge requests found
<?php
/**
* Class for CiviRules engine
*
* @author Jaap Jansma (CiviCooP) <jaap.jansma@civicoop.org>
* @license AGPL-3.0
*/
class CRM_Civirules_Engine {
......@@ -7,9 +13,11 @@ class CRM_Civirules_Engine {
*
* The trigger will check the conditions and if conditions are valid then the actions are executed
*
* @param CRM_Civirules_EventData_EventData $eventData
* @param $ruleId
* @param $eventId
* @param object CRM_Civirules_EventData_EventData $eventData
* @param int $ruleId
* @param int $eventId
* @access public
* @static
*/
public static function triggerRule(CRM_Civirules_EventData_EventData $eventData, $ruleId, $eventId) {
$eventData->setEventId($eventId);
......@@ -22,6 +30,14 @@ class CRM_Civirules_Engine {
}
}
/**
* Method to execute the actions
*
* @param object CRM_Civirules_EventData_EventData $eventData
* @param int $ruleId
* @access protected
* @static
*/
protected static function executeActions(CRM_Civirules_EventData_EventData $eventData, $ruleId) {
$actionParams = array(
'rule_id' => $ruleId
......@@ -32,6 +48,14 @@ class CRM_Civirules_Engine {
}
}
/**
* Method to execute a single action
*
* @param object CRM_Civirules_EventData_EventData $eventData
* @param array $ruleAction
* @access protected
* @static
*/
protected static function executeAction(CRM_Civirules_EventData_EventData $eventData, $ruleAction) {
$object = CRM_Civirules_BAO_Action::getActionObjectById($ruleAction['action_id'], true);
if (!$object) {
......@@ -42,6 +66,15 @@ class CRM_Civirules_Engine {
$object->processAction($eventData);
}
/**
* Method to check if all conditions are valid
*
* @param object CRM_Civirules_EventData_EventData $eventData
* @param int $ruleId
* @return bool
* @access protected
* @static
*/
protected static function areConditionsValid(CRM_Civirules_EventData_EventData $eventData, $ruleId) {
$isValid = true;
$firstCondition = true;
......@@ -74,6 +107,15 @@ class CRM_Civirules_Engine {
return $isValid;
}
/**
* Method to check condition
*
* @param array $ruleCondition
* @param object CRM_Civirules_EventData_EventData $eventData
* @return bool
* @access protected
* @static
*/
protected static function checkCondition($ruleCondition, CRM_Civirules_EventData_EventData $eventData) {
$condition = CRM_Civirules_BAO_Condition::getConditionObjectById($ruleCondition['condition_id'], false);
if (!$condition) {
......
<?php
/**
* The post event handler
* Class for CiviRules post event handling
*
* @author Jaap Jansma (CiviCooP) <jaap.jansma@civicoop.org>
* @license AGPL-3.0
*/
class CRM_Civirules_Event_EditEntity {
/**
* Data set in pre and used for compare which field is changed
*
* @var array
* @var array $preData
*/
protected static $preData = array();
/**
* Method pre to store the entity data before the data in the database is changed
* for the edit operation
*
* @param string $op
* @param string $objectName
* @param int $objectId
* @param array $params
* @access public
* @static
*
*/
public static function pre($op, $objectName, $objectId, $params) {
if ($op != 'edit') {
return;
......@@ -24,6 +38,16 @@ class CRM_Civirules_Event_EditEntity {
self::setPreData($entity, $objectId, $data);
}
/**
* Method post
*
* @param string $op
* @param string $objectName
* @param int $objectId
* @param object $objectRef
* @access public
* @static
*/
public static function post( $op, $objectName, $objectId, &$objectRef ) {
$extensionConfig = CRM_Civirules_Config::singleton();
if (!in_array($op,$extensionConfig->getValidEventOperations())) {
......@@ -55,17 +79,43 @@ class CRM_Civirules_Event_EditEntity {
}
}
protected static function setPreData($entity, $entity_id, $data) {
self::$preData[$entity][$entity_id] = $data;
/**
* Method to set the pre operation data
*
* @param string $entity
* @param int $entityId
* @param array $data
* @access protected
* @static
*/
protected static function setPreData($entity, $entityId, $data) {
self::$preData[$entity][$entityId] = $data;
}
protected static function getPreData($entity, $entity_id) {
if (isset(self::$preData[$entity][$entity_id])) {
return self::$preData[$entity][$entity_id];
/**
* Method to get the pre operation data
*
* @param string $entity
* @param id $entityId
* @return array
* @access protected
* @static
*/
protected static function getPreData($entity, $entityId) {
if (isset(self::$preData[$entity][$entityId])) {
return self::$preData[$entity][$entityId];
}
return array();
}
/**
* Method to convert the object name to the entity for contacts
*
* @param string $objectName
* @return string $entity
* @access public
* @static
*/
public static function convertObjectNameToEntity($objectName) {
$entity = $objectName;
switch($objectName) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment