Merge branch 'MDL-79531-master-1' of https://github.com/mihailges/moodle
This commit is contained in:
+1
-1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -283,12 +283,12 @@ export default class ModalAddRandomQuestion extends Modal {
|
||||
}
|
||||
e.preventDefault();
|
||||
|
||||
const randomcount = document.querySelector(SELECTORS.SELECT_NUMBER_TO_ADD).value;
|
||||
const filtercondition = document.querySelector(SELECTORS.FILTER_CONDITION_ELEMENT).dataset?.filtercondition;
|
||||
|
||||
// Add Random questions if the add random button was clicked.
|
||||
const addRandomButton = e.target.closest(SELECTORS.ADD_RANDOM_BUTTON);
|
||||
if (addRandomButton) {
|
||||
const randomcount = document.querySelector(SELECTORS.SELECT_NUMBER_TO_ADD).value;
|
||||
const filtercondition = document.querySelector(SELECTORS.FILTER_CONDITION_ELEMENT).dataset?.filtercondition;
|
||||
|
||||
this.addQuestions(cmid, addonpage, randomcount, filtercondition, '', '');
|
||||
return;
|
||||
}
|
||||
@@ -298,8 +298,8 @@ export default class ModalAddRandomQuestion extends Modal {
|
||||
this.addQuestions(
|
||||
cmid,
|
||||
addonpage,
|
||||
randomcount,
|
||||
filtercondition,
|
||||
1,
|
||||
'',
|
||||
document.querySelector(SELECTORS.NEW_CATEGORY_ELEMENT).value,
|
||||
document.querySelector(SELECTORS.PARENT_CATEGORY_ELEMENT).value
|
||||
);
|
||||
|
||||
+19
-4
@@ -51,7 +51,13 @@ class add_random_questions extends external_api {
|
||||
'cmid' => new external_value(PARAM_INT, 'The cmid of the quiz'),
|
||||
'addonpage' => new external_value(PARAM_INT, 'The page where random questions will be added to'),
|
||||
'randomcount' => new external_value(PARAM_INT, 'Number of random questions'),
|
||||
'filtercondition' => new external_value(PARAM_TEXT, 'Filter condition'),
|
||||
'filtercondition' => new external_value(
|
||||
PARAM_TEXT,
|
||||
'(Optional) The filter condition used when adding random questions from an existing category.
|
||||
Not required if adding random questions from a new category.',
|
||||
VALUE_DEFAULT,
|
||||
'',
|
||||
),
|
||||
'newcategory' => new external_value(
|
||||
PARAM_TEXT,
|
||||
'(Optional) The name of a new question category to create and use for the random questions.',
|
||||
@@ -83,7 +89,7 @@ class add_random_questions extends external_api {
|
||||
int $cmid,
|
||||
int $addonpage,
|
||||
int $randomcount,
|
||||
string $filtercondition,
|
||||
string $filtercondition = '',
|
||||
string $newcategory = '',
|
||||
string $parentcategory = '',
|
||||
): array {
|
||||
@@ -108,7 +114,8 @@ class add_random_questions extends external_api {
|
||||
self::validate_context($thiscontext);
|
||||
require_capability('mod/quiz:manage', $thiscontext);
|
||||
|
||||
$filtercondition = json_decode($filtercondition, true);
|
||||
// If filtercondition is not empty, decode it. Otherwise, set it to empty array.
|
||||
$filtercondition = !empty($filtercondition) ? json_decode($filtercondition, true) : [];
|
||||
|
||||
// Create new category.
|
||||
if (!empty($newcategory)) {
|
||||
@@ -131,7 +138,15 @@ class add_random_questions extends external_api {
|
||||
'filteroptions' => ['includesubcategories' => false],
|
||||
]
|
||||
];
|
||||
$filtercondition['filter'] = $filter;
|
||||
// Generate default filter condition for the random question to be added in the new category.
|
||||
$filtercondition = [
|
||||
'qpage' => 0,
|
||||
'cat' => "{$categoryid},{$thiscontext->id}",
|
||||
'qperpage' => DEFAULT_QUESTIONS_PER_PAGE,
|
||||
'tabname' => 'questions',
|
||||
'sortdata' => [],
|
||||
'filter' => $filter,
|
||||
];
|
||||
}
|
||||
|
||||
// Add random question to the quiz.
|
||||
|
||||
@@ -8,7 +8,9 @@ This files describes API changes in the quiz code.
|
||||
In the distant past it was always a stdClass, then at one point there was an undocumented change making
|
||||
it sometimes a stdClass and sometimes a cm_info. Now it is consistently a cm_info. Type hints have been
|
||||
updated to reflect this.
|
||||
|
||||
* The parameter filtercondition in the web service mod_quiz_add_random_questions is now optional. This parameter is
|
||||
only used when adding random questions from an existing category. It is not required when adding random questions from
|
||||
a new category since it is not used in this case.
|
||||
|
||||
=== 4.2 ===
|
||||
|
||||
|
||||
@@ -1167,8 +1167,10 @@ class view {
|
||||
echo \html_writer::empty_tag('input', ['type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()]);
|
||||
echo \html_writer::input_hidden_params($this->baseurl);
|
||||
|
||||
$filtercondition = json_encode($this->get_pagevars());
|
||||
// Embeded filterconditon into the div.
|
||||
echo \html_writer::start_tag('div',
|
||||
['class' => 'categoryquestionscontainer']);
|
||||
['class' => 'categoryquestionscontainer', 'data-filtercondition' => $filtercondition]);
|
||||
if ($totalquestions > 0) {
|
||||
// Bulk load any required statistics.
|
||||
$this->load_required_statistics($questions);
|
||||
@@ -1365,11 +1367,8 @@ class view {
|
||||
echo $OUTPUT->render($pagingbar);
|
||||
|
||||
// Table of questions.
|
||||
// Embeded filterconditon into the div.
|
||||
$filtercondition = json_encode($this->get_pagevars());
|
||||
|
||||
echo \html_writer::start_tag('div',
|
||||
['class' => 'question_table', 'id' => 'question_table', 'data-filtercondition' => $filtercondition]);
|
||||
['class' => 'question_table', 'id' => 'question_table']);
|
||||
$this->print_table($questions);
|
||||
echo \html_writer::end_tag('div');
|
||||
echo $OUTPUT->render($pagingbar);
|
||||
|
||||
Reference in New Issue
Block a user