You are here

function _webform_analysis_rows_date in Webform 6.2

Same name and namespace in other branches
  1. 5.2 components/date.inc \_webform_analysis_rows_date()
  2. 5 components/date.inc \_webform_analysis_rows_date()

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

$sids: An optional array of submission IDs (sid). If supplied, the analysis will be limited to these sids.

Return value

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

File

components/date.inc, line 340
Webform module date component.

Code

function _webform_analysis_rows_date($component, $sids = array()) {
  $placeholders = count($sids) ? array_fill(0, count($sids), "'%s'") : array();
  $sidfilter = count($sids) ? " AND sid in (" . implode(",", $placeholders) . ")" : "";
  $query = 'SELECT no,data ' . ' FROM {webform_submitted_data} ' . ' WHERE nid = %d ' . ' AND  cid = %d ' . $sidfilter . ' ORDER BY sid,no ASC ';
  $result = db_query($query, array_merge(array(
    $component['nid'],
    $component['cid'],
  ), $sids));

  // build an array of timestamps from entered values.
  $timestamps = array();
  $submissions = 0;
  while ($row = db_fetch_array($result)) {
    if ($row['no'] == '0') {
      $submissions++;
      $month = $row['data'];
      if ($row = db_fetch_array($result)) {
        if ($row['no'] == '1') {
          $day = $row['data'];
          if ($row = db_fetch_array($result)) {
            if ($row['no'] == '2') {
              $year = $row['data'];

              // Build the full timestamp.
              if (drupal_strlen($month) > 0 && drupal_strlen($day) > 0 && drupal_strlen($year) > 0) {
                $timestamp = strtotime($month . '/' . $day . '/' . $year);

                // Add usefull information about this date into an array.
                $timestamps[$timestamp] = array(
                  date('l', $timestamp),
                  // Day of the week (Monday, Tuesday, etc.).
                  date('F', $timestamp),
                  // Full Month name (January, February, etc.).
                  $year,
                  // Year.
                  $day,
                );
              }
            }
          }
        }
      }
    }
  }

  // Display stats.
  // TODO: display date statistics in javascript tabs.
  $nonblanks = count($timestamps);
  $rows[0] = array(
    t('Left Blank'),
    $submissions - $nonblanks,
  );
  $rows[1] = array(
    t('User entered value'),
    $nonblanks,
  );
  return $rows;
}