Ensured all available contexts are listed in the edit form

This commit is contained in:
PMKuipers 2024-08-22 10:46:32 +02:00
parent b0a61d018c
commit 1eb862a3ea

View File

@ -30,6 +30,7 @@ use local_treestudyplan\studyplan;
use local_treestudyplan\debug; use local_treestudyplan\debug;
use local_treestudyplan\studyplanservice; use local_treestudyplan\studyplanservice;
use local_treestudyplan\courseservice; use local_treestudyplan\courseservice;
use local_treestudyplan\contextinfo;
use local_treestudyplan\form\text_integer; use local_treestudyplan\form\text_integer;
use moodle_exception; use moodle_exception;
use stdClass; use stdClass;
@ -184,8 +185,15 @@ class studyplan_editform extends formbase {
[]); []);
$contextlist = []; $contextlist = [];
foreach (courseservice::list_available_categories('edit') as $c) { // Add system if the user has permissions.
$contextlist[$c['context_id']] = implode(" / ", $c['category']['path']); if (has_all_capabilities([courseservice::CAP_EDIT,'moodle/category:viewcourselist'], \context_system::instance())) {
$contextlist[1] = get_string("coresystem");
}
// Add any other contexts the user has access to.
foreach (courseservice::categories_by_capability(courseservice::CAP_EDIT) as $c) {
$ctx = $c->get_context();
$ci = new contextinfo($ctx);
$contextlist[$ctx->id] = implode(" / ", $ci->path(false));
} }
$mform->addElement('autocomplete', 'context_id', $mform->addElement('autocomplete', 'context_id',