Merge branch 'MDL-66584-master' of https://github.com/danghieu1407/moodle

This commit is contained in:
Sara Arjona
2025-04-14 17:47:29 +02:00
10 changed files with 60 additions and 52 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1120,9 +1120,9 @@ define([
* @method
* @param {String} containerId the id of the div.que that contains this question.
* @param {boolean} readOnly whether the question is read-only.
* @param {Array} places data.
*/
init: function(containerId, readOnly, places) {
init: function(containerId, readOnly) {
const places = JSON.parse(document.querySelector('#' + containerId + ' .dropzones').dataset.placeInfo);
questionManager.questions[containerId] =
new DragDropOntoImageQuestion(containerId, readOnly, places);
if (!questionManager.eventHandlersInitialised) {
+16 -17
View File
@@ -75,7 +75,21 @@ class qtype_ddtoimage_renderer_base extends qtype_with_combined_feedback_rendere
$output .= html_writer::img(self::get_url_for_image($qa, 'bgimage'), get_string('dropbackground', 'qtype_ddmarker'),
['class' => 'dropbackground img-fluid w-100']);
$output .= html_writer::div('', 'dropzones');
// Note, the mobile app implementation of ddimageortext relies on extracting the
// blob of places data out of the rendered HTML, which makes it impossible
// to clean up this structure of otherwise unnecessary stuff.
$placeinfoforjsandmobileapp = [];
foreach ($question->places as $placeno => $place) {
$varname = $question->field($placeno);
[$fieldname, $html] = $this->hidden_field_for_qt_var($qa, $varname, null,
['placeinput', 'place' . $placeno, 'group' . $place->group]);
$output .= $html;
$placeinfo = (object) (array) $place;
$placeinfo->fieldname = $fieldname;
$placeinfoforjsandmobileapp[$placeno] = $placeinfo;
}
$output .= html_writer::div('', 'dropzones', ['data-place-info' => json_encode($placeinfoforjsandmobileapp)]);
$output .= html_writer::end_div();
$output .= html_writer::start_div($draghomesclass);
@@ -107,26 +121,11 @@ class qtype_ddtoimage_renderer_base extends qtype_with_combined_feedback_rendere
$output .= $dragimagehomes;
$output .= html_writer::end_div();
// Note, the mobile app implementation of ddimageortext relies on extracting the
// blob of places data out of the rendered HTML, which makes it impossible
// to clean up this structure of otherwise unnecessary stuff.
$placeinfoforjsandmobileapp = [];
foreach ($question->places as $placeno => $place) {
$varname = $question->field($placeno);
[$fieldname, $html] = $this->hidden_field_for_qt_var($qa, $varname, null,
['placeinput', 'place' . $placeno, 'group' . $place->group]);
$output .= $html;
$placeinfo = (object) (array) $place;
$placeinfo->fieldname = $fieldname;
$placeinfo->text = format_string($placeinfo->text);
$placeinfoforjsandmobileapp[$placeno] = $placeinfo;
}
$output .= html_writer::end_div();
$this->page->requires->string_for_js('blank', 'qtype_ddimageortext');
$this->page->requires->js_call_amd('qtype_ddimageortext/question', 'init',
[$qa->get_outer_question_div_unique_id(), $options->readonly, $placeinfoforjsandmobileapp]);
[$qa->get_outer_question_div_unique_id(), $options->readonly]);
if ($qa->get_state() == question_state::$invalid) {
$output .= html_writer::div($question->get_validation_error($qa->get_last_qt_data()), 'validationerror');
@@ -68,6 +68,8 @@ final class walkthrough_test extends \qbehaviour_walkthrough_test_base {
$this->check_current_mark(null);
$this->check_current_output(
new \question_pattern_expectation(
'~<div class="dropzones" data-place-info=~'),
$this->get_contains_drag_image_home_expectation(1, 1, 1),
$this->get_contains_drag_image_home_expectation(2, 2, 1),
$this->get_contains_drag_image_home_expectation(3, 1, 2),
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+3 -2
View File
@@ -908,9 +908,10 @@ define([
*
* @param {String} containerId the id of the div.que that contains this question.
* @param {boolean} readOnly whether the question is read-only.
* @param {Object[]} visibleDropZones data on any drop zones to draw as part of the feedback.
*/
init: function(containerId, readOnly, visibleDropZones) {
init: function(containerId, readOnly) {
const visibleDropZones = JSON.parse(document.querySelector('#' + containerId + ' .dropzones')
.dataset.visibledDropzones);
questionManager.questions[containerId] =
new DragDropMarkersQuestion(containerId, readOnly, visibleDropZones);
if (!questionManager.eventHandlersInitialised) {
+18 -17
View File
@@ -60,7 +60,19 @@ class qtype_ddmarker_renderer extends qtype_ddtoimage_renderer_base {
$output .= html_writer::img(self::get_url_for_image($qa, 'bgimage'), get_string('dropbackground', 'qtype_ddmarker'),
['class' => 'dropbackground img-fluid w-100']);
$output .= html_writer::div('', 'dropzones');
$visibledropzones = [];
if ($question->showmisplaced && $qa->get_state()->is_finished()) {
$visibledropzones = $question->get_drop_zones_without_hit($response);
if (count($visibledropzones) !== 0) {
$wrongpartsstringspans = [];
foreach ($visibledropzones as $visibledropzone) {
$visibledropzone->markertext = question_utils::format_question_fragment(
$visibledropzone->markertext, $this->page->context);
$wrongpartsstringspans[] = html_writer::span($visibledropzone->markertext, 'wrongpart');
}
}
}
$output .= html_writer::div('', 'dropzones', ['data-visibled-dropzones' => json_encode($visibledropzones)]);
$output .= html_writer::div('', 'markertexts');
$output .= html_writer::end_div();
@@ -99,26 +111,15 @@ class qtype_ddmarker_renderer extends qtype_ddtoimage_renderer_base {
$output .= html_writer::div($question->get_validation_error($qa->get_last_qt_data()), 'validationerror');
}
$visibledropzones = [];
if ($question->showmisplaced && $qa->get_state()->is_finished()) {
$visibledropzones = $question->get_drop_zones_without_hit($response);
if (count($visibledropzones) !== 0) {
$wrongpartsstringspans = [];
foreach ($visibledropzones as $visibledropzone) {
$visibledropzone->markertext = question_utils::format_question_fragment(
$visibledropzone->markertext, $this->page->context);
$wrongpartsstringspans[] = html_writer::span($visibledropzone->markertext, 'wrongpart');
}
$wrongpartsstring = join(', ', $wrongpartsstringspans);
$output .= html_writer::span(get_string('followingarewrongandhighlighted', 'qtype_ddmarker', $wrongpartsstring),
'wrongparts');
}
if (count($visibledropzones) !== 0) {
$wrongpartsstring = join(', ', $wrongpartsstringspans);
$output .= html_writer::span(get_string('followingarewrongandhighlighted', 'qtype_ddmarker', $wrongpartsstring),
'wrongparts');
}
$output .= html_writer::div($hiddenfields, 'ddform');
$this->page->requires->js_call_amd('qtype_ddmarker/question', 'init',
[$qa->get_outer_question_div_unique_id(), $options->readonly, $visibledropzones]);
[$qa->get_outer_question_div_unique_id(), $options->readonly]);
return $output;
}
@@ -96,16 +96,18 @@ final class walkthrough_test extends \qbehaviour_walkthrough_test_base {
$this->check_current_mark(null);
$this->check_current_output(
$this->get_contains_draggable_marker_home_expectation(1, false),
$this->get_contains_draggable_marker_home_expectation(2, false),
$this->get_contains_draggable_marker_home_expectation(3, false),
$this->get_contains_hidden_expectation(1),
$this->get_contains_hidden_expectation(2),
$this->get_contains_hidden_expectation(3),
$this->get_contains_submit_button_expectation(true),
$this->get_does_not_contain_feedback_expectation(),
$this->get_tries_remaining_expectation(3),
$this->get_no_hint_visible_expectation());
new \question_pattern_expectation(
'~<div class="dropzones" data-visibled-dropzones=~'),
$this->get_contains_draggable_marker_home_expectation(1, false),
$this->get_contains_draggable_marker_home_expectation(2, false),
$this->get_contains_draggable_marker_home_expectation(3, false),
$this->get_contains_hidden_expectation(1),
$this->get_contains_hidden_expectation(2),
$this->get_contains_hidden_expectation(3),
$this->get_contains_submit_button_expectation(true),
$this->get_does_not_contain_feedback_expectation(),
$this->get_tries_remaining_expectation(3),
$this->get_no_hint_visible_expectation());
$completelywrong = array('c1' => '0,250', 'c2' => '100,250', 'c3' => '150,250');
// Save the wrong answer.
@@ -321,6 +323,7 @@ final class walkthrough_test extends \qbehaviour_walkthrough_test_base {
// Create a drag-and-drop question.
$dd = \test_question_maker::make_question('ddmarker');
$dd->shufflechoices = false;
$dd->showmisplaced = true;
$this->start_attempt_at_question($dd, 'deferredfeedback', 3);
// Check the initial state.
@@ -358,6 +361,8 @@ final class walkthrough_test extends \qbehaviour_walkthrough_test_base {
$this->check_current_state(question_state::$gradedpartial);
$this->check_current_mark(2);
$this->check_current_output(
new \question_pattern_expectation(
'~<div class="dropzones" data-visibled-dropzones="\\[[^]]+\\]"~'),
$this->get_contains_draggable_marker_home_expectation(1, false),
$this->get_contains_draggable_marker_home_expectation(2, false),
$this->get_contains_draggable_marker_home_expectation(3, false),