You are here

function webform_results_submissions in Webform 6.3

Same name and namespace in other branches
  1. 5.2 webform_report.inc \webform_results_submissions()
  2. 6.2 webform_report.inc \webform_results_submissions()
  3. 7.4 includes/webform.report.inc \webform_results_submissions()
  4. 7.3 includes/webform.report.inc \webform_results_submissions()

Retrieve lists of submissions for a given webform.

1 string reference to 'webform_results_submissions'
webform_menu in ./webform.module
Implements hook_menu().

File

includes/webform.report.inc, line 16
This file includes helper functions for creating reports for webform.module

Code

function webform_results_submissions($node, $user_filter, $pager_count) {
  global $user;
  if (isset($_GET['results']) && is_numeric($_GET['results'])) {
    $pager_count = $_GET['results'];
  }
  $header = theme('webform_results_submissions_header', $node);
  if ($user_filter) {
    if ($user->uid) {
      drupal_set_title(t('Submissions for %user', array(
        '%user' => $user->name,
      )));
    }
    else {
      drupal_set_title(t('Your submissions'));
      webform_disable_page_cache();
    }
    webform_set_breadcrumb($node);
    $submissions = webform_get_submissions(array(
      'nid' => $node->nid,
      'uid' => $user->uid,
    ), $header, $pager_count);
    $count = webform_get_submission_count($node->nid, $user->uid);
  }
  else {
    $submissions = webform_get_submissions($node->nid, $header, $pager_count);
    $count = webform_get_submission_count($node->nid);
  }
  $operation_column = end($header);
  $operation_total = $operation_column['colspan'];
  $rows = array();
  foreach ($submissions as $sid => $submission) {
    $row = array(
      $submission->is_draft ? t('@sid (draft)', array(
        '@sid' => $sid,
      )) : $sid,
      format_date($submission->submitted, 'small'),
    );
    if (webform_results_access($node, $user)) {
      $row[] = theme('username', $submission);
      $row[] = $submission->remote_addr;
    }
    $row[] = l(t('View'), "node/{$node->nid}/submission/{$sid}");
    $operation_count = 1;

    // No need to call this multiple times, just reference this in a variable.
    $destination = drupal_get_destination();
    if (webform_submission_access($node, $submission, 'edit', $user)) {
      $row[] = l(t('Edit'), "node/{$node->nid}/submission/{$sid}/edit", array(
        'query' => $destination,
      ));
      $operation_count++;
    }
    if (webform_submission_access($node, $submission, 'delete', $user)) {
      $row[] = l(t('Delete'), "node/{$node->nid}/submission/{$sid}/delete", array(
        'query' => $destination,
      ));
      $operation_count++;
    }
    if ($operation_count < $operation_total) {
      $row[count($row) - 1] = array(
        'data' => $row[count($row) - 1],
        'colspan' => $operation_total - $operation_count + 1,
      );
    }
    $rows[] = $row;
  }
  $element['#theme'] = 'webform_results_submissions';
  $element['#node'] = $node;
  $element['#submissions'] = $submissions;
  $element['#total_count'] = $count;
  $element['#pager_count'] = $pager_count;
  $element['table']['#theme'] = 'table';
  $element['table']['#header'] = $header;
  $element['table']['#rows'] = $rows;
  $element['table']['#operation_total'] = $operation_total;
  return drupal_render($element);
}