Skip to content

Commit

Permalink
MBS-8796: Dont load all courses for the form
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-csg committed Aug 27, 2024
1 parent d32b5dd commit ec1dc88
Showing 1 changed file with 5 additions and 23 deletions.
28 changes: 5 additions & 23 deletions mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ public function definition() {
$mform->setExpanded('section-refcourse');
$mform->addHelpButton('section-refcourse', 'refcourse', 'subcourse');

$mycourses = subcourse_available_courses();

$currentrefcourseid = isset($this->current->refcourse) ? $this->current->refcourse : null;
$currentrefcoursename = null;
$currentrefcourseavailable = false;
Expand All @@ -86,11 +84,8 @@ public function definition() {

} else {
// Check if the currently set value is still available.
foreach ($mycourses as $mycourse) {
if ($mycourse->id == $currentrefcourseid) {
$currentrefcourseavailable = true;
break;
}
if (has_capability('moodle/grade:viewall', context_course::instance($currentrefcourseid))) {
$currentrefcourseavailable = true;
}
}
}
Expand All @@ -105,23 +100,10 @@ public function definition() {
$includekeepref = true;
}

$options = [get_string('none')];

if (empty($mycourses)) {
if (empty($includekeepref)) {
$options = [0 => get_string('nocoursesavailable', 'subcourse')];
$mform->addElement('select', 'refcourse', get_string('refcourselabel', 'subcourse'), $options);
} else {
$mform->addElement('hidden', 'refcourse', 0);
$mform->setType('refcourse', PARAM_INT);
}
$mform->addElement('course', 'refcourse', get_string('refcourselabel', 'subcourse'), ['limittoenrolled' => 1]);

} else {
$mform->addElement('course', 'refcourse', get_string('refcourselabel', 'subcourse'), ['limittoenrolled' => 1]);

if (!empty($includekeepref)) {
$mform->disabledIf('refcourse', 'refcoursecurrent', 'checked');
}
if (!empty($includekeepref)) {
$mform->disabledIf('refcourse', 'refcoursecurrent', 'checked');
}

$mform->addElement('header', 'section-gradesfetching', get_string('gradesfetching', 'subcourse'));
Expand Down

0 comments on commit ec1dc88

Please sign in to comment.