You are here

abstract class RulesListConditionsConditionalLoop in Rules List Conditions 7

Base class for condition loops.

Hierarchy

Expanded class hierarchy of RulesListConditionsConditionalLoop

1 string reference to 'RulesListConditionsConditionalLoop'
rules_list_conditions.plugins.inc in includes/rules_list_conditions.plugins.inc

File

includes/rules_list_conditions.core.inc, line 11
Contains the base class for condition loops.

View source
abstract class RulesListConditionsConditionalLoop extends RulesConditionContainer {
  protected $listItemInfo;

  /**
   * {@inheritdoc}
   */
  public function __construct($settings = array(), $variables = NULL) {
    parent::__construct();
    $this->settings = (array) $settings + array(
      'item:var' => t('list_item'),
      'item:label' => t('Current list item'),
    );
    if (!empty($variables)) {
      $this->info['variables'] = $variables;
    }
  }

  /**
   * {@inheritdoc}
   */
  public function pluginParameterInfo() {
    return array(
      'list' => array(
        'type' => 'list',
        'restriction' => 'selector',
        'label' => t('List'),
        'description' => t('The list to loop over. The loop will check against each item in the list.'),
      ),
    );
  }

  /**
   * {@inheritdoc}
   */
  public function dependencies() {
    $dependencies = parent::dependencies();
    $dependencies[] = 'rules_list_conditions';
    return $dependencies;
  }

  /**
   * {@inheritdoc}
   */
  public function integrityCheck() {
    parent::integrityCheck();
    $this
      ->checkVarName($this->settings['item:var']);
  }

  /**
   * {@inheritdoc}
   */
  protected function exportSettings() {
    $export = parent::exportSettings();
    $export['ITEM'][$this->settings['item:var']] = $this->settings['item:label'];
    return $export;
  }

  /**
   * {@inheritdoc}
   */
  protected function importSettings($export) {
    parent::importSettings($export);
    if (isset($export['ITEM'])) {
      $this->settings['item:var'] = rules_array_key($export['ITEM']);
      $this->settings['item:label'] = reset($export['ITEM']);
    }
  }

  /**
   * {@inheritdoc}
   */
  protected function importChildren($export, $key = NULL) {

    // Up to children to set $key.
    if (!isset($export[$key]) && isset($export['NOT ' . $key])) {
      $this->negate = TRUE;
      $key = 'NOT ' . $key;
    }
    parent::importChildren($export, $key);
  }

  /**
   * Return information about the list being iterated over.
   *
   * @return array
   *   An associate array containing
   *     'type': The type of the list's elements (or unknown if not set).
   *     'label': The human readable label, if set.
   */
  public function listItemInfo() {
    if (!isset($this->listItemInfo)) {
      if ($info = $this
        ->getArgumentInfo('list')) {

        // Pass through the variable info keys like property info.
        $iks = array_flip(array(
          'type',
          'property info',
          'bundle',
        ));
        $this->listItemInfo = array_intersect_key($info, $iks);
        $this->listItemInfo['type'] = isset($info['type']) ? entity_property_list_extract_type($info['type']) : 'unknown';
      }
      else {
        $this->listItemInfo = array(
          'type' => 'unknown',
        );
      }
      $this->listItemInfo['label'] = $this->settings['item:label'];
    }
    return $this->listItemInfo;
  }

  /**
   * {@inheritdoc}
   */
  protected function stateVariables($element = NULL) {
    return array(
      $this->settings['item:var'] => $this
        ->listItemInfo(),
    ) + parent::stateVariables($element);
  }

  /**
   * Internal helper for child loops to log exceptions.
   */
  protected function logExn($e) {
    rules_log($e->msg, $e->args, $e->severity);
    rules_log('Unable to evaluate %name.', array(
      '%name' => $this
        ->getPluginName(),
    ), RulesLog::WARN, $this);
  }

  /**
   * Internal helper for child loops to set current item in loop body.
   * @return RulesState
   *   A copy of the rules execution context with the loop variable for
   *   the current item in the list being iterated over.
   */
  protected function setListVar($state, $item) {
    $local = clone $state;
    $info = $this
      ->listItemInfo();
    $name = $this->settings['item:var'];
    $local
      ->addVariable($name, $item, $info);
    return $local;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RulesConditionContainer::$negate protected property
RulesConditionContainer::condition public function Adds a condition to the container.
RulesConditionContainer::exportChildren protected function Overrides RulesContainerPlugin::exportChildren
RulesConditionContainer::isNegated public function Returns whether the element is configured to negate the result. Overrides RulesConditionInterface::isNegated
RulesConditionContainer::negate public function Negate this condition. Overrides RulesConditionInterface::negate
RulesConditionContainer::returnVariables protected function Just return the condition container's result. Overrides RulesPlugin::returnVariables
RulesConditionContainer::__sleep public function Overrides RulesContainerPlugin::__sleep
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::delete public function Overrides delete to keep the children alive, if possible. Overrides RulesPlugin::delete 1
RulesContainerPlugin::destroy public function Removes circular object references so PHP garbage collector can work. Overrides RulesPlugin::destroy 1
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::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::resetInternalCache public function Resets any internal static caches. Overrides RulesPlugin::resetInternalCache 1
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::variableInfoAssertions protected function Returns asserted additions to the available variable info. Overrides RulesPlugin::variableInfoAssertions 1
RulesContainerPlugin::__clone public function By default we do a deep clone. Overrides RulesPlugin::__clone 1
RulesExtendable::$itemInfo protected property
RulesExtendable::$itemName protected property The name of the item this class represents in the info hook. 9
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
RulesExtendable::__call public function Magic method: Invoke the dynamically implemented methods.
RulesListConditionsConditionalLoop::$listItemInfo protected property
RulesListConditionsConditionalLoop::dependencies public function Calculates an array of required modules. Overrides RulesContainerPlugin::dependencies
RulesListConditionsConditionalLoop::exportSettings protected function Overrides RulesPlugin::exportSettings
RulesListConditionsConditionalLoop::importChildren protected function Overrides RulesConditionContainer::importChildren
RulesListConditionsConditionalLoop::importSettings protected function Overrides RulesPlugin::importSettings
RulesListConditionsConditionalLoop::integrityCheck public function Makes sure the plugin is configured right. Overrides RulesContainerPlugin::integrityCheck
RulesListConditionsConditionalLoop::listItemInfo public function Return information about the list being iterated over.
RulesListConditionsConditionalLoop::logExn protected function Internal helper for child loops to log exceptions.
RulesListConditionsConditionalLoop::pluginParameterInfo public function Returns info about parameters needed by the plugin. Overrides RulesPlugin::pluginParameterInfo
RulesListConditionsConditionalLoop::setListVar protected function Internal helper for child loops to set current item in loop body.
RulesListConditionsConditionalLoop::stateVariables protected function Overridden to exclude variable assertions of negated conditions. Overrides RulesConditionContainer::stateVariables
RulesListConditionsConditionalLoop::__construct public function Overrides RulesContainerPlugin::__construct 2
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::evaluate abstract public function Evaluate the element on a given rules evaluation state. 5
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::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::label public function Returns the label of the element. 4
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::providesVariables public function Returns info about all variables provided for later evaluated elements. 2
RulesPlugin::returnExport protected function Finalizes the configuration export.
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.