diff --git a/mod_form.php b/mod_form.php index a15524d..de5cf8a 100644 --- a/mod_form.php +++ b/mod_form.php @@ -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; @@ -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; } } } @@ -105,37 +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); - } - - } else { - $catlist = core_course_category::make_categories_list('', 0, ' / '); - - foreach ($mycourses as $mycourse) { - $courselabel = $catlist[$mycourse->category] . ' / ' . $mycourse->fullname.' ('.$mycourse->shortname.')'; - if (empty($mycourse->visible)) { - if ($config->displayhiddencourses || $mycourse->id == $currentrefcourseid) { - $hiddenlabel = ' '.get_string('hiddencourse', 'subcourse'); - $options[$mycourse->id] = $courselabel.$hiddenlabel; - } - } else { - $options[$mycourse->id] = $courselabel; - } - } + $mform->addElement('course', 'refcourse', get_string('refcourselabel', 'subcourse'), ['limittoenrolled' => 1]); - $mform->addElement('autocomplete', 'refcourse', get_string('refcourselabel', 'subcourse'), $options); - - 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'));