You are here

public function ViewsRulesLoop::evaluate in Views Rules 7

Evaluate, whereas by default new vars are visible in the parent's scope.

Overrides RulesActionContainer::evaluate

File

rules/views_rules.plugin.inc, line 62
Views Rules plugin implementations.

Class

ViewsRulesLoop
Loop plugin for using results from a view with Rules displays.

Code

public function evaluate(RulesState $state) {
  try {
    if ($iterator = $this
      ->getViewIterator()) {

      // Prepare view arguments.
      $arguments = array_intersect_key($this
        ->getExecutionArguments($state), $this
        ->pluginParameterInfo());
      $arguments = array_values(rules_unwrap_data($arguments));

      // Execute view.
      $this->viewLoopState = $state;
      try {
        $iterator
          ->execute_iterator($arguments, $this);
      } catch (views_rules_iterator_exception $e) {
        throw new RulesEvaluationException($e
          ->getMessage(), array(), $this);
      }
      unset($this->viewLoopState);
    }
    else {
      throw new RulesEvaluationException('Unable to evaluate invalid view iterator.', array(), $this);
    }
  } catch (RulesEvaluationException $e) {
    rules_log($e->msg, $e->args, $e->severity);
    rules_log('Unable to evaluate %name.', array(
      '%name' => $this
        ->getPluginName(),
    ), RulesLog::WARN, $this);
  }
  $this
    ->resetView();
}