views_rules.action.inc in Views Rules 7
File
rules/views_rules.action.inc
View source
<?php
function views_rules_collect_rows($view_display_id) {
if (!($view = views_rules_get_view($view_display_id))) {
return array();
}
$iterator = $view->display_handler;
$args = func_get_args();
array_shift($args);
$collector = new ViewsRulesResultCollector(array_keys($iterator
->get_rules_variable_info()));
$iterator
->execute_iterator($args, $collector);
$data = $collector
->getData();
return $data;
}
function views_rules_collect_rows_info_alter(&$info, RulesAbstractPlugin $element) {
if (!empty($element->settings['views_rules_display']) && ($view = views_rules_get_view($element->settings['views_rules_display']))) {
if (!$view
->validate()) {
return;
}
$iterator = $view->display_handler;
if (!$iterator instanceof views_rules_iterator) {
return;
}
foreach ($iterator
->get_rules_parameter_info() as $var_name => $var_info) {
$info['parameter'][$var_name] = $var_info;
}
foreach ($iterator
->get_rules_variable_info() as $var_name => $var_info) {
$type = $var_info['type'];
$label = $var_info['label'];
$info['provides'][$var_name] = array(
'type' => "list<{$type}>",
'label' => t('List of @label', array(
'@label' => $label,
)),
) + $var_info;
}
}
}
function views_rules_collect_rows_validate(RulesPlugin $element) {
$view_display_id = $element->settings['views_rules_display'];
$view = views_rules_get_view($view_display_id);
if (!$view || !$view->display_handler) {
throw new RulesIntegrityException(t('The view display %display does not exist.', array(
'%display' => $view_display_id,
)), $element);
}
if (!$view->display_handler instanceof views_rules_iterator) {
throw new RulesIntegrityException(t('The view display %display is not a Rules display.', array(
'%display' => $view_display_id,
)), $element);
}
if (!$view
->validate()) {
throw new RulesIntegrityException(t('The view display %display does not validate.', array(
'%display' => $view_display_id,
)), $element);
}
}
class ViewsRulesResultCollector implements ViewsRulesIterable {
protected $variables;
protected $data = array();
public function __construct(array $variables) {
$this->variables = $variables;
foreach ($this->variables as $variable) {
$this->data[$variable] = array();
}
}
public function evaluateRow(array $data) {
foreach ($this->variables as $variable) {
$this->data[$variable][] = isset($data[$variable]) ? $data[$variable] : NULL;
}
}
public function getData() {
return $this->data;
}
}