You are here

function webform_service_get_submission in Webform Service 7.4

Same name and namespace in other branches
  1. 6.3 webform_service.module \webform_service_get_submission()

Returns a single submission resource.

Parameters

object The webform node object.:

array The submission array.:

4 calls to webform_service_get_submission()
webform_service_get_submission_by_uuid in ./webform_service.module
Returns a single submission provided the uuid.
webform_service_submission_create in resources/submission_resource.inc
Creates a new submission within a webform.
webform_service_submission_index in ./webform_service.module
Retrieve all submissions for a webform.
webform_service_submission_update in resources/submission_resource.inc
Updates a webform submission based on submitted values.

File

./webform_service.module, line 288

Code

function webform_service_get_submission($webform, $submission) {
  $return = array();

  // If the webform and submission exist.
  if ($webform && $submission) {

    // Get the components and establish the values.
    $components = webform_service_get_components($webform->webform);

    // Get the submitted values from this submission.
    $values = array();
    foreach ($components as $cid => $component) {
      $values[$cid] = array(
        'form_key' => $component['form_key'],
        'cid' => $component['cid'],
        'type' => $component['type'],
      );
      if (isset($submission->data[$component['cid']])) {
        $values[$cid]['values'] = $submission->data[$component['cid']];
      }
    }

    // Load the user account.
    $account = user_load($submission->uid);
    $submissionHasUuid = isset($submission->uuid);

    // The return for this submission.
    $return = array(
      'sid' => $submission->sid,
      'uuid' => $submissionHasUuid ? $submission->uuid : NULL,
      'uri' => $submissionHasUuid ? services_resource_uri(array(
        'submission',
        $submission->uuid,
      )) : NULL,
      'webform' => services_resource_uri(array(
        'webform',
        $webform->uuid,
      )),
      'user' => $account->uuid,
      'submitted' => $submission->submitted,
      'data' => $values,
    );
  }
  return $return;
}