function _webform_analysis_rows_file in Webform 5.2
Same name and namespace in other branches
- 5 components/file.inc \_webform_analysis_rows_file()
- 6.2 components/file.inc \_webform_analysis_rows_file()
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/
file.inc, line 472 - Webform module file component.
Code
function _webform_analysis_rows_file($component, $sids = array()) {
$placeholders = count($sids) ? array_fill(0, count($sids), "'%s'") : array();
$sidfilter = count($sids) ? " AND sid in (" . implode(",", $placeholders) . ")" : "";
$query = 'SELECT data ' . ' FROM {webform_submitted_data} ' . ' WHERE nid = %d ' . ' AND cid = %d' . $sidfilter;
$nonblanks = 0;
$sizetotal = 0;
$submissions = 0;
$result = db_query($query, array_merge(array(
$component['nid'],
$component['cid'],
), $sids));
while ($data = db_fetch_array($result)) {
$filedata = unserialize($data['data']);
if (isset($filedata['filesize'])) {
$nonblanks++;
$sizetotal += $filedata['filesize'];
}
$submissions++;
}
$rows[0] = array(
t('Left Blank'),
$submissions - $nonblanks,
);
$rows[1] = array(
t('User uploaded file'),
$nonblanks,
);
$rows[2] = array(
t('Average uploaded file size'),
$sizetotal != 0 ? (int) ($sizetotal / $nonblanks / 1024) . ' KB' : '0',
);
return $rows;
}