mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
question bank: MDL-18531 if someone can use questions in the quiz context, but not the course context, choose a more sensible default category in the question bank. Merged from MOODLE_19_STABLE.
This commit is contained in:
parent
89175225bf
commit
353b2d700d
@ -2117,7 +2117,6 @@ function get_question_responses($question, $state) {
|
|||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the response given by the user in a particular state
|
* Gets the response given by the user in a particular state
|
||||||
*
|
*
|
||||||
@ -2327,11 +2326,18 @@ function question_edit_url($context) {
|
|||||||
*/
|
*/
|
||||||
function question_make_default_categories($contexts) {
|
function question_make_default_categories($contexts) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
static $preferredlevels = array(
|
||||||
|
CONTEXT_COURSE => 4,
|
||||||
|
CONTEXT_MODULE => 3,
|
||||||
|
CONTEXT_COURSECAT => 2,
|
||||||
|
CONTEXT_SYSTEM => 1,
|
||||||
|
);
|
||||||
|
|
||||||
$toreturn = null;
|
$toreturn = null;
|
||||||
|
$preferredness = 0;
|
||||||
// If it already exists, just return it.
|
// If it already exists, just return it.
|
||||||
foreach ($contexts as $key => $context) {
|
foreach ($contexts as $key => $context) {
|
||||||
if (!$exists = $DB->record_exists("question_categories", array('contextid'=>$context->id))){
|
if (!$exists = $DB->record_exists("question_categories", array('contextid'=>$context->id))) {
|
||||||
// Otherwise, we need to make one
|
// Otherwise, we need to make one
|
||||||
$category = new stdClass;
|
$category = new stdClass;
|
||||||
$contextname = print_context_name($context, false, true);
|
$contextname = print_context_name($context, false, true);
|
||||||
@ -2348,12 +2354,15 @@ function question_make_default_categories($contexts) {
|
|||||||
$category = question_get_default_category($context->id);
|
$category = question_get_default_category($context->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($context->contextlevel == CONTEXT_COURSE){
|
if ($preferredlevels[$context->contextlevel] > $preferredness && has_capability('moodle/question:use', $context)) {
|
||||||
$toreturn = clone($category);
|
$toreturn = $category;
|
||||||
|
$preferredness = $preferredlevels[$context->contextlevel];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!is_null($toreturn)) {
|
||||||
|
$toreturn = clone($toreturn);
|
||||||
|
}
|
||||||
return $toreturn;
|
return $toreturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user