Skip to content

Commit 9c6aff8

Browse files
committed
2.0.6; closes #10
1 parent 818e02a commit 9c6aff8

File tree

2 files changed

+42
-35
lines changed

2 files changed

+42
-35
lines changed

code/FieldCharts.class.php

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -172,38 +172,11 @@ public static function getFieldChartInfo($form_id, $view_id, $field_id, $ignore_
172172
$form_field = Fields::getFormField($field_id, array("include_field_settings" => true));
173173
$field_type_info = FieldTypes::getFieldType($form_field["field_type_id"]);
174174

175-
if (!empty($field_type_info["raw_field_type_map_multi_select_id"])) {
176-
$option_list_setting_id = $field_type_info["raw_field_type_map_multi_select_id"];
177-
$option_list_id = (isset($form_field["settings"][$option_list_setting_id])) ? $form_field["settings"][$option_list_setting_id] : "";
178-
179-
if (!empty($option_list_id)) {
180-
$option_list = OptionLists::getOptionListOptions($option_list_id);
181-
$map = array();
182-
foreach ($option_list as $grouped) {
183-
if (!is_array($grouped["options"])) {
184-
continue;
185-
}
186-
187-
foreach ($grouped["options"] as $option) {
188-
$map[$option["option_value"]] = $option["option_name"];
189-
}
190-
}
191-
192-
$updated_results = array();
193-
while (list($val, $name) = each($map)) {
194-
foreach ($results as $result) {
195-
if ($val == $result["label"]) {
196-
$updated_results[] = array(
197-
"label" => $map[$result["label"]],
198-
"data" => $result["data"]
199-
);
200-
break;
201-
}
202-
}
203-
}
204-
205-
$results = $updated_results;
206-
}
175+
// radios, checkboxes, select + multi-select are handled separately: we need to look at the option list & get the
176+
// display values
177+
$raw_field_type_map_multi_select_id = $field_type_info["raw_field_type_map_multi_select_id"];
178+
if (!empty($raw_field_type_map_multi_select_id) && isset($form_field["settings"][$raw_field_type_map_multi_select_id])) {
179+
$results = self::parseMultiSelectData($form_field["settings"][$raw_field_type_map_multi_select_id], $results);
207180
}
208181

209182
$now = CoreGeneral::getCurrentDatetime();
@@ -369,4 +342,38 @@ public static function updateFieldChartPermissionsTab($vis_id, $info)
369342

370343
return array(true, "");
371344
}
345+
346+
347+
private static function parseMultiSelectData($option_list_id, $results)
348+
{
349+
if (!empty($option_list_id)) {
350+
$option_list = OptionLists::getOptionListOptions($option_list_id);
351+
352+
$option_list_map = array();
353+
foreach ($option_list as $grouped) {
354+
if (!is_array($grouped["options"])) {
355+
continue;
356+
}
357+
foreach ($grouped["options"] as $option) {
358+
$option_list_map[$option["option_value"]] = $option["option_name"];
359+
}
360+
}
361+
362+
$updated_results = array();
363+
foreach ($results as $result) {
364+
if (!array_key_exists($result["field_value"], $option_list_map)) {
365+
continue;
366+
}
367+
368+
$updated_results[] = array(
369+
"field_value" => $option_list_map[$result["field_value"]],
370+
"count" => $result["count"]
371+
);
372+
}
373+
374+
$results = $updated_results;
375+
}
376+
377+
return $results;
378+
}
372379
}

code/Module.class.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
class Module extends FormToolsModule
1414
{
1515
protected $moduleName = "Data Visualization";
16-
protected $moduleDesc = "This module utilizes Google Charts API to create custom graphs and charts of your form submission data, providing an alternative, visual interpretation of your data.";
16+
protected $moduleDesc = "This module uses Google Charts API to create custom graphs and charts of your form submission data.";
1717
protected $author = "Ben Keen";
1818
protected $authorEmail = "[email protected]";
1919
protected $authorLink = "https://formtools.org";
20-
protected $version = "2.0.5";
21-
protected $date = "2018-01-24";
20+
protected $version = "2.0.6";
21+
protected $date = "2018-03-24";
2222
protected $originLanguage = "en_us";
2323
protected $jsFiles = array(
2424
"https://www.gstatic.com/charts/loader.js",

0 commit comments

Comments
 (0)