Merge branch 'MDL-85754_500_STABLE' of https://github.com/marxjohnson/moodle into MOODLE_500_STABLE

This commit is contained in:
Mihail Geshoski
2025-07-15 10:31:41 +08:00
7 changed files with 60 additions and 4 deletions
@@ -339,6 +339,7 @@ class question_bank_helper {
int $userid,
int $notincourseid = 0,
?context $filtercontext = null,
array $havingcap = [],
): array {
$prefs = get_user_preferences(self::RECENTLY_VIEWED, null, $userid);
$contextids = !empty($prefs) ? explode(',', $prefs) : [];
@@ -360,6 +361,9 @@ class question_bank_helper {
if (!empty($notincourseid) && $notincourseid == $cm->course) {
continue;
}
if (!empty($havingcap) && !(new question_edit_contexts($context))->have_one_cap($havingcap)) {
continue;
}
$record = self::get_formatted_bank($cm, filtercontext: $filtercontext);
$banks[] = $record;
}
@@ -66,7 +66,7 @@ class question_edit_contexts {
* @param \context $thiscontext the current context.
*/
public function __construct(\context $thiscontext) {
$this->allcontexts = array_values($thiscontext->get_parent_contexts(true));
$this->allcontexts = [$thiscontext];
}
/**
@@ -62,12 +62,13 @@ class switch_question_bank implements \renderable, \templatable {
[, $cm] = get_module_from_cmid($this->quizcmid);
$cminfo = cm_info::create($cm);
$capabilities = ['moodle/question:useall', 'moodle/question:usemine'];
$coursesharedbanks = question_bank_helper::get_activity_instances_with_shareable_questions(
incourseids: [$this->courseid],
havingcap: ['moodle/question:managecategory'],
havingcap: $capabilities,
filtercontext: $cminfo->context,
);
$recentlyviewedbanks = question_bank_helper::get_recently_used_open_banks($this->userid);
$recentlyviewedbanks = question_bank_helper::get_recently_used_open_banks($this->userid, havingcap: $capabilities);
return [
'quizname' => $cminfo->get_formatted_name(),