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

cleanup Engine and EditEntity

parent af4383db
No related branches found
No related tags found
No related merge requests found
<?php <?php
/**
* Class for CiviRules engine
*
* @author Jaap Jansma (CiviCooP) <jaap.jansma@civicoop.org>
* @license AGPL-3.0
*/
class CRM_Civirules_Engine { class CRM_Civirules_Engine {
...@@ -7,9 +13,11 @@ 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 * The trigger will check the conditions and if conditions are valid then the actions are executed
* *
* @param CRM_Civirules_EventData_EventData $eventData * @param object CRM_Civirules_EventData_EventData $eventData
* @param $ruleId * @param int $ruleId
* @param $eventId * @param int $eventId
* @access public
* @static
*/ */
public static function triggerRule(CRM_Civirules_EventData_EventData $eventData, $ruleId, $eventId) { public static function triggerRule(CRM_Civirules_EventData_EventData $eventData, $ruleId, $eventId) {
$eventData->setEventId($eventId); $eventData->setEventId($eventId);
...@@ -22,6 +30,14 @@ class CRM_Civirules_Engine { ...@@ -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) { protected static function executeActions(CRM_Civirules_EventData_EventData $eventData, $ruleId) {
$actionParams = array( $actionParams = array(
'rule_id' => $ruleId 'rule_id' => $ruleId
...@@ -32,6 +48,14 @@ class CRM_Civirules_Engine { ...@@ -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) { protected static function executeAction(CRM_Civirules_EventData_EventData $eventData, $ruleAction) {
$object = CRM_Civirules_BAO_Action::getActionObjectById($ruleAction['action_id'], true); $object = CRM_Civirules_BAO_Action::getActionObjectById($ruleAction['action_id'], true);
if (!$object) { if (!$object) {
...@@ -42,6 +66,15 @@ class CRM_Civirules_Engine { ...@@ -42,6 +66,15 @@ class CRM_Civirules_Engine {
$object->processAction($eventData); $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) { protected static function areConditionsValid(CRM_Civirules_EventData_EventData $eventData, $ruleId) {
$isValid = true; $isValid = true;
$firstCondition = true; $firstCondition = true;
...@@ -74,6 +107,15 @@ class CRM_Civirules_Engine { ...@@ -74,6 +107,15 @@ class CRM_Civirules_Engine {
return $isValid; 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) { protected static function checkCondition($ruleCondition, CRM_Civirules_EventData_EventData $eventData) {
$condition = CRM_Civirules_BAO_Condition::getConditionObjectById($ruleCondition['condition_id'], false); $condition = CRM_Civirules_BAO_Condition::getConditionObjectById($ruleCondition['condition_id'], false);
if (!$condition) { if (!$condition) {
......
<?php <?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 { class CRM_Civirules_Event_EditEntity {
/** /**
* Data set in pre and used for compare which field is changed * Data set in pre and used for compare which field is changed
* *
* @var array * @var array $preData
*/ */
protected static $preData = array(); 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) { public static function pre($op, $objectName, $objectId, $params) {
if ($op != 'edit') { if ($op != 'edit') {
return; return;
...@@ -24,6 +38,16 @@ class CRM_Civirules_Event_EditEntity { ...@@ -24,6 +38,16 @@ class CRM_Civirules_Event_EditEntity {
self::setPreData($entity, $objectId, $data); 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 ) { public static function post( $op, $objectName, $objectId, &$objectRef ) {
$extensionConfig = CRM_Civirules_Config::singleton(); $extensionConfig = CRM_Civirules_Config::singleton();
if (!in_array($op,$extensionConfig->getValidEventOperations())) { if (!in_array($op,$extensionConfig->getValidEventOperations())) {
...@@ -55,17 +79,43 @@ class CRM_Civirules_Event_EditEntity { ...@@ -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])) { * Method to get the pre operation data
return self::$preData[$entity][$entity_id]; *
* @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(); 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) { public static function convertObjectNameToEntity($objectName) {
$entity = $objectName; $entity = $objectName;
switch($objectName) { switch($objectName) {
......
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