You are here

function _webform_analysis_addressfield in Addressfield Tokens 7

Calculate and returns statistics about results for this component.

This takes into account all submissions to this webform. The output of this function will be displayed under the "Results" tab then "Analysis".

Parameters

mixed $component: An array of information describing the component, directly correlating to the webform_component database schema.

mixed $sids: An optional array of submission IDs (sid). If supplied, the analysis will be limited to these sids.

bool $single: Boolean flag determining if the details about a single component are being shown. May be used to provided detailed information about a single component's analysis, such as showing "Other" options within a select list.

Return value

array An array of data rows, each containing a statistic for this component's submissions.

File

./addressfield_tokens.components.inc, line 332
Webform Component information for an address field type.

Code

function _webform_analysis_addressfield($component, $sids = array(), $single = FALSE) {

  // @todo Update this function
  // Generate the list of options and questions.
  $query = db_select('webform_submitted_data', 'wsd')
    ->fields('wsd', array(
    'data',
  ))
    ->condition('nid', $component['nid'])
    ->condition('cid', $component['cid']);
  if (count($sids)) {
    $query
      ->condition('sid', $sids, 'IN');
  }
  $non_blanks = 0;
  $submissions = 0;
  $results = $query
    ->execute();
  foreach ($results as $row) {
    if (drupal_strlen(trim($row->data)) > 0) {
      $non_blanks++;
    }
    $submissions++;
  }
  $rows[0] = array(
    t('Left Blank'),
    $submissions - $non_blanks,
  );
  $rows[1] = array(
    t('User entered value'),
    $non_blanks,
  );
  return array(
    'table_rows' => $rows,
  );
}