You are here

protected function WebformRulesSubmissionWrapper::setData in Webform Rules 7

Sets the data internally accepting both the data id and object.

Overrides RulesIdentifiableDataWrapper::setData

1 call to WebformRulesSubmissionWrapper::setData()
WebformRulesSubmissionWrapper::__construct in ./webform_rules.rules.inc
Construct a new wrapper object.

File

./webform_rules.rules.inc, line 483
Functions for rules integration.

Class

WebformRulesSubmissionWrapper
Provide entity-like access to webform submission data.

Code

protected function setData($data) {
  parent::setData($data);
  if (!is_array($data)) {
    return;
  }
  $submission = current($data);
  if (!isset($submission->sid)) {
    return;
  }
  $s = webform_get_submissions(array(
    'sid' => $submission->sid,
  ));
  if (empty($s) || !is_array($s)) {
    return;
  }
  $s = current($s);
  $this->id = $s->sid;
  $this->data = $s;
  $webform = node_load($this->data->nid);
  $components = $webform->webform['components'];
  foreach ($s->data as $cid => $val) {
    $c_key = $components[$cid]['form_key'];
    $id = "{$c_key}";
    $this->data->{$id} = array_values($val);
  }
}