Merge branch 'MDL-85248-405' of https://github.com/albertgasset/moodle into MOODLE_405_STABLE

This commit is contained in:
Sara Arjona
2025-05-14 21:42:47 +07:00
committed by Huong Nguyen
10 changed files with 52 additions and 60 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) {
const places = JSON.parse(document.querySelector('#' + containerId + ' .dropzones').dataset.placeInfo);
init: function(containerId, readOnly, places) {
questionManager.questions[containerId] =
new DragDropOntoImageQuestion(containerId, readOnly, places);
if (!questionManager.eventHandlersInitialised) {
+17 -16
View File
@@ -71,21 +71,7 @@ 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']);
// 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::div('', 'dropzones');
$output .= html_writer::end_div();
$output .= html_writer::start_div($draghomesclass);
@@ -117,11 +103,26 @@ 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]);
[$qa->get_outer_question_div_unique_id(), $options->readonly, $placeinfoforjsandmobileapp]);
if ($qa->get_state() == question_state::$invalid) {
$output .= html_writer::div($question->get_validation_error($qa->get_last_qt_data()), 'validationerror');
@@ -68,8 +68,6 @@ 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
+2 -3
View File
@@ -908,10 +908,9 @@ 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) {
const visibleDropZones = JSON.parse(document.querySelector('#' + containerId + ' .dropzones')
.dataset.visibledDropzones);
init: function(containerId, readOnly, visibleDropZones) {
questionManager.questions[containerId] =
new DragDropMarkersQuestion(containerId, readOnly, visibleDropZones);
if (!questionManager.eventHandlersInitialised) {
+17 -18
View File
@@ -60,19 +60,7 @@ 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']);
$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('', 'dropzones');
$output .= html_writer::div('', 'markertexts');
$output .= html_writer::end_div();
@@ -111,15 +99,26 @@ class qtype_ddmarker_renderer extends qtype_ddtoimage_renderer_base {
$output .= html_writer::div($question->get_validation_error($qa->get_last_qt_data()), 'validationerror');
}
if (count($visibledropzones) !== 0) {
$wrongpartsstring = join(', ', $wrongpartsstringspans);
$output .= html_writer::span(get_string('followingarewrongandhighlighted', 'qtype_ddmarker', $wrongpartsstring),
'wrongparts');
$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');
}
}
$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]);
[$qa->get_outer_question_div_unique_id(), $options->readonly, $visibledropzones]);
return $output;
}
@@ -96,18 +96,16 @@ 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-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());
$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.
@@ -323,7 +321,6 @@ 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.
@@ -361,8 +358,6 @@ 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),