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

added condition activity_type and resolved merge conflicts

parents 429122b5 7e97f5f8
No related branches found
No related tags found
No related merge requests found
Showing
with 686 additions and 108 deletions
......@@ -136,27 +136,42 @@ class CRM_Civirules_BAO_Event extends CRM_Civirules_DAO_Event {
}
/**
* Get the cron event class for this event
* Get the event class based on class name or on objectName
*
* @param $className
* @param bool $abort
* @return CRM_Civirules_Event
* @throws Exception if abort is set to true and class does not exist or is not valid
*/
public static function getPostEventObjectByClassName($className, $abort=true) {
if (empty($className)) {
$className = 'CRM_Civirules_Event_Post';
}
return self::getEventObjectByClassName($className, $abort);
}
/**
* Get the event class for this event
*
* @param $className
* @param bool $abort if true this function will throw an exception if class could not be instanciated
* @return CRM_Civirules_Event_Cron
* @return CRM_Civirules_Event
* @throws Exception if abort is set to true and class does not exist or is not valid
*/
public static function getCronEventObjectByClassName($className, $abort=true)
public static function getEventObjectByClassName($className, $abort=true)
{
if (!class_exists($className)) {
if ($abort) {
throw new Exception('CiviRule cron event class "' . $className . '" does not exist');
throw new Exception('CiviRule event class "' . $className . '" does not exist');
}
return false;
}
$object = new $className();
if (!$object instanceof CRM_Civirules_Event_Cron) {
if (!$object instanceof CRM_Civirules_Event) {
if ($abort) {
throw new Exception('CiviRule cron event class "' . $className . '" is not a subclass of CRM_Civirules_Event_Cron');
throw new Exception('CiviRule event class "' . $className . '" is not a subclass of CRM_Civirules_Event');
}
return false;
}
......
......@@ -165,8 +165,8 @@ class CRM_Civirules_BAO_Rule extends CRM_Civirules_DAO_Rule {
*/
public static function findRulesByObjectNameAndOp($objectName, $op)
{
$rules = array();
$sql = "SELECT r.id AS rule_id, e.id AS event_id
$events = array();
$sql = "SELECT r.id AS rule_id, e.id AS event_id, e.class_name
FROM `civirule_rule` r
INNER JOIN `civirule_event` e ON r.event_id = e.id AND e.is_active = 1
WHERE r.`is_active` = 1 AND e.cron = 0 AND e.object_name = %1 AND e.op = %2";
......@@ -175,13 +175,14 @@ class CRM_Civirules_BAO_Rule extends CRM_Civirules_DAO_Rule {
$dao = CRM_Core_DAO::executeQuery($sql, $params);
while ($dao->fetch()) {
$ruleData = array(
'event_id' => $dao->event_id,
'rule_id' => $dao->rule_id,
);
$rules[] = $ruleData;
$eventObject = CRM_Civirules_BAO_Event::getPostEventObjectByClassName($dao->class_name, $objectName, false);
if ($eventObject !== false) {
$eventObject->setEventId($dao->event_id);
$eventObject->setRuleId($dao->rule_id);
$events[] = $eventObject;
}
}
return $rules;
return $events;
}
/**
......@@ -191,7 +192,7 @@ class CRM_Civirules_BAO_Rule extends CRM_Civirules_DAO_Rule {
*/
public static function findRulesForCron()
{
$rules = array();
$cronEvents = array();
$sql = "SELECT r.id AS rule_id, e.id AS event_id, e.class_name
FROM `civirule_rule` r
INNER JOIN `civirule_event` e ON r.event_id = e.id AND e.is_active = 1
......@@ -199,7 +200,7 @@ class CRM_Civirules_BAO_Rule extends CRM_Civirules_DAO_Rule {
$dao = CRM_Core_DAO::executeQuery($sql);
while ($dao->fetch()) {
$cronEventObject = CRM_Civirules_BAO_Event::getCronEventObjectByClassName($dao->class_name, false);
$cronEventObject = CRM_Civirules_BAO_Event::getEventObjectByClassName($dao->class_name, false);
if ($cronEventObject !== false) {
$cronEventObject->setEventId($dao->event_id);
$cronEventObject->setRuleId($dao->rule_id);
......
......@@ -13,22 +13,18 @@ class CRM_Civirules_Engine {
*
* The trigger will check the conditions and if conditions are valid then the actions are executed
*
* @param CRM_Civirules_Event $event
* @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);
$eventData->setRuleId($ruleId);
$isRuleValid = self::areConditionsValid($eventData, $ruleId);
public static function triggerRule(CRM_Civirules_Event $event, CRM_Civirules_EventData_EventData $eventData) {
$eventData->setEvent($event);
$isRuleValid = self::areConditionsValid($eventData);
if ($isRuleValid) {
self::logRule($eventData, $ruleId);
self::executeActions($eventData, $ruleId);
self::logRule($eventData);
self::executeActions($eventData);
}
}
......@@ -36,13 +32,12 @@ 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) {
$actionParams = array(
'rule_id' => $ruleId
'rule_id' => $eventData->getEvent()->getRuleId(),
);
$ruleActions = CRM_Civirules_BAO_RuleAction::getValues($actionParams);
foreach ($ruleActions as $ruleAction) {
......@@ -72,17 +67,16 @@ class CRM_Civirules_Engine {
* 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) {
$isValid = true;
$firstCondition = true;
$conditionParams = array(
'rule_id' => $ruleId
'rule_id' => $eventData->getEvent()->getRuleId(),
);
$ruleConditions = CRM_Civirules_BAO_RuleCondition::getValues($conditionParams);
foreach ($ruleConditions as $ruleConditionId => $ruleCondition) {
......@@ -132,11 +126,10 @@ class CRM_Civirules_Engine {
* This function writes a record to the log table to indicate that this rule for this event is triggered
*
* @param CRM_Civirules_EventData_EventData $eventData
* @param $ruleId
*/
protected static function logRule(CRM_Civirules_EventData_EventData $eventData, $ruleId) {
protected static function logRule(CRM_Civirules_EventData_EventData $eventData) {
$sql = "INSERT INTO `civirule_rule_log` (`rule_id`, `contact_id`, `log_date`) VALUES (%1, %2, NOW())";
$params[1] = array($ruleId, 'Integer');
$params[1] = array($eventData->getEvent()->getRuleId(), 'Integer');
$params[2] = array($eventData->getContactId(), 'Integer');
CRM_Core_DAO::executeQuery($sql, $params);
}
......
<?php
abstract class CRM_Civirules_Event {
protected $ruleId;
protected $eventId;
public function setRuleId($ruleId) {
$this->ruleId = $ruleId;
}
public function getRuleId() {
return $this->ruleId;
}
public function setEventId($eventId) {
$this->eventId = $eventId;
}
public function getEventId() {
return $this->eventId;
}
/**
* Returns an array of entities on which the event reacts
*
* @return CRM_Civirules_EventData_EntityDefinition
*/
abstract protected function reactOnEntity();
public function getProvidedEntities() {
$additionalEntities = $this->getAdditionalEntities();
foreach($additionalEntities as $entity) {
$entities[$entity->key] = $entity;
}
$entity = $this->reactOnEntity();
$entities[$entity->key] = $entity;
return $entities;
}
/**
* Returns an array of additional entities provided in this event
*
* @return array of CRM_Civirules_EventData_EntityDefinition
*/
protected function getAdditionalEntities() {
return array();
}
}
\ No newline at end of file
<?php
abstract class CRM_Civirules_Event_Cron {
protected $ruleId;
protected $eventId;
public function setRuleId($ruleId) {
$this->ruleId = $ruleId;
}
public function getRuleId() {
return $this->ruleId;
}
public function setEventId($eventId) {
$this->eventId = $eventId;
}
public function getEventId() {
return $this->eventId;
}
abstract class CRM_Civirules_Event_Cron extends CRM_Civirules_Event {
/**
* This function returns a CRM_Civirules_EventData_EventData this entity is used for triggering the rule
......
<?php
/**
* Class for CiviRules post event handling
*
* @author Jaap Jansma (CiviCooP) <jaap.jansma@civicoop.org>
* @license AGPL-3.0
*/
class CRM_Civirules_Event_Post extends CRM_Civirules_Event {
protected $objectName;
protected $op;
public function setEventId($eventId) {
parent::setEventId($eventId);
$event = new CRM_Civirules_BAO_Event();
$event->id = $this->eventId;
if (!$event->find(true)) {
throw new Exception('Civirules: could not find event with ID: '.$this->eventId);
}
$this->objectName = $event->object_name;
$this->op = $event->op;
}
/**
* Returns an array of entities on which the event reacts
*
* @return CRM_Civirules_EventData_EntityDefinition
*/
protected function reactOnEntity() {
$entity = CRM_Civirules_Utils_ObjectName::convertToEntity($this->objectName);
return new CRM_Civirules_EventData_EntityDefinition($this->objectName, $entity, $this->getDaoClassName(), $entity);
}
/**
* Return the name of the DAO Class. If a dao class does not exist return an empty value
*
* @return string
*/
protected function getDaoClassName() {
$daoClassName = CRM_Core_DAO_AllCoreTables::getFullName($this->objectName);
return $daoClassName;
}
/**
* 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())) {
return;
}
$entity = CRM_Civirules_Utils_ObjectName::convertToEntity($objectName);
//set data
$data = array();
if (is_object($objectRef)) {
CRM_Core_DAO::storeValues($objectRef, $data);
} elseif (is_array($objectRef)) {
$data = $objectRef;
}
if ($op == 'edit') {
//set also original data with an edit event
$oldData = CRM_Civirules_Utils_PreData::getPreData($entity, $objectId);
$eventData = new CRM_Civirules_EventData_Edit($entity, $objectId, $data, $oldData);
} else {
$eventData = new CRM_Civirules_EventData_Post($entity, $objectId, $data);
}
//find matching rules for this objectName and op
$events = CRM_Civirules_BAO_Rule::findRulesByObjectNameAndOp($objectName, $op);
foreach($events as $event) {
CRM_Civirules_Engine::triggerRule($event, clone $eventData);
}
}
}
\ No newline at end of file
<?php
class CRM_Civirules_EventData_EntityDefinition {
/**
* Label of the entity might be shown to the user
*
* @var string
*/
public $label;
/**
* Entity type e.g. contact, contribution, event, participant etc...
*
* @var string
*/
public $entity;
/**
* DAO class name e.g. CRM_Contact_DAO_Contact or CRM_Contribution_DAO_Contribution
*
* @var string
*/
public $daoClass;
/**
* Key of this entity in the event e.g. contact, individual, first_contribution etc...,
*
* @var string
*/
public $key;
public function __construct($label, $entity, $daoClass='', $key='') {
$this->label = $label;
$this->entity = $entity;
$this->daoClass = $daoClass;
$this->key = $entity;
if (!empty($key)) {
$this->key = $key;
}
}
}
\ No newline at end of file
......@@ -15,16 +15,32 @@ abstract class CRM_Civirules_EventData_EventData {
*/
private $entity_data = array();
protected $event_id;
protected $rule_id;
protected $contact_id;
/**
* @var CRM_Civirules_Event
*/
protected $event;
public function __construct() {
}
/**
* Set the event
*
* @param CRM_Civirules_Event $event
*/
public function setEvent(CRM_Civirules_Event $event) {
$this->event = $event;
}
/**
* @return CRM_Civirules_Event
*/
public function getEvent() {
return $this->event;
}
/**
* Returns the ID of the contact used in the event
......@@ -64,24 +80,6 @@ abstract class CRM_Civirules_EventData_EventData {
return $this;
}
public function setEventId($event_id) {
$this->event_id = $event_id;
return $this;
}
public function setRuleId($rule_id) {
$this->rule_id = $rule_id;
return $this;
}
public function getEventId() {
return $this->event_id;
}
public function getRuleId() {
return $this->rule_id;
}
}
\ No newline at end of file
......@@ -133,13 +133,15 @@ class CRM_Civirules_Form_RuleCondition extends CRM_Core_Form {
$event->id = $rule->event_id;
$event->find(true);
$eventEntities = array('contact');
$eventEntities[] = strtolower($event->object_name);
if (CRM_Civirules_Event_EditEntity::convertObjectNameToEntity($event->object_name) != $event->object_name) {
$eventEntities[] = strtolower(CRM_Civirules_Event_EditEntity::convertObjectNameToEntity($event->object_name));
$eventObject = CRM_Civirules_BAO_Event::getPostEventObjectByClassName($event->class_name, true);
$eventObject->setEventId($event->id);
$availableEntities = array();
foreach($eventObject->getProvidedEntities() as $entityDef) {
$availableEntities[] = strtolower($entityDef->entity);
}
foreach($requiredEntities as $entity) {
if (!in_array(strtolower($entity), $eventEntities)) {
if (!in_array(strtolower($entity), $availableEntities)) {
$errors['rule_condition_select'] = ts('This condition is not available with event %1', array(1 => $event->label));
return $errors;
}
......
<?php
class CRM_Civirules_Utils_ObjectName {
/**
* Method to convert the object name to the entity for contacts
*
* @param string $objectName
* @return string $entity
* @access public
* @static
*/
public static function convertToEntity($objectName) {
$entity = $objectName;
switch($objectName) {
case 'Individual':
case 'Household':
case 'Organization':
$entity = 'contact';
break;
}
return $entity;
}
}
\ No newline at end of file
<?php
/**
* 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_Utils_PreData {
/**
* Data set in pre and used for compare which field is changed
......@@ -33,52 +27,11 @@ class CRM_Civirules_Event_EditEntity {
}
//retrieve data as it is currently in the database
$entity = self::convertObjectNameToEntity($objectName);
$entity = CRM_Civirules_Utils_ObjectName::convertToEntity($objectName);
$data = civicrm_api3($entity, 'getsingle', array('id' => $objectId));
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())) {
return;
}
$entity = self::convertObjectNameToEntity($objectName);
//set data
$data = array();
if (is_object($objectRef)) {
CRM_Core_DAO::storeValues($objectRef, $data);
} elseif (is_array($objectRef)) {
$data = $objectRef;
}
if ($op == 'edit') {
//set also original data with an edit event
$oldData = self::getPreData($entity, $objectId);
$eventData = new CRM_Civirules_EventData_Edit($entity, $objectId, $data, $oldData);
} else {
$eventData = new CRM_Civirules_EventData_Post($entity, $objectId, $data);
}
//find matching rules for this objectName and op
$rules = CRM_Civirules_BAO_Rule::findRulesByObjectNameAndOp($objectName, $op);
foreach($rules as $rule) {
CRM_Civirules_Engine::triggerRule(clone $eventData, $rule['rule_id'], $rule['event_id']);
}
}
/**
* Method to set the pre operation data
*
......@@ -96,36 +49,16 @@ class CRM_Civirules_Event_EditEntity {
* Method to get the pre operation data
*
* @param string $entity
* @param id $entityId
* @param int $entityId
* @return array
* @access protected
* @static
*/
protected static function getPreData($entity, $entityId) {
public 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) {
case 'Individual':
case 'Household':
case 'Organization':
$entity = 'contact';
break;
}
return $entity;
}
}
\ No newline at end of file
<?php
class CRM_CivirulesConditions_FieldValueComparison extends CRM_CivirulesConditions_Generic_ValueComparison {
/**
* Returns the value of the field for the condition
* For example: I want to check if age > 50, this function would return the 50
*
* @param object CRM_Civirules_EventData_EventData $eventData
* @return
* @access protected
* @abstract
*/
protected function getFieldValue(CRM_Civirules_EventData_EventData $eventData) {
$entity = $this->conditionParams['entity'];
$field = $this->conditionParams['field'];
$data = $eventData->getEntityData($entity);
if (isset($data[$field])) {
return $this->normalizeValue($data[$field]);
}
return null;
}
/**
* Returns the value for the data comparison
*
* @return mixed
* @access protected
*/
protected function getComparisonValue() {
if (!empty($this->conditionParams['value'])) {
return $this->normalizeValue($this->conditionParams['value']);
} else {
return null;
}
}
protected function normalizeValue($value) {
if (value === null) {
return null;
}
//@todo normalize value based on the field
return $value;
}
/**
* Returns a redirect url to extra data input from the user after adding a condition
*
* Return false if you do not need extra data input
*
* @param int $ruleConditionId
* @return bool|string
* @access public
*/
public function getExtraDataInputUrl($ruleConditionId) {
return CRM_Utils_System::url('civicrm/civirule/form/condition/fieldvaluecomparison/', 'rule_condition_id='.$ruleConditionId);
}
/**
* Returns a user friendly text explaining the condition params
* e.g. 'Older than 65'
*
* @return string
* @access public
*/
public function userFriendlyConditionParams() {
return htmlentities($this->conditionParams['entity'].'.'.$this->conditionParams['field'].' '.($this->getOperator())).' '.htmlentities($this->getComparisonValue());
}
}
\ No newline at end of file
<?php
/**
* Class for CiviRules ValueComparison Form
*
* @author Jaap Jansma (CiviCooP) <jaap.jansma@civicoop.org>
* @license AGPL-3.0
*/
class CRM_CivirulesConditions_Form_FieldValueComparison extends CRM_Core_Form {
protected $ruleConditionId = false;
protected $ruleCondition;
protected $condition;
protected $rule;
protected $event;
/**
* @var CRM_Civirules_Event
*/
protected $eventClass;
/**
* Overridden parent method to perform processing before form is build
*
* @access public
*/
public function preProcess() {
$this->ruleConditionId = CRM_Utils_Request::retrieve('rule_condition_id', 'Integer');
$this->ruleCondition = new CRM_Civirules_BAO_RuleCondition();
$this->ruleCondition->id = $this->ruleConditionId;
$this->condition = new CRM_Civirules_BAO_Condition();
$this->rule = new CRM_Civirules_BAO_Rule();
$this->event = new CRM_Civirules_BAO_Event();
if (!$this->ruleCondition->find(true)) {
throw new Exception('Civirules could not find ruleCondition');
}
$this->condition->id = $this->ruleCondition->condition_id;
if (!$this->condition->find(true)) {
throw new Exception('Civirules could not find condition');
}
$this->rule->id = $this->ruleCondition->rule_id;
if (!$this->rule->find(true)) {
throw new Exception('Civirules could not find rule');
}
$this->event->id = $this->rule->event_id;
if (!$this->event->find(true)) {
throw new Exception('Civirules could not find event');
}
$this->eventClass = CRM_Civirules_BAO_Event::getPostEventObjectByClassName($this->event->class_name, true);
$this->eventClass->setEventId($this->event->id);
parent::preProcess();
}
protected function getEntities() {
$return = array();
foreach($this->eventClass->getProvidedEntities() as $entityDef) {
if (!empty($entityDef->daoClass) && class_exists($entityDef->daoClass)) {
$return[$entityDef->entity] = $entityDef->label;
}
}
return $return;
}
protected function getFields() {
$return = array();
foreach($this->eventClass->getProvidedEntities() as $entityDef) {
if (!empty($entityDef->daoClass) && class_exists($entityDef->daoClass)) {
$key = $entityDef->entity . '_';
$className = $entityDef->daoClass;
if (!is_callable(array($className, 'fields'))) {
continue;
}
$fields = call_user_func(array($className, 'fields'));
foreach ($fields as $field) {
$fieldKey = $key . $field['name'];
$label = $field['title'];
if (empty($label)) {
$label = $field['name'];
}
$return[$fieldKey] = $label;
}
}
}
return $return;
}
/**
* Overridden parent method to build form
*
* @access public
*/
public function buildQuickForm() {
$this->setFormTitle();
$this->add('hidden', 'rule_condition_id');
$this->add('select', 'entity', ts('Entity'), $this->getEntities(), true);
$this->add('select', 'field', ts('Field'), $this->getFields(), true);
$this->add('select', 'operator', ts('Operator'), array(
'=' => ts('Is equal to'),
'!=' => ts('Is not equal to'),
'>' => ts('Is greater than'),
'<' => ts('Is less than'),
'>=' => ts('Is greater than or equal to'),
'<=' => ts('Is less than or equal to'),
), true);
$this->add('text', 'value', ts('Compare value'), true);
$this->addButtons(array(
array('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE,),
array('type' => 'cancel', 'name' => ts('Cancel'))));
}
/**
* Function to add validation condition rules (overrides parent function)
*
* @access public
*/
public function addRules()
{
$this->addFormRule(array('CRM_CivirulesConditions_Form_FieldValueComparison', 'validateEntityAndField'));
}
public static function validateEntityAndField($fields) {
$entity = $fields['entity'];
if (empty($entity)) {
return array('entity' => ts('Entity could not be empty'));
}
if (stripos($fields['field'], $fields['entity'].'_')!==0) {
return array('entity' => ts('Field is not valid'));
}
return true;
}
/**
* Overridden parent method to set default values
*
* @return array $defaultValues
* @access public
*/
public function setDefaultValues() {
$data = array();
$defaultValues['rule_condition_id'] = $this->ruleConditionId;
if (!empty($this->ruleCondition->condition_params)) {
$data = unserialize($this->ruleCondition->condition_params);
}
if (!empty($data['operator'])) {
$defaultValues['operator'] = $data['operator'];
}
if (!empty($data['value'])) {
$defaultValues['value'] = $data['value'];
}
if (!empty($data['entity'])) {
$defaultValues['entity'] = $data['entity'];
}
if (!empty($data['entity']) && !empty($data['field'])) {
$defaultValues['field'] = $data['entity'].'_'.$data['field'];
}
return $defaultValues;
}
/**
* Overridden parent method to process form data after submission
*
* @throws Exception when rule condition not found
* @access public
*/
public function postProcess() {
$data['operator'] = $this->_submitValues['operator'];
$data['value'] = $this->_submitValues['value'];
$data['entity'] = $this->_submitValues['entity'];
$data['field'] = substr($this->_submitValues['field'], strlen($data['entity'].'_'));
$this->ruleCondition->condition_params = serialize($data);
$this->ruleCondition->save();
$session = CRM_Core_Session::singleton();
$session->setStatus('Condition '.$this->condition->label .'Parameters updated to CiviRule '
.$this->rule->label,
'Condition parameters updated', 'success');
$redirectUrl = CRM_Utils_System::url('civicrm/civirule/form/rule', 'action=update&id='.$this->rule->id, TRUE);
CRM_Utils_System::redirect($redirectUrl); }
/**
* Method to set the form title
*
* @access protected
*/
protected function setFormTitle() {
$title = 'CiviRules Edit Condition parameters';
$this->assign('ruleConditionHeader', 'Edit Condition '.$this->condition->label.' of CiviRule '.$this->rule->label);
CRM_Utils_System::setTitle($title);
}
}
\ No newline at end of file
......@@ -82,7 +82,6 @@ abstract class CRM_CivirulesConditions_Generic_ValueComparison extends CRM_Civir
public function isConditionValid(CRM_Civirules_EventData_EventData $eventData) {
$value = $this->getFieldValue($eventData);
$compareValue = $this->getComparisonValue();
return $this->compare($value, $compareValue, $this->getOperator());
}
......
......@@ -10,6 +10,15 @@ class CRM_CivirulesCronEvent_Birthday extends CRM_Civirules_Event_Cron {
private $dao = false;
/**
* Returns an array of entities on which the event reacts
*
* @return CRM_Civirules_EventData_EntityDefinition
*/
protected function reactOnEntity() {
return new CRM_Civirules_EventData_EntityDefinition(ts('Person'), 'contact', 'CRM_Contact_DAO_Contact', 'contact');
}
/**
* This method returns a CRM_Civirules_EventData_EventData this entity is used for triggering the rule
*
......
<?php
class CRM_CivirulesPostEvent_Contact extends CRM_Civirules_Event_Post {
/**
* Returns an array of entities on which the event reacts
*
* @return CRM_Civirules_EventData_EntityDefinition
*/
protected function reactOnEntity() {
return new CRM_Civirules_EventData_EntityDefinition($this->objectName, $this->objectName, $this->getDaoClassName(), 'contact');
}
/**
* Return the name of the DAO Class. If a dao class does not exist return an empty value
*
* @return string
*/
protected function getDaoClassName() {
return 'CRM_Contact_DAO_Contact';
}
}
\ No newline at end of file
......@@ -25,7 +25,7 @@ function civicrm_api3_civi_rule_action_create($params) {
if (!isset($params['id']) && empty($params['label'])) {
return civicrm_api3_create_error('Label can not be empty when adding a new CiviRule Action');
}
if (empty($params['class_name'])) {
if (empty($params['class_name']) && !isset($params['id'])) {
return civicrm_api3_create_error('Class_name can not be empty');
}
/*
......
......@@ -26,7 +26,7 @@ function civicrm_api3_civi_rule_condition_create($params) {
if (!isset($params['id']) && empty($params['label'])) {
return civicrm_api3_create_error('Label can not be empty when adding a new CiviRule Condition');
}
if (empty($params['class_name'])) {
if (empty($params['class_name']) && !isset($params['id'])) {
return civicrm_api3_create_error('Class_name can not be empty');
}
/*
......
......@@ -123,9 +123,9 @@ function civirules_civicrm_navigationMenu( &$params ) {
}
function civirules_civicrm_pre($op, $objectName, $objectId, &$params) {
CRM_Civirules_Event_EditEntity::pre($op, $objectName, $objectId, $params);
CRM_Civirules_Utils_PreData::pre($op, $objectName, $objectId, $params);
}
function civirules_civicrm_post( $op, $objectName, $objectId, &$objectRef ) {
CRM_Civirules_Event_EditEntity::post($op, $objectName, $objectId, $objectRef);
CRM_Civirules_Event_Post::post($op, $objectName, $objectId, $objectRef);
}
......@@ -9,26 +9,26 @@ VALUES
('new_case', 'Case is added', 'Case', 'create', null, CURDATE(), 1),
('changed_case', 'Case is changed', 'Case', 'edit', null, CURDATE(), 1),
('deleted_case', 'Case is deleted', 'Case', 'delete', null, CURDATE(), 1),
('new_contact', 'Contact of any type is added', 'Contact', 'create', null, CURDATE(), 1),
('changed_contact', 'Contact of any type is changed', 'Contact', 'edit', null, CURDATE(), 1),
('deleted_contact', 'Contact of any type is deleted', 'Contact', 'delete', null, CURDATE(), 1),
('trashed_contact', 'Contact of any type is trashed', 'Contact', 'delete', null, CURDATE(), 1),
('restored_contact', 'Contact of any type is restored', 'Contact', 'delete', null, CURDATE(), 1),
('new_individual', 'Individual is added', 'Individual', 'create', null, CURDATE(), 1),
('changed_individual', 'Individual is changed', 'Individual', 'edit', null, CURDATE(), 1),
('deleted_individual', 'Individual is deleted', 'Individual', 'delete', null, CURDATE(), 1),
('trashed_individual', 'Individual is trashed', 'Individual', 'delete', null, CURDATE(), 1),
('restored_individual', 'Individual is restored', 'Individual', 'delete', null, CURDATE(), 1),
('new_household', 'Household is added', 'Household', 'create', null, CURDATE(), 1),
('changed_household', 'Household is changed', 'Household', 'edit', null, CURDATE(), 1),
('deleted_household', 'Household is deleted', 'Household', 'delete', null, CURDATE(), 1),
('trashed_household', 'Household is trashed', 'Household', 'delete', null, CURDATE(), 1),
('restored_household', 'Household is restored', 'Household', 'delete', null, CURDATE(), 1),
('new_organization', 'Organization is added', 'Organization', 'create', null, CURDATE(), 1),
('changed_organization', 'Organization is changed', 'Organization', 'edit', null, CURDATE(), 1),
('deleted_organization', 'Organization is deleted', 'Organization', 'delete', null, CURDATE(), 1),
('trashed_organization', 'Organization is trashed', 'Organization', 'delete', null, CURDATE(), 1),
('restored_organization', 'Organization is restored', 'Organization', 'delete', null, CURDATE(), 1);
('new_contact', 'Contact of any type is added', 'Contact', 'create', 'CRM_CivirulesPostEvent_Contact', CURDATE(), 1),
('changed_contact', 'Contact of any type is changed', 'Contact', 'edit', 'CRM_CivirulesPostEvent_Contact', CURDATE(), 1),
('deleted_contact', 'Contact of any type is deleted', 'Contact', 'delete', 'CRM_CivirulesPostEvent_Contact', CURDATE(), 1),
('trashed_contact', 'Contact of any type is trashed', 'Contact', 'delete', 'CRM_CivirulesPostEvent_Contact', CURDATE(), 1),
('restored_contact', 'Contact of any type is restored', 'Contact', 'delete', 'CRM_CivirulesPostEvent_Contact', CURDATE(), 1),
('new_individual', 'Individual is added', 'Individual', 'create', 'CRM_CivirulesPostEvent_Contact', CURDATE(), 1),
('changed_individual', 'Individual is changed', 'Individual', 'edit', 'CRM_CivirulesPostEvent_Contact', CURDATE(), 1),
('deleted_individual', 'Individual is deleted', 'Individual', 'delete', 'CRM_CivirulesPostEvent_Contact', CURDATE(), 1),
('trashed_individual', 'Individual is trashed', 'Individual', 'delete', 'CRM_CivirulesPostEvent_Contact', CURDATE(), 1),
('restored_individual', 'Individual is restored', 'Individual', 'delete', 'CRM_CivirulesPostEvent_Contact', CURDATE(), 1),
('new_household', 'Household is added', 'Household', 'create', 'CRM_CivirulesPostEvent_Contact', CURDATE(), 1),
('changed_household', 'Household is changed', 'Household', 'edit', 'CRM_CivirulesPostEvent_Contact', CURDATE(), 1),
('deleted_household', 'Household is deleted', 'Household', 'delete', 'CRM_CivirulesPostEvent_Contact', CURDATE(), 1),
('trashed_household', 'Household is trashed', 'Household', 'delete', 'CRM_CivirulesPostEvent_Contact', CURDATE(), 1),
('restored_household', 'Household is restored', 'Household', 'delete', 'CRM_CivirulesPostEvent_Contact', CURDATE(), 1),
('new_organization', 'Organization is added', 'Organization', 'create', 'CRM_CivirulesPostEvent_Contact', CURDATE(), 1),
('changed_organization', 'Organization is changed', 'Organization', 'edit', 'CRM_CivirulesPostEvent_Contact', CURDATE(), 1),
('deleted_organization', 'Organization is deleted', 'Organization', 'delete', 'CRM_CivirulesPostEvent_Contact', CURDATE(), 1),
('trashed_organization', 'Organization is trashed', 'Organization', 'delete', 'CRM_CivirulesPostEvent_Contact', CURDATE(), 1),
('restored_organization', 'Organization is restored', 'Organization', 'delete', 'CRM_CivirulesPostEvent_Contact', CURDATE(), 1);
INSERT INTO civirule_event (name, label, object_name, op, class_name, created_date, created_user_id)
VALUES
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment