You are here

function _webform_analysis_multifile in Webform Multiple File Upload 7

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

Implementation of _webform_analysis_component().

File

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

Code

function _webform_analysis_multifile($component, $sids = array()) {
  $q = db_select('webform_submitted_data', 'wsd')
    ->fields('wsd', array(
    'data',
  ))
    ->condition('nid', $component['nid'])
    ->condition('cid', $component['cid']);
  if (!empty($sids)) {
    $q
      ->condition('sid', $sids);
  }
  $result = $q
    ->execute();
  $nonblanks = 0;
  $sizetotal = 0;
  $submissions = 0;
  $numfiles = 0;
  while ($data = $result
    ->fetchAssoc()) {
    if ($fids = drupal_json_decode($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'),
    $nonblanks == 0 ? 0 : $numfiles / $nonblanks,
  );
  $rows[3] = array(
    t('Average uploaded file size'),
    $sizetotal != 0 && $numfiles != 0 ? (int) ($sizetotal / $numfiles / 1024) . ' KB' : '0',
  );
  return $rows;
}