You are here

function _webform_analysis_rows_hidden in Webform 5

Same name and namespace in other branches
  1. 5.2 components/hidden.inc \_webform_analysis_rows_hidden()
  2. 6.2 components/hidden.inc \_webform_analysis_rows_hidden()

Calculate and returns statistics about results for this component from all submission to this webform. The output of this function will be displayed under the "results" tab then "analysis".

Parameters

$component: An array of information describing the component, directly correlating to the webform_component database schema

Return value

An array of data rows, each containing a statistic for this component's submissions.

File

components/hidden.inc, line 92

Code

function _webform_analysis_rows_hidden($component) {
  $query = 'SELECT data ' . ' FROM {webform_submitted_data} ' . ' WHERE nid = %d ' . ' AND cid = %d';
  $nonblanks = 0;
  $submissions = 0;
  $wordcount = 0;
  $result = db_query($query, $component['nid'], $component['cid']);
  while ($data = db_fetch_array($result)) {
    if (strlen(trim($data['data'])) > 0) {
      $nonblanks++;
      $wordcount += str_word_count(trim($data['data']));
    }
    $submissions++;
  }
  $rows[0] = array(
    t('Empty'),
    $submissions - $nonblanks,
  );
  $rows[1] = array(
    t('Non-empty'),
    $nonblanks,
  );
  $rows[2] = array(
    t('Average submission length in words (ex blanks)'),
    $nonblanks != 0 ? number_format($wordcount / $nonblanks, 2) : '0',
  );
  return $rows;
}