abstract class RulesConditionalPredicateElement in Conditional Rules 8
Same name and namespace in other branches
- 7 includes/rules_conditional.core.inc \RulesConditionalPredicateElement
Base conditional element that uses a predicate.
Hierarchy
- class \RulesConditionalElement extends \RulesActionContainer implements \RulesActionInterface
Expanded class hierarchy of RulesConditionalPredicateElement
File
- includes/
rules_conditional.core.inc, line 396 - Conditional Rules framework implementation.
View source
abstract class RulesConditionalPredicateElement extends RulesConditionalElement {
/**
* @var RulesCondition
*/
protected $predicate;
public function __construct($predicate = NULL, $settings = array()) {
parent::__construct();
if (isset($predicate)) {
$predicate = is_object($predicate) && $predicate instanceof RulesConditionInterface ? $predicate : rules_condition($predicate, $settings);
$this
->setPredicate($predicate);
}
}
/**
* Sets a condition as predicate.
*/
protected function setPredicate($predicate) {
$this->predicate = $predicate;
$this->predicate->parent = $this;
// Set up variables with the new parent.
$this
->resetInternalCache();
}
public function resetInternalCache() {
parent::resetInternalCache();
if (isset($this->predicate)) {
$this->predicate
->resetInternalCache();
}
}
public function __sleep() {
$array = parent::__sleep();
$array['predicate'] = 'predicate';
return $array;
}
public function __clone() {
parent::__clone();
$this->predicate = clone $this->predicate;
$this->predicate->parent = $this;
}
public function label() {
$text = '@plugin';
$variables = array(
'@plugin' => $this
->pluginLabel(),
);
if (isset($this->predicate)) {
$text = '@plugin: @label';
$variables['@label'] = $this->predicate
->label();
}
return t($text, $variables);
}
public function pluginLabel() {
return parent::label();
}
public function integrityCheck() {
if (!isset($this->predicate)) {
throw new RulesIntegrityException(t('The conditional "%plugin" does not have a valid predicate.', array(
'%plugin' => $this
->plugin(),
)), $this);
}
parent::integrityCheck();
return $this;
}
/**
* Adds predicate assertions to state.
*/
protected function stateVariables($element = NULL) {
if (!isset($element) || $element === $this->predicate) {
return parent::stateVariables();
}
else {
// Add assertions from the predicate.
$variables = parent::stateVariables($element);
if (isset($this->predicate) && ($assertions = $this->predicate
->call('variableInfoAssertions'))) {
$variables = RulesData::addMetadataAssertions($variables, $assertions);
}
return $variables;
}
}
public function dependencies() {
$modules = array_flip(parent::dependencies());
if (isset($this->predicate)) {
$modules += array_flip($this->predicate
->dependencies());
}
return array_keys($modules);
}
/**
* Negates the predicate.
*/
public function negate($negate = TRUE) {
$this->predicate
->negate($negate);
return $this;
}
/**
* Returns whether the predicate is negated.
*/
public function isNegated() {
return $this->predicate
->isNegated();
}
/**
* Evaluates the predicate.
*/
public function canEvaluate(RulesState $state) {
return $this->predicate
->evaluate($state);
}
/**
* Imports predicate.
*/
protected function importChildren($export, $key = NULL) {
$this
->importPredicate($export);
parent::importChildren($export, 'DO');
}
/**
* Imports predicate.
*/
protected function importPredicate($export, $key = NULL) {
if (!isset($key)) {
$key = strtoupper($this
->plugin());
}
$predicate = rules_plugin_factory('condition');
$this
->setPredicate($predicate);
$predicate
->import($export[$key]);
}
/**
* Exports predicate with actions.
*/
protected function exportChildren($key = NULL) {
$export = $this
->exportPredicate();
return $export + parent::exportChildren('DO');
}
/**
* Exports predicate.
*/
protected function exportPredicate($key = NULL) {
$export = array();
if (!isset($key)) {
$key = strtoupper($this
->plugin());
}
if (isset($this->predicate)) {
$export[$key] = $this->predicate
->export();
}
return $export;
}
protected function exportFlat() {
return TRUE;
}
}