Skip to content
Snippets Groups Projects
Commit 18160982 authored by Lee Kirkland's avatar Lee Kirkland Committed by Ryan Smith
Browse files

fix: Removes HTML from quiz responses to close #304. (#315)

parent 1c3bef27
No related branches found
No related tags found
No related merge requests found
......@@ -27,7 +27,6 @@ function multichoice(array $config, \stdClass $event, \stdClass $questionattempt
$quiz = $repo->read_record_by_id('quiz', $attempt->quiz);
$coursemodule = $repo->read_record_by_id('course_modules', $event->contextinstanceid);
$lang = utils\get_course_lang($course);
return [[
'actor' => utils\get_user($config, $user),
'verb' => [
......@@ -42,11 +41,12 @@ function multichoice(array $config, \stdClass $event, \stdClass $questionattempt
],
'timestamp' => utils\get_event_timestamp($event),
'result' => [
'response' => $questionattempt->responsesummary,
'response' => utils\get_string_html_removed($questionattempt->responsesummary),
'success' => $questionattempt->rightanswer == $questionattempt->responsesummary,
'completion' => $questionattempt->responsesummary !== '',
'extensions' => [
'http://learninglocker.net/xapi/cmi/choice/response' => $questionattempt->responsesummary,
'http://learninglocker.net/xapi/cmi/choice/response' =>
utils\get_string_html_removed($questionattempt->responsesummary),
],
],
'context' => [
......
......@@ -28,7 +28,6 @@ function truefalse(array $config, \stdClass $event, \stdClass $questionattempt,
$quiz = $repo->read_record_by_id('quiz', $attempt->quiz);
$coursemodule = $repo->read_record_by_id('course_modules', $event->contextinstanceid);
$lang = utils\get_course_lang($course);
return [[
'actor' => utils\get_user($config, $user),
'verb' => [
......@@ -42,14 +41,14 @@ function truefalse(array $config, \stdClass $event, \stdClass $questionattempt,
'definition' => [
'type' => 'http://adlnet.gov/expapi/activities/cmi.interaction',
'name' => [
$lang => $question->questiontext,
$lang => utils\get_string_html_removed($question->questiontext),
],
'interactionType' => 'true-false',
]
],
'timestamp' => utils\get_event_timestamp($event),
'result' => [
'response' => $questionattempt->responsesummary,
'response' => utils\get_string_html_removed($questionattempt->responsesummary),
'completion' => $questionattempt->responsesummary !== null,
'success' => $questionattempt->rightanswer === $questionattempt->responsesummary,
'extensions' => [
......
......@@ -15,6 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace src\transformer\utils;
use src\transformer\utils as utils;
defined('MOODLE_INTERNAL') || die();
function get_multichoice_definition(array $config, \stdClass $questionattempt, \stdClass $question, $lang) {
......@@ -27,27 +28,28 @@ function get_multichoice_definition(array $config, \stdClass $questionattempt, \
return [
"id" => "$answer->id",
"description" => [
$lang => $answer->answer
$lang => utils\get_string_html_removed($answer->answer)
]
];
}, $answers);
return [
'type' => 'http://adlnet.gov/expapi/activities/cmi.interaction',
'name' => [
$lang => $question->questiontext,
$lang => utils\get_string_html_removed($question->questiontext),
],
'interactionType' => 'choice',
'correctResponsesPattern' => [
$questionattempt->rightanswer,
utils\get_string_html_removed($questionattempt->rightanswer),
],
'choices' => $choices
// Need to pull out id's that are appended during array_map so json parses it correctly as an array.
'choices' => array_values($choices)
];
}
return [
'type' => 'http://adlnet.gov/expapi/activities/cmi.interaction',
'name' => [
$lang => $question->questiontext,
$lang => utils\get_string_html_removed($question->questiontext),
],
'interactionType' => 'choice'
];
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace src\transformer\utils;
defined('MOODLE_INTERNAL') || die();
function get_string_html_removed($string) {
// For some reason, newlines and &nbsp; is being added to strings,
// in order to remove new lines we have to ensure nbsp is also removed.
$replacestrings = ["\n", "&nbsp;"];
return str_replace($replacestrings, "", strip_tags($string));
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment