You are here

class RulesConditionalSwitch in Conditional Rules 7

Same name and namespace in other branches
  1. 8 includes/rules_conditional.plugin.inc \RulesConditionalSwitch

Switch conditional container.

@method RulesConditionalSwitch case() case($value, $fallThrough = FALSE, $valueIsSelector = FALSE) Adds a "case" statement. @method RulesConditionalSwitch defaultCase() defaultCase() Adds a "default case" statement. @method RulesConditionalSwitch action() action($name, array $settings = array()) Adds an action to the currently active statement. Pass arguments as rules_action() would need.

Hierarchy

Expanded class hierarchy of RulesConditionalSwitch

1 string reference to 'RulesConditionalSwitch'
rules_conditional_rules_plugin_info in ./rules_conditional.rules.inc
Implements hook_rules_plugin_info().

File

includes/rules_conditional.plugin.inc, line 160
Rules plugin implementation.

View source
class RulesConditionalSwitch extends RulesConditionalContainer {
  protected $itemName = 'switch';

  /**
   * Intercepts calls to "case" and "defaultCase".
   * @var array
   */
  protected $interceptMethods = array(
    'case',
    'defaultCase',
  );
  public function __construct($dataSelector = NULL) {
    parent::__construct();
    if (isset($dataSelector)) {
      $this->settings['data:select'] = $dataSelector;
    }
  }

  /**
   * Adds a "case" statement, for use with magic call.
   */
  protected function call_case($settings = array(), $fallThrough = FALSE) {
    $this->fluentElement = $element = rules_conditional_case($settings, $fallThrough);
    $element
      ->setParent($this);
    return $this;
  }

  /**
   * Adds a "defaultCase" statement, for use with magic call.
   */
  protected function call_defaultCase() {
    $this->fluentElement = $element = rules_conditional_default_case();
    $element
      ->setParent($this);
    return $this;
  }
  public function pluginParameterInfo() {
    $parameterInfo = array(
      'data' => array(
        'type' => '*',
        'label' => t('Data to match cases against'),
        'description' => t('The data to be compared, specified by using a data selector, e.g. "node:author:name".'),
        'restriction' => 'selector',
        'allow null' => TRUE,
      ),
    );
    return $parameterInfo;
  }

