You are here

function _webform_analysis_file in Webform 6.3

Same name and namespace in other branches
  1. 7.4 components/file.inc \_webform_analysis_file()
  2. 7.3 components/file.inc \_webform_analysis_file()

Implements _webform_analysis_component().

File

components/file.inc, line 525
Webform module file component.

Code

function _webform_analysis_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)) {
    $file = webform_get_file($data['data']);
    if (isset($file->filesize)) {
      $nonblanks++;
      $sizetotal += $file->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;
}