You are here

function theme_webform_results_table in Webform 7.4

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

Theme the results table displaying all the submissions for a particular node.

Parameters

array $variables: An array with keys:

  • node: The node whose results are being displayed.
  • components: An associative array of the components for this webform.
  • submissions: An array of all submissions for this webform.
  • total_count: The total number of submissions to this webform.
  • pager_count: The number of results to be shown per page.

Return value

string HTML string with result data.

1 theme call to theme_webform_results_table()
webform_results_table in includes/webform.report.inc
Create a table containing all submitted values for a webform node.

File

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

Code

function theme_webform_results_table(array $variables) {
  drupal_add_library('webform', 'admin');
  $node = $variables['node'];
  $components = $variables['components'];
  $submissions = $variables['submissions'];
  $total_count = $variables['total_count'];
  $pager_count = $variables['pager_count'];
  $rows = array();
  $cell = array();

  // This header has to be generated separately so we can add the SQL necessary.
  // to sort the results.
  $header = theme('webform_results_table_header', array(
    'node' => $node,
  ));

  // Generate a row for each submission.
  foreach ($submissions as $sid => $submission) {
    $link_text = $submission->is_draft ? t('@serial (draft)', array(
      '@serial' => $submission->serial,
    )) : $submission->serial;
    $cell[] = l($link_text, 'node/' . $node->nid . '/submission/' . $sid);
    $cell[] = format_date($submission->submitted, 'short');
    $cell[] = theme('username', array(
      'account' => $submission,
    ));
    $cell[] = $submission->remote_addr;
    $component_headers = array();

    // Generate a cell for each component.
    foreach ($components as $component) {
      $data = isset($submission->data[$component['cid']]) ? $submission->data[$component['cid']] : NULL;
      $submission_output = webform_component_invoke($component['type'], 'table', $component, $data);
      if ($submission_output !== NULL) {
        $component_headers[] = array(
          'data' => check_plain($component['name']),
          'field' => $component['cid'],
        );
        $cell[] = $submission_output;
      }
    }
    $rows[] = $cell;
    unset($cell);
  }
  if (!empty($component_headers)) {
    $header = array_merge($header, $component_headers);
  }
  if (count($rows) == 0) {
    $rows[] = array(
      array(
        'data' => t('There are no submissions for this form. <a href="!url">View this form</a>.', array(
          '!url' => url('node/' . $node->nid),
        )),
        'colspan' => 4,
      ),
    );
  }
  $output = '';
  $output .= theme('webform_results_per_page', array(
    'total_count' => $total_count,
    'pager_count' => $pager_count,
  ));
  $output .= theme('table', array(
    'header' => $header,
    'rows' => $rows,
  ));
  return $output;
}