You are here

function _webform_analysis_multifile in Webform Multiple File Upload 6

Same name and namespace in other branches
  1. 7 multifile.inc \_webform_analysis_multifile()

Implementation of _webform_analysis_component().

File

./multifile.inc, line 623
Webform module file component.

Code

function _webform_analysis_multifile($component, $sids = array()) {
  module_load_include('inc', 'webform_multifile', 'safe_unserialize');
  $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));
  $numfiles = 0;
  while ($data = db_fetch_array($result)) {
    if ($fids = safe_unserialize($data['data'])) {
      $counter = 0;
      foreach (webform_get_multifile($fids) as $file) {
        if (isset($file->filesize)) {
          $counter++;
          $sizetotal += $file->filesize;
        }
      }
      if ($counter) {
        $numfiles += $counter;
        $nonblanks++;
      }
      $submissions++;
    }
  }
  $rows[0] = array(
    t('Left Blank'),
    $submissions - $nonblanks,
  );
  $rows[1] = array(
    t('User uploaded file'),
    $nonblanks,
  );
  $rows[2] = array(
    t('Average uploaded files'),
    $numfiles / $nonblanks,
  );
  $rows[3] = array(
    t('Average uploaded file size'),
    $sizetotal != 0 ? (int) ($sizetotal / $numfiles / 1024) . ' KB' : '0',
  );
  return $rows;
}