Skip to content

Commit c9f1267

Browse files
Merge pull request #71 from wiris/fix/moodle-402
fix: provide question chooser compatibility with moodle 4.0.2
2 parents 9b531e4 + d142d46 commit c9f1267

File tree

3 files changed

+68
-3
lines changed

3 files changed

+68
-3
lines changed

questiontype.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,11 @@ public function menu_name() {
141141
if ($CFG->version < 2014051200) {
142142
// Backwards compatibility.
143143
$PAGE->requires->js('/question/type/wq/js/display.js', false);
144+
} else if ($CFG->version >= 2022041900) {
145+
// Moodle 4.0.2 and up.
146+
$PAGE->requires->yui_module('moodle-qtype_wq-question_chooser_qbank', 'M.qtype_wq.question_chooser.init', array()); // @codingStandardsIgnoreLine
144147
} else {
145-
// New moodle-standard way.
148+
// Moodle 3.X.
146149
$PAGE->requires->yui_module('moodle-qtype_wq-question_chooser', 'M.qtype_wq.question_chooser.init');
147150
}
148151

version.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
defined('MOODLE_INTERNAL') || die();
1818

19-
$plugin->version = 2022072600;
19+
$plugin->version = 2022090700;
2020
$plugin->requires = 2015111600; // Moodle 3.0.
21-
$plugin->release = '4.5.1';
21+
$plugin->release = '4.5.2';
2222
$plugin->maturity = MATURITY_STABLE;
2323
$plugin->component = 'qtype_wq';
2424
$plugin->dependencies = array (
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
YUI.add('moodle-qtype_wq-question_chooser_qbank', function (Y, NAME) {
2+
3+
// Namespace for Wiris Quizzes.
4+
M.qtype_wq = M.qtype_wq || {};
5+
// Question chooser class.
6+
M.qtype_wq.question_chooser = {
7+
/**
8+
* Array with all the real Wiris Quizzes questions.
9+
* */
10+
wirisquestions: null,
11+
/**
12+
* Start point.
13+
* */
14+
init: function() {
15+
this.wirisSection();
16+
},
17+
/**
18+
* Moves all Wiris Quizzes questions under node_before and populates the array
19+
* this.wirisquestions.
20+
* @param {node} nodeBefore - Previous node.
21+
*/
22+
moveWirisQuestions: function(nodeBefore) {
23+
var wirisdivs = [];
24+
Y.all('div.option').each(function(node) {
25+
var input = node.one('input');
26+
if (
27+
input &&
28+
input.getAttribute('value') &&
29+
input.getAttribute('value').indexOf('wiris') !== -1
30+
) {
31+
nodeBefore.insert(node, 'after');
32+
nodeBefore = node;
33+
wirisdivs.push(node);
34+
}
35+
});
36+
this.wirisquestions = wirisdivs;
37+
},
38+
/**
39+
* Unused function. Join all Wiris Quizzes questions in a section after
40+
* QUESTIONS and before OTHER.
41+
* */
42+
wirisSection: function() {
43+
var label = Y.one('label[for=qtype_qtype_wq]');
44+
label = label ? label : Y.one('label[for=item_qtype_wq]');
45+
if (label) {
46+
// Convert qtype option into section title and move to the bottom.
47+
var wq = label.ancestor('div');
48+
var name = wq.one('span.typename').remove(false);
49+
wq.one('label').remove(true);
50+
wq.append(name).addClass('moduletypetitle');
51+
var container = wq.ancestor();
52+
wq.remove();
53+
container.insertBefore(wq, container.one('div.separator'));
54+
container.insertBefore(Y.Node.create('<div class="separator"/>'), wq);
55+
// Move all Wiris qtypes under title.
56+
this.moveWirisQuestions(wq);
57+
}
58+
}
59+
};
60+
61+
62+
}, '@VERSION@', {"requires": ["moodle-qbank_editquestion-chooser"]});

0 commit comments

Comments
 (0)