  /**
   * Selects the branches to evaluate for this conditional.
   *
   * @param RulesState $state
   *   Rules state to use.
   * @return RulesConditionalElement[]
   *   An array of branches to evaluate.
   */
  protected function selectBranches(RulesState $state) {
    $branches = array();

    // Collect all cases to be evaluated.
    $fallThrough = FALSE;
    foreach ($this->children as $case) {

      /** @var $case RulesConditionalCase */
      if ($case
        ->canEvaluate($state)) {
        $branches[] = $case;
      }
    }
    return $branches;
  }
  protected function importChildren($export, $key = NULL) {
    parent::importChildren($export, 'DO');
  }
  protected function exportChildren($key = NULL) {
    return parent::exportChildren('DO');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RulesConditionalContainer::$fluentElement protected property
RulesConditionalContainer::$providesVariables protected property
RulesConditionalContainer::action public function Adds an action to the active fluent statement.
RulesConditionalContainer::delete public function Deletes the container and its children. Overrides RulesContainerPlugin::delete
RulesConditionalContainer::dependencies public function Calculates an array of required modules. Overrides RulesContainerPlugin::dependencies
RulesConditionalContainer::destroy public function Removes circular object references so PHP garbage collector can work. Overrides RulesContainerPlugin::destroy
RulesConditionalContainer::evaluate public function Evaluates the conditional statement. Overrides RulesPlugin::evaluate
RulesConditionalContainer::exportSettings protected function Overrides RulesPlugin::exportSettings
RulesConditionalContainer::label public function Returns the label of the element. Overrides RulesPlugin::label
RulesConditionalContainer::providesVariables public function Provides intersections of variables in all branches, at least one default. Overrides RulesPlugin::providesVariables
RulesConditionalContainer::resetInternalCache public function Resets any internal static caches. Overrides RulesContainerPlugin::resetInternalCache
RulesConditionalContainer::stateVariables protected function Declares only parent state variables for individual branches. Overrides RulesContainerPlugin::stateVariables
RulesConditionalContainer::variableInfoAssertions protected function Asserts no variables (since a conditional is *conditionally* evaluated). Overrides RulesContainerPlugin::variableInfoAssertions
RulesConditionalContainer::__call public function Intercepts calls to magic methods, possibly using reserved keywords. Overrides RulesExtendable::__call
RulesConditionalSwitch::$interceptMethods protected property Intercepts calls to "case" and "defaultCase". Overrides RulesConditionalContainer::$interceptMethods
RulesConditionalSwitch::$itemName protected property The name of the item this class represents in the info hook. Overrides RulesExtendable::$itemName
RulesConditionalSwitch::call_case protected function Adds a "case" statement, for use with magic call.
RulesConditionalSwitch::call_defaultCase protected function Adds a "defaultCase" statement, for use with magic call.
RulesConditionalSwitch::exportChildren protected function Overrides RulesContainerPlugin::exportChildren
RulesConditionalSwitch::importChildren protected function Overrides RulesContainerPlugin::importChildren
RulesConditionalSwitch::pluginParameterInfo public function Returns info about parameters needed by the plugin. Overrides RulesPlugin::pluginParameterInfo
RulesConditionalSwitch::selectBranches protected function Selects the branches to evaluate for this conditional. Overrides RulesConditionalContainer::selectBranches
RulesConditionalSwitch::__construct public function Overrides RulesContainerPlugin::__construct
RulesContainerPlugin::$children protected property
RulesContainerPlugin::access public function Whether the currently logged in user has access to all configured elements. Overrides RulesPlugin::access 1
RulesContainerPlugin::availableVariables public function Returns info about variables available to be used as arguments for this element. Overrides RulesPlugin::availableVariables
RulesContainerPlugin::componentVariables public function Returns the specified variables, in case the plugin is used as component.
RulesContainerPlugin::executeByArgs public function Executes container with the given arguments. Overrides RulesPlugin::executeByArgs 1
RulesContainerPlugin::exportFlat protected function Determines whether the element should be exported in flat style. 1
RulesContainerPlugin::exportToArray protected function Overrides RulesPlugin::exportToArray 1
RulesContainerPlugin::getIterator public function Allows access to the children through the iterator. 1
RulesContainerPlugin::import public function Applies the given export. Overrides RulesPlugin::import 1
RulesContainerPlugin::integrityCheck public function Overrides RulesPlugin::integrityCheck 2
RulesContainerPlugin::optimize public function Overrides optimize(). Overrides RulesPlugin::optimize
RulesContainerPlugin::parameterInfo public function Returns info about parameters needed for executing the configured plugin. Overrides RulesPlugin::parameterInfo
RulesContainerPlugin::setUpVariables protected function Returns info about all variables that have to be setup in the state. Overrides RulesPlugin::setUpVariables
RulesContainerPlugin::sortChildren public function Sorts all child elements by their weight. 1
RulesContainerPlugin::__clone public function By default we do a deep clone. Overrides RulesPlugin::__clone 1
RulesContainerPlugin::__sleep public function Overrides RulesPlugin::__sleep 2
RulesExtendable::$itemInfo protected property
RulesExtendable::facesAs public function
RulesExtendable::forceSetUp public function Forces the object to be setUp, this executes setUp() if not done yet. 1
RulesExtendable::itemFacesAs public static function Returns whether the a RuleExtendable supports the given interface.
RulesExtendable::rebuildCache public function Allows items to add something to the rules cache. 1
RulesExtendable::setUp protected function 1
RulesPlugin::$availableVariables protected property Static cache for availableVariables(). 1
RulesPlugin::$cache protected property Overrides RulesExtendable::$cache
RulesPlugin::$elementId protected property Identifies an element inside a configuration.
RulesPlugin::$hook protected property Overrides RulesExtendable::$hook
RulesPlugin::$id public property If this is a configuration saved to the db, the id of it.
RulesPlugin::$info protected property Info about this element. Usage depends on the plugin. 2
RulesPlugin::$name public property
RulesPlugin::$parent protected property The parent element, if any.
RulesPlugin::$settings public property An array of settings for this element.
RulesPlugin::$weight public property
RulesPlugin::applyDataSelector public function Applies the given data selector.
RulesPlugin::checkParameterSettings protected function Checks whether parameters are correctly configured.
RulesPlugin::checkVarName protected function
RulesPlugin::compare protected static function
RulesPlugin::depth public function Returns the depth of this element in the configuration.
RulesPlugin::elementId public function Returns the element id, which identifies the element inside the config.
RulesPlugin::elementMap public function Gets the element map helper object, which helps mapping elements to ids.
RulesPlugin::elements public function Iterate over all elements nested below the current element.
RulesPlugin::ensureNameExists protected function Ensure the configuration has a name. If not, generate one.
RulesPlugin::entityInfo public function
RulesPlugin::entityType public function
RulesPlugin::execute public function Execute the configuration.
RulesPlugin::export public function Exports a rule configuration.
RulesPlugin::exportParameterSetting protected function
RulesPlugin::form public function Seamlessly invokes the method implemented via faces.
RulesPlugin::form_submit public function
RulesPlugin::form_validate public function
RulesPlugin::getArgument protected function Returns the argument for the parameter $name described with $info.
RulesPlugin::getArgumentInfo public function Returns info about the configured argument.
RulesPlugin::getExecutionArguments protected function Gets the right arguments for executing the element.
RulesPlugin::getPluginName public function Gets the name of this plugin instance. 1
RulesPlugin::hasStatus public function Checks if the configuration has a certain exportable status.
RulesPlugin::identifier public function Returns the config name.
RulesPlugin::importParameterSetting protected function
RulesPlugin::importSettings protected function 1
RulesPlugin::info public function Returns the info of the plugin. 2
RulesPlugin::internalIdentifier public function
RulesPlugin::isRoot public function Returns whether the element is the root of the configuration.
RulesPlugin::parentElement public function Returns the element's parent.
RulesPlugin::plugin public function Returns the name of the element's plugin.
RulesPlugin::pluginInfo public function Returns info about the element's plugin.
RulesPlugin::pluginProvidesVariables public function Returns info about variables 'provided' by the plugin. 2
RulesPlugin::processSettings public function Processes the settings e.g. to prepare input evaluators. 1
RulesPlugin::returnExport protected function Finalizes the configuration export.
RulesPlugin::returnVariables protected function Gets variables to return once the configuration has been executed. 2
RulesPlugin::root public function Gets the root element of the configuration.
RulesPlugin::save public function Saves the configuration to the database. 1
RulesPlugin::setParent public function Sets a new parent element.
RulesPlugin::setUpState public function Sets up the execution state for the given arguments.
RulesPlugin::__toString public function When converted to a string, just use the export format.