You are here

function _webform_analysis_rows_date in Webform 5

Same name and namespace in other branches
  1. 5.2 components/date.inc \_webform_analysis_rows_date()
  2. 6.2 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

Return value

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

File

components/date.inc, line 224

Code

function _webform_analysis_rows_date($component) {
  $query = 'SELECT no,data ' . ' FROM {webform_submitted_data} ' . ' WHERE nid = %d ' . ' AND  cid = %d ' . ' ORDER BY sid,no ASC ';
  $result = db_query($query, $component['nid'], $component['cid']);

  // build an array of timestamps from entered values.
  $timestamps = array();
  $submissions = 1;
  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 (strlen($month) > 0 && strlen($day) > 0 && 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;
}