updated rules
This commit is contained in:
@@ -1,15 +1,18 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file Contains plugin info and implementations not needed for rule evaluation.
|
||||
* @file
|
||||
* Contains plugin info and implementations not needed for rule evaluation.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Implements a rules action.
|
||||
*/
|
||||
class RulesAction extends RulesAbstractPlugin implements RulesActionInterface {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $itemName = 'action';
|
||||
|
||||
/**
|
||||
@@ -69,6 +72,7 @@ class RulesAction extends RulesAbstractPlugin implements RulesActionInterface {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,7 +80,14 @@ class RulesAction extends RulesAbstractPlugin implements RulesActionInterface {
|
||||
*/
|
||||
class RulesCondition extends RulesAbstractPlugin implements RulesConditionInterface {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $itemName = 'condition';
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $negate = FALSE;
|
||||
|
||||
public function providesVariables() {
|
||||
@@ -132,19 +143,28 @@ class RulesCondition extends RulesAbstractPlugin implements RulesConditionInterf
|
||||
|
||||
public function label() {
|
||||
$label = parent::label();
|
||||
return $this->negate ? t('NOT @condition', array('@condition' => $label)) : $label;
|
||||
return $this->negate ? t('NOT !condition', array('!condition' => $label)) : $label;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* An actual rule.
|
||||
*
|
||||
* Note: A rule also implements the RulesActionInterface (inherited).
|
||||
*/
|
||||
class Rule extends RulesActionContainer {
|
||||
|
||||
protected $conditions = NULL;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $itemName = 'rule';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $label = 'unlabeled';
|
||||
|
||||
public function __construct($variables = array(), $providesVars = array()) {
|
||||
@@ -159,8 +179,9 @@ class Rule extends RulesActionContainer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an iterator over all contained conditions. Note that this iterator also
|
||||
* implements the ArrayAcces interface.
|
||||
* Gets an iterator over all contained conditions.
|
||||
*
|
||||
* Note that this iterator also implements the ArrayAccess interface.
|
||||
*
|
||||
* @return RulesRecursiveElementIterator
|
||||
*/
|
||||
@@ -183,8 +204,9 @@ class Rule extends RulesActionContainer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an iterator over all contained actions. Note that this iterator also
|
||||
* implements the ArrayAccess interface.
|
||||
* Gets an iterator over all contained actions.
|
||||
*
|
||||
* Note that this iterator also implements the ArrayAccess interface.
|
||||
*
|
||||
* @return RulesRecursiveElementIterator
|
||||
*/
|
||||
@@ -193,11 +215,12 @@ class Rule extends RulesActionContainer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a condition. Pass either an instance of the RulesConditionInterface
|
||||
* or the arguments as needed by rules_condition().
|
||||
* Adds a condition.
|
||||
*
|
||||
* @return Rule
|
||||
* Returns $this to support chained usage.
|
||||
* Pass either an instance of the RulesConditionInterface or the arguments as
|
||||
* needed by rules_condition().
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function condition($name, $settings = array()) {
|
||||
$this->conditions->condition($name, $settings);
|
||||
@@ -309,7 +332,9 @@ class Rule extends RulesActionContainer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Rules may not provided any variable info assertions, as Rules are only
|
||||
* Overrides RulesPlugin::variableInfoAssertions().
|
||||
*
|
||||
* Rules may not provide any variable info assertions, as Rules are only
|
||||
* conditionally executed.
|
||||
*/
|
||||
protected function variableInfoAssertions() {
|
||||
@@ -324,7 +349,7 @@ class Rule extends RulesActionContainer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Overriden to expose the variables of all actions for embedded rules.
|
||||
* Overridden to expose the variables of all actions for embedded rules.
|
||||
*/
|
||||
public function providesVariables() {
|
||||
$provides = parent::providesVariables();
|
||||
@@ -340,6 +365,7 @@ class Rule extends RulesActionContainer {
|
||||
parent::resetInternalCache();
|
||||
$this->conditions->resetInternalCache();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -347,8 +373,20 @@ class Rule extends RulesActionContainer {
|
||||
*/
|
||||
class RulesReactionRule extends Rule implements RulesTriggerableInterface {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $itemName = 'reaction rule';
|
||||
protected $events = array(), $eventSettings = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $events = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $eventSettings = array();
|
||||
|
||||
/**
|
||||
* Implements RulesTriggerableInterface::events().
|
||||
@@ -516,6 +554,7 @@ class RulesReactionRule extends Rule implements RulesTriggerableInterface {
|
||||
// No need to keep event settings for evaluation.
|
||||
$this->eventSettings = array();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -523,6 +562,9 @@ class RulesReactionRule extends Rule implements RulesTriggerableInterface {
|
||||
*/
|
||||
class RulesAnd extends RulesConditionContainer {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $itemName = 'and';
|
||||
|
||||
public function evaluate(RulesState $state) {
|
||||
@@ -539,6 +581,7 @@ class RulesAnd extends RulesConditionContainer {
|
||||
public function label() {
|
||||
return !empty($this->label) ? $this->label : ($this->negate ? t('NOT AND') : t('AND'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -546,6 +589,9 @@ class RulesAnd extends RulesConditionContainer {
|
||||
*/
|
||||
class RulesOr extends RulesConditionContainer {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $itemName = 'or';
|
||||
|
||||
public function evaluate(RulesState $state) {
|
||||
@@ -564,6 +610,8 @@ class RulesOr extends RulesConditionContainer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides RulesContainerPlugin::stateVariables().
|
||||
*
|
||||
* Overridden to exclude all variable assertions as in an OR we cannot assert
|
||||
* the children are successfully evaluated.
|
||||
*/
|
||||
@@ -580,6 +628,7 @@ class RulesOr extends RulesConditionContainer {
|
||||
}
|
||||
return $vars;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -587,6 +636,9 @@ class RulesOr extends RulesConditionContainer {
|
||||
*/
|
||||
class RulesLoop extends RulesActionContainer {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $itemName = 'loop';
|
||||
protected $listItemInfo;
|
||||
|
||||
@@ -693,6 +745,7 @@ class RulesLoop extends RulesActionContainer {
|
||||
$this->settings['item:label'] = reset($export['ITEM']);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -700,6 +753,9 @@ class RulesLoop extends RulesActionContainer {
|
||||
*/
|
||||
class RulesActionSet extends RulesActionContainer {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $itemName = 'action set';
|
||||
|
||||
}
|
||||
@@ -709,6 +765,9 @@ class RulesActionSet extends RulesActionContainer {
|
||||
*/
|
||||
class RulesRuleSet extends RulesActionContainer {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $itemName = 'rule set';
|
||||
|
||||
/**
|
||||
@@ -725,6 +784,7 @@ class RulesRuleSet extends RulesActionContainer {
|
||||
protected function importChildren($export, $key = 'RULES') {
|
||||
parent::importChildren($export, $key);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -732,8 +792,16 @@ class RulesRuleSet extends RulesActionContainer {
|
||||
*/
|
||||
class RulesEventSet extends RulesRuleSet {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $itemName = 'event set';
|
||||
// Event sets may recurse as we block recursions on rule-level.
|
||||
|
||||
/**
|
||||
* Event sets may recurse as we block recursions on rule-level.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $recursion = TRUE;
|
||||
|
||||
public function __construct($info = array()) {
|
||||
@@ -751,7 +819,10 @@ class RulesEventSet extends RulesRuleSet {
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache event-sets per event to allow efficient usage via rules_invoke_event().
|
||||
* Rebuilds the event cache.
|
||||
*
|
||||
* We cache event-sets per event in order to allow efficient usage via
|
||||
* rules_invoke_event().
|
||||
*
|
||||
* @see rules_get_cache()
|
||||
* @see rules_invoke_event()
|
||||
@@ -824,4 +895,5 @@ class RulesEventSet extends RulesRuleSet {
|
||||
public function save($name = NULL, $module = 'rules') {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user