You are here

function _webform_analysis_textarea in Webform 7.3

Same name and namespace in other branches
  1. 6.3 components/textarea.inc \_webform_analysis_textarea()
  2. 7.4 components/textarea.inc \_webform_analysis_textarea()

Implements _webform_analysis_component().

File

components/textarea.inc, line 165
Webform module textarea component.

Code

function _webform_analysis_textarea($component, $sids = array()) {
  $query = db_select('webform_submitted_data', 'wsd', array(
    'fetch' => PDO::FETCH_ASSOC,
  ))
    ->fields('wsd', array(
    'no',
    'data',
  ))
    ->condition('nid', $component['nid'])
    ->condition('cid', $component['cid']);
  if (count($sids)) {
    $query
      ->condition('sid', $sids, 'IN');
  }
  $nonblanks = 0;
  $submissions = 0;
  $wordcount = 0;
  $result = $query
    ->execute();
  foreach ($result as $data) {
    if (drupal_strlen(trim($data['data'])) > 0) {
      $nonblanks++;
      $wordcount += str_word_count(trim($data['data']));
    }
    $submissions++;
  }
  $rows[0] = array(
    t('Left Blank'),
    $submissions - $nonblanks,
  );
  $rows[1] = array(
    t('User entered value'),
    $nonblanks,
  );
  $rows[2] = array(
    t('Average submission length in words (ex blanks)'),
    $nonblanks != 0 ? number_format($wordcount / $nonblanks, 2) : '0',
  );
  return $rows;
}