function _webform_analysis_rows_time in Webform 6.2
Same name and namespace in other branches
- 5.2 components/time.inc \_webform_analysis_rows_time()
- 5 components/time.inc \_webform_analysis_rows_time()
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/
time.inc, line 281 - Webform module time component.
Code
function _webform_analysis_rows_time($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++;
$hour = $row['data'];
if ($row = db_fetch_array($result)) {
if ($row['no'] == '1') {
$minute = $row['data'];
if ($row = db_fetch_array($result)) {
if ($row['no'] == '2') {
$ampm = $row['data'];
// Build the full timestamp.
if (drupal_strlen($hour) > 0 && drupal_strlen($minute) > 0) {
$timestamps[] = strtotime($hour . ':' . $minute . ' ' . $ampm);
}
}
else {
// Build military time.
$timestamps[] = strtotime($hour . ':' . $minute);
}
}
}
}
}
}
// 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;
}