Survey: Fix multiplechoiceother results export - refs #4879

Author: @TheTomcat14
pull/4909/head
TheTomcat14 2 years ago committed by GitHub
parent b9f5322809
commit 7c112932aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 24
      main/survey/ch_multiplechoiceother.php
  2. 118
      main/survey/surveyUtil.class.php

@ -73,6 +73,21 @@ class ch_multiplechoiceother extends survey_question
}
}
$questionId = $questionData['question_id'];
$display = 'display:none';
$defaultOtherData = '';
if (!empty($answers)) {
$answers = self::decodeOptionValue($answers);
if (isset($answers[1])) {
$display = '';
$defaultOtherData = $answers[1];
}
$answers = $answers[0];
}
$question->render($form, $questionData, $answers);
$form->addHtml(
'<script>
@ -89,15 +104,6 @@ class ch_multiplechoiceother extends survey_question
</script>'
);
$display = 'display:none';
$defaultOtherData = '';
if (!empty($answers)) {
$answers = self::decodeOptionValue($answers);
if (isset($answers[1])) {
$display = '';
$defaultOtherData = $answers[1];
}
}
$form->addHtml('<div id="other_div_'.$questionId.'" class="multiple_choice_other" style="'.$display.'">');
$element = $form->addText(
'other_question'.$questionId,

@ -905,7 +905,11 @@ class SurveyUtil
$row['option_id'] = $parts[0];
}
$data[$row['option_id']] = $row;
if (!isset($data[$row['option_id']])) {
$data[$row['option_id']] = $row;
} else {
$data[$row['option_id']]['total'] = $data[$row['option_id']]['total'] + $row['total'];
}
}
foreach ($options as $option) {
@ -1740,7 +1744,9 @@ class SurveyUtil
)
.';';
} else {
for ($ii = 0; $ii < $row['number_of_options']; $ii++) {
$numberOfOptions = $row['number_of_options'];
if ($row['type'] == 'multiplechoiceother') $numberOfOptions++;
for ($ii = 0; $ii < $numberOfOptions; $ii++) {
$return .= str_replace(
"\r\n",
' ',
@ -1795,6 +1801,8 @@ class SurveyUtil
$result = Database::query($sql);
$possible_answers = [];
$possible_answers_type = [];
$current_question_type = '';
$current_question_id = null;
while ($row = Database::fetch_array($result)) {
// We show the options if
// 1. there is no question filter and the export button has not been clicked
@ -1807,9 +1815,21 @@ class SurveyUtil
in_array($row['question_id'], $_POST['questions_filter'.$suffixLpItem])
)
) {
if ($current_question_id != $row['question_id']) {
if ($current_question_type == 'multiplechoiceother') {
$return .= api_html_entity_decode(strip_tags(get_lang('Comment')), ENT_QUOTES).';';
}
}
$current_question_type = $row['type'];
$current_question_id = $row['question_id'];
$row['option_text'] = str_replace(["\r", "\n"], ['', ''], $row['option_text']);
if (!$compact) {
$return .= api_html_entity_decode(strip_tags($row['option_text']), ENT_QUOTES).';';
$possible_answers[$row['question_id']][$row['question_option_id']] = $row['question_option_id'];
} else {
$possible_answers[$row['question_id']][$row['question_option_id']] = $row['option_text'];
@ -1818,6 +1838,10 @@ class SurveyUtil
}
}
if ($current_question_type == 'multiplechoiceother') {
$return .= api_html_entity_decode(strip_tags(get_lang('Comment')), ENT_QUOTES).';';
}
$return .= "\n";
// To select the answers by Lp item
@ -1856,7 +1880,8 @@ class SurveyUtil
$answers_of_user,
$old_user,
!$survey_data['anonymous'],
$compact
$compact,
$possible_answers_type
);
$answers_of_user = [];
}
@ -1880,7 +1905,8 @@ class SurveyUtil
$answers_of_user,
$old_user,
true,
$compact
$compact,
$possible_answers_type
);
return $return;
@ -1908,7 +1934,8 @@ class SurveyUtil
$answers_of_user,
$user,
$display_extra_user_fields = false,
$compact = false
$compact = false,
$questionTypes = true
) {
$return = '';
if (0 == $survey_data['anonymous']) {
@ -1946,6 +1973,7 @@ class SurveyUtil
if (is_array($possible_options)) {
foreach ($possible_options as $question_id => $possible_option) {
if (is_array($possible_option) && count($possible_option) > 0) {
$otherPaddingNeeded = ($questionTypes[$question_id] == 'multiplechoiceother' ? true : false);
foreach ($possible_option as $option_id => &$value) {
// For each option of this question, look if it matches the user's answer
$my_answer_of_user = !isset($answers_of_user[$question_id]) || isset($answers_of_user[$question_id]) && $answers_of_user[$question_id] == null ? [] : $answers_of_user[$question_id];
@ -1994,12 +2022,30 @@ class SurveyUtil
$return .= 'v;';
}
}
} elseif (isset($key[0]) && strpos($key[0], '@:@') !== false) {
list($idAnswer, $other) = explode('@:@', $key[0]);
if ($idAnswer == $option_id) {
$return .= (
strlen($other) > 0
? 'v;"' . str_replace('"', '""', api_html_entity_decode(strip_tags($other), ENT_QUOTES)) . '";'
: 'v;'
);
} else {
if (!$compact) {
$return .= ';';
$otherPaddingNeeded = false;
}
}
} else {
if (!$compact) {
if (!$compact || $questionTypes[$question_id] == 'multipleresponse') {
$return .= ';';
}
}
}
if ($otherPaddingNeeded == true) {
$return .= ';';
}
}
}
}
@ -2107,7 +2153,9 @@ class SurveyUtil
);
$column++;
} else {
for ($ii = 0; $ii < $row['number_of_options']; $ii++) {
$numberOfOptions = $row['number_of_options'];
if ($row['type'] == 'multiplechoiceother') $numberOfOptions++;
for ($ii = 0; $ii < $numberOfOptions; $ii++) {
$worksheet->setCellValueByColumnAndRow(
$column,
$line,
@ -2162,6 +2210,8 @@ class SurveyUtil
$result = Database::query($sql);
$possible_answers = [];
$possible_answers_type = [];
$current_question_type = '';
$current_question_id = null;
while ($row = Database::fetch_array($result)) {
// We show the options if
// 1. there is no question filter and the export button has not been clicked
@ -2170,6 +2220,23 @@ class SurveyUtil
(isset($_POST['questions_filter'.$suffixLpItem]) && is_array($_POST['questions_filter'.$suffixLpItem]) &&
in_array($row['question_id'], $_POST['questions_filter'.$suffixLpItem]))
) {
if ($current_question_id != $row['question_id']) {
if ($current_question_type == 'multiplechoiceother') {
$worksheet->setCellValueByColumnAndRow(
$column,
$line,
api_html_entity_decode(
strip_tags(get_lang('Comment')),
ENT_QUOTES
)
);
$column++;
}
}
$current_question_type = $row['type'];
$current_question_id = $row['question_id'];
$worksheet->setCellValueByColumnAndRow(
$column,
$line,
@ -2184,6 +2251,17 @@ class SurveyUtil
}
}
if ($current_question_type == 'multiplechoiceother') {
$worksheet->setCellValueByColumnAndRow(
$column,
$line,
api_html_entity_decode(
strip_tags(get_lang('Comment')),
ENT_QUOTES
)
);
}
// To select the answers by Lp item
$lpItemCondition = '';
if (api_get_configuration_value('allow_survey_tool_in_lp')) {
@ -2211,7 +2289,8 @@ class SurveyUtil
$possible_answers,
$answers_of_user,
$old_user,
!$survey_data['anonymous']
!$survey_data['anonymous'],
$possible_answers_type
);
foreach ($return as $elem) {
$worksheet->setCellValueByColumnAndRow($column, $line, $elem);
@ -2238,7 +2317,8 @@ class SurveyUtil
$possible_answers,
$answers_of_user,
$old_user,
true
true,
$possible_answers_type
);
// this is to display the last user
@ -2275,7 +2355,8 @@ class SurveyUtil
$possible_options,
$answers_of_user,
$user,
$display_extra_user_fields = false
$display_extra_user_fields = false,
$questionTypes = true
) {
$return = [];
if ($survey_data['anonymous'] == 0) {
@ -2311,6 +2392,7 @@ class SurveyUtil
if (is_array($possible_options)) {
foreach ($possible_options as $question_id => &$possible_option) {
$otherPaddingNeeded = ($questionTypes[$question_id] == 'multiplechoiceother' ? true : false);
if (is_array($possible_option) && count($possible_option) > 0) {
foreach ($possible_option as $option_id => &$value) {
$my_answers_of_user = isset($answers_of_user[$question_id])
@ -2328,10 +2410,26 @@ class SurveyUtil
} else {
$return[] = 'v';
}
} elseif (isset($key[0]) && strpos($key[0], '@:@') !== false) {
list($idAnswer, $other) = explode('@:@', $key[0]);
if ($idAnswer == $option_id) {
if (strlen($other) > 0) {
$return[] = 'v';
$return[] = api_html_entity_decode(strip_tags($other), ENT_QUOTES);
$otherPaddingNeeded = false;
} else {
$return[] = 'v';
}
} else {
$return[] = '';
}
} else {
$return[] = '';
}
}
if ($otherPaddingNeeded == true) {
$return[] = '';
}
}
}
}

Loading…
Cancel
Save