Skip to content
Snippets Groups Projects
Commit 0ab60b3f authored by jaapjansma's avatar jaapjansma
Browse files

Fixed #89 possibly to check whether a condition or action is valid in a...

Fixed #89 possibly to check whether a condition or action is valid in a certain rule setup or with a certain trigger
parent 2db55b3b
No related branches found
No related tags found
No related merge requests found
......@@ -107,6 +107,20 @@ abstract class CRM_Civirules_Action {
return '';
}
/**
* This function validates whether this action works with the selected trigger.
*
* This function could be overriden in child classes to provide additional validation
* whether an action is possible in the current setup.
*
* @param CRM_Civirules_Trigger $trigger
* @param CRM_Civirules_BAO_Rule $rule
* @return bool
*/
public function doesWorkWithTrigger(CRM_Civirules_Trigger $trigger, CRM_Civirules_BAO_Rule $rule) {
return true;
}
/**
* Logs a message to the logger
*
......
......@@ -66,6 +66,22 @@ abstract class CRM_Civirules_Condition {
return array();
}
/**
* This function validates whether this condition works with the selected trigger.
*
* This function could be overriden in child classes to provide additional validation
* whether a condition is possible in the current setup. E.g. we could have a condition
* which works on contribution or on contributionRecur then this function could do
* this kind of validation and return false/true
*
* @param CRM_Civirules_Trigger $trigger
* @param CRM_Civirules_BAO_Rule $rule
* @return bool
*/
public function doesWorkWithTrigger(CRM_Civirules_Trigger $trigger, CRM_Civirules_BAO_Rule $rule) {
return true;
}
/**
* Logs a message to the logger
*
......
......@@ -207,6 +207,24 @@ class CRM_Civirules_Form_RuleAction extends CRM_Core_Form {
$errors = array();
if (isset($fields['rule_action_select']) && empty($fields['rule_action_select'])) {
$errors['rule_action_select'] = ts('Action has to be selected, press CANCEL if you do not want to add an action');
} else {
$actionClass = CRM_Civirules_BAO_Action::getActionObjectById($fields['rule_action_select'], false);
if (!$actionClass) {
$errors['rule_action_select'] = ts('Not a valid action, action class is missing');
} else {
$rule = new CRM_Civirules_BAO_Rule();
$rule->id = $fields['rule_id'];
$rule->find(TRUE);
$trigger = new CRM_Civirules_BAO_Trigger();
$trigger->id = $rule->trigger_id;
$trigger->find(TRUE);
$triggerObject = CRM_Civirules_BAO_Trigger::getPostTriggerObjectByClassName($trigger->class_name, TRUE);
$triggerObject->setTriggerId($trigger->id);
if (!$actionClass->doesWorkWithTrigger($triggerObject, $rule)) {
$errors['rule_action_select'] = ts('This action is not available with trigger %1', array(1 => $trigger->label));
}
}
}
if (!empty($fields['delay_select'])) {
$delayClass = CRM_Civirules_Delay_Factory::getDelayClassByName($fields['delay_select']);
......
......@@ -152,6 +152,13 @@ class CRM_Civirules_Form_RuleCondition extends CRM_Core_Form {
return $errors;
}
}
if (!$conditionClass->doesWorkWithTrigger($triggerObject, $rule)) {
$errors['rule_condition_select'] = ts('This condition is not available with trigger %1', array(1 => $trigger->label));
return $errors;
}
return true;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment