function _webform_analysis_optionsmarkup in Webform Options Markup 7
Same name and namespace in other branches
- 7.2 components/webform_optionsmarkup.inc \_webform_analysis_optionsmarkup()
Implements _webform_analysis_component().
File
- components/
webform_optionsmarkup.inc, line 410 - Webform component that allows markup in checkbox and radio options.
Code
function _webform_analysis_optionsmarkup($component, $sids = array(), $single = FALSE) {
$options = _webform_optionsmarkup_options($component, TRUE);
$show_other_results = $single;
$option_operator = $show_other_results ? 'NOT IN' : 'IN';
$query = db_select('webform_submitted_data', 'wsd', array(
'fetch' => PDO::FETCH_ASSOC,
))
->fields('wsd', array(
'data',
))
->condition('nid', $component['nid'])
->condition('cid', $component['cid'])
->condition('data', '', '<>')
->condition('data', array_keys($options), $option_operator)
->groupBy('data');
$query
->addExpression('COUNT(data)', 'datacount');
if (count($sids)) {
$query
->condition('sid', $sids, 'IN');
}
$count_query = db_select('webform_submitted_data', 'wsd', array(
'fetch' => PDO::FETCH_ASSOC,
))
->condition('nid', $component['nid'])
->condition('cid', $component['cid'])
->condition('data', '', '<>');
$count_query
->addExpression('COUNT(*)', 'datacount');
if (count($sids)) {
$count_query
->condition('sid', $sids, 'IN');
}
$result = $query
->execute();
$rows = array();
$normal_count = 0;
foreach ($result as $data) {
$display_option = $single ? $data['data'] : $options[$data['data']]['title'];
$rows[$data['data']] = array(
_webform_filter_xss($display_option),
$data['datacount'],
);
$normal_count += $data['datacount'];
}
if (!$show_other_results) {
// Order the results according to the normal options array.
$ordered_rows = array();
foreach (array_intersect_key($options, $rows) as $key => $label) {
$ordered_rows[] = $rows[$key];
}
$rows = $ordered_rows;
}
return $rows;
}