You are here

function _webform_analysis_serial in Webform Serial 7

Implements _webform_analysis_component().

File

components/serial.inc, line 125
Webform module serial component.

Code

function _webform_analysis_serial($component, $sids = array(), $single = FALSE) {
  $query = db_select('webform_submitted_data', 'wsd', array(
    'fetch' => PDO::FETCH_ASSOC,
  ))
    ->condition('nid', $component['nid'])
    ->condition('cid', $component['cid'])
    ->condition('data', '', '!=');
  if (count($sids)) {
    $query
      ->condition('sid', $sids, 'IN');
  }

  // Must CAST() to "decimal" because MySQL does not support "integer".
  $query
    ->addExpression('MIN(CAST(data AS decimal))', 'minimum');
  $query
    ->addExpression('MAX(CAST(data AS decimal))', 'maximum');
  $query
    ->addExpression('COUNT(*)', 'count');
  $results = $query
    ->execute()
    ->fetch();
  $rows = array();
  $rows[] = array(
    t('Lowest serial number'),
    $results['minimum'],
  );
  $rows[] = array(
    t('Highest serial number'),
    $results['maximum'],
  );
  $rows[] = array(
    t('Number of submissions with a serial number'),
    $results['count'],
  );
  return array(
    'table_rows' => $rows,
  );
}