You are here

function webform_service_submission_update in Webform Service 7.4

Same name and namespace in other branches
  1. 6.3 resources/submission_resource.inc \webform_service_submission_update()

Updates a webform submission based on submitted values.

Note that this function uses drupal_execute() to create new nodes, which may require very specific formatting. The full implications of this are beyond the scope of this comment block. The Googles are your friend.

Parameters

$uuid: UUID of the webform we're editing.

$sid: Submission ID of the submission we are editing.

$submission: Array representing the submission.

Return value

The submission object.

See also

drupal_execute()

1 string reference to 'webform_service_submission_update'
_submission_resource_definition in resources/submission_resource.inc
The submission resource definition.

File

resources/submission_resource.inc, line 144

Code

function webform_service_submission_update($uuid, $submission) {

  // Get the webform entity.
  $webform = webform_submission_uuid_webform($uuid);
  $current_submission = webform_submission_uuid_submission($uuid);

  // If the entity exists.
  if ($webform && $current_submission) {
    foreach ($current_submission as $key => $value) {
      if ($key == 'data') {
        foreach ($value as $cid => $data) {
          if (!isset($submission['data'][$cid])) {
            $submission['data'][$cid] = array(
              'values' => $data,
            );
          }
        }
      }
      else {
        $submission[$key] = $value;
      }
    }

    // If there is a current submission id, we must be updating a submission, so
    // add it to the submission.
    if (!isset($submission['submission']['sid']) && isset($current_submission->sid)) {
      $submission['submission']['sid'] = $current_submission->sid;
    }
    module_load_include('inc', 'webform', 'includes/webform.submissions');
    $parsed = webform_service_parse_submission($webform, $submission);
    $sid = webform_submission_update($webform, $parsed);
    return webform_service_get_submission($webform, webform_get_submission($webform->nid, $sid, TRUE));
  }
  else {
    return FALSE;
  }
}