You are here

webform_submission_uuid.module in Webform Submission UUID 7

Same filename and directory in other branches
  1. 6.4 webform_submission_uuid.module
  2. 7.4 webform_submission_uuid.module

File

webform_submission_uuid.module
View source
<?php

/**
 * Implementation of hook_uuid_sync
 */
function webform_submission_uuid_uuid_sync() {

  // Update the webform_submissions table with missing UUID's
  _uuid_sync_table('webform_submissions', 'sid', 'uuid');
}

/**
 * Implementation of hook_webform_submission_presave
 */
function webform_submission_uuid_webform_submission_presave($node, $submission) {
  if (empty($submission->uuid)) {
    $submission->uuid = uuid_generate();
  }
}

/**
 * Get's the webform submission entry provided a uuid.
 *
 * @param string $uuid
 * @param bool $reset
 * @return array
 *   An array of submissions stubs (having only the nid and sid attributes)
 *   keyed by UUID. An empty array is returned if no matching submission is
 *   found.
 */
function webform_submission_uuid_entry($uuid, $reset = FALSE) {

  // Get the submissions from static cache.
  $submissions =& drupal_static(__FUNCTION__);

  // See if we need to reset or if it is statically cached.
  if ($reset || empty($submissions[$uuid])) {

    // Get the nid and sid for this uuid.
    $result = db_select('webform_submissions', 's')
      ->fields('s', array(
      'sid',
      'nid',
    ))
      ->condition('s.uuid', $uuid)
      ->execute();

    // Make sure we have a result.
    if ($row = $result
      ->fetchObject()) {

      // Add the result to the static cache.
      $submissions[$uuid] = $row;
    }
  }

  // Return the submission.
  return !empty($submissions[$uuid]) ? $submissions[$uuid] : array();
}

/**
 * Loads a webform submission provided the UUID.
 */
function webform_submission_uuid_submission($uuid, $reset = FALSE) {

  // Get the submission entry.
  if ($submission = webform_submission_uuid_entry($uuid, $reset)) {

    // Translate this to a webform submission.
    module_load_include('inc', 'webform', 'includes/webform.submissions');
    $submission = webform_get_submission($submission->nid, $submission->sid, $reset);
  }

  // Return the submission.
  return $submission;
}

/**
 * Loads a webform provided the UUID of the submission.
 */
function webform_submission_uuid_webform($uuid, $reset = FALSE) {
  $webform = null;

  // Get the submission entry.
  if ($submission = webform_submission_uuid_entry($uuid, $reset)) {

    // Translate this to a webform node.
    $webform = node_load($submission->nid, NULL, $reset);
  }

  // Return the webform node.
  return $webform;
}

Functions

Namesort descending Description
webform_submission_uuid_entry Get's the webform submission entry provided a uuid.
webform_submission_uuid_submission Loads a webform submission provided the UUID.
webform_submission_uuid_uuid_sync Implementation of hook_uuid_sync
webform_submission_uuid_webform Loads a webform provided the UUID of the submission.
webform_submission_uuid_webform_submission_presave Implementation of hook_webform_submission_presave