function _webform_analysis_grid in Webform 7.3
Same name and namespace in other branches
- 6.3 components/grid.inc \_webform_analysis_grid()
- 7.4 components/grid.inc \_webform_analysis_grid()
Implements _webform_analysis_component().
File
- components/
grid.inc, line 295 - Webform module grid component.
Code
function _webform_analysis_grid($component, $sids = array()) {
// Generate the list of options and questions.
$options = _webform_select_options_from_text($component['extra']['options'], TRUE);
$questions = _webform_select_options_from_text($component['extra']['questions'], TRUE);
// Generate a lookup table of results.
$query = db_select('webform_submitted_data', 'wsd')
->fields('wsd', array(
'no',
'data',
))
->condition('nid', $component['nid'])
->condition('cid', $component['cid'])
->condition('data', '', '<>')
->groupBy('no')
->groupBy('data');
$query
->addExpression('COUNT(sid)', 'datacount');
if (count($sids)) {
$query
->condition('sid', $sids, 'IN');
}
$result = $query
->execute();
$counts = array();
foreach ($result as $data) {
$counts[$data->no][$data->data] = $data->datacount;
}
// Create an entire table to be put into the returned row.
$rows = array();
$header = array(
'',
);
// Add options as a header row.
foreach ($options as $option) {
$header[] = _webform_filter_xss($option);
}
// Add questions as each row.
foreach ($questions as $qkey => $question) {
$row = array(
_webform_filter_xss($question),
);
foreach ($options as $okey => $option) {
$row[] = !empty($counts[$qkey][$okey]) ? $counts[$qkey][$okey] : 0;
}
$rows[] = $row;
}
$output = theme('table', array(
'header' => $header,
'rows' => $rows,
'attributes' => array(
'class' => array(
'webform-grid',
),
),
));
return array(
array(
array(
'data' => $output,
'colspan' => 2,
),
),
);
}