You are here

function webform_workflow_get_notify_users in Webform Workflow 7

Get a list of user accounts to notify when the submission changes state.

Parameters

object $submission: The webform submission.

Return value

array An array of user accounts, keyed by UID. The anonymous user will never be included in this list.

1 call to webform_workflow_get_notify_users()
webform_workflow_notify_users in ./webform_workflow.module
Notify users of a state transition by e-mail.

File

./webform_workflow.module, line 712
A simple workflow module for webforms.

Code

function webform_workflow_get_notify_users($submission) {
  $cache = drupal_static(__FUNCTION__, array());
  $state = webform_workflow_state_load_by_submission($submission);
  if (!$state) {
    return array();
  }
  $cache_key = $submission->sid . ':' . $state->wsid;
  if (isset($cache[$cache_key])) {
    return $cache[$cache_key];
  }
  $state_wrapper = entity_metadata_wrapper('webform_workflow_state', $state);
  $uids = array();

  // Add any users configured to be notified in the entity reference field
  // 'ww_state_notify_users'.
  if (!empty($state_wrapper->ww_state_notify_users)) {
    foreach ($state_wrapper->ww_state_notify_users as $account_wrapper) {
      $uid = $account_wrapper->uid
        ->value();
      if ($uid) {
        $uids[$uid] = $uid;
      }
    }
  }

  // Add the original submitter, depending on the Boolean field
  // ww_state_notify_os.
  if ($submission->uid && isset($state_wrapper->ww_state_notify_os) && $state_wrapper->ww_state_notify_os
    ->value()) {
    $uids[$submission->uid] = $submission->uid;
  }

  // Allow other modules to alter the list of users.
  drupal_alter('webform_workflow_notify_users', $uids, $submission, $state);
  $cache[$cache_key] = $uids;
  return user_load_multiple($uids);
}