You are here

function _webform_analysis_hidden in Webform 6.3

Same name and namespace in other branches
  1. 7.4 components/hidden.inc \_webform_analysis_hidden()
  2. 7.3 components/hidden.inc \_webform_analysis_hidden()

Implements _webform_analysis_component().

File

components/hidden.inc, line 126
Webform module hidden component.

Code

function _webform_analysis_hidden($component, $sids = array()) {
  $placeholders = count($sids) ? array_fill(0, count($sids), "'%s'") : array();
  $sidfilter = count($sids) ? " AND sid in (" . implode(",", $placeholders) . ")" : "";
  $query = 'SELECT data ' . ' FROM {webform_submitted_data} ' . ' WHERE nid = %d ' . ' AND cid = %d ' . $sidfilter;
  $nonblanks = 0;
  $submissions = 0;
  $wordcount = 0;
  $result = db_query($query, array_merge(array(
    $component['nid'],
    $component['cid'],
  ), $sids));
  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;
}