Category selected defaults to first one available instead of first with studyplans

This commit is contained in:
PMKuipers 2023-12-01 11:14:46 +01:00
parent 97552704ce
commit e092758ff1

View File

@ -46,14 +46,11 @@ if ($categoryid > 0) {
$studyplancontext = $systemcontext;
}
} else {
// If no context is selected, find the first available one.
// If no context is selected, find the first available context for this user.
$availablecontexts = courseservice::list_accessible_categories_with_usage("edit");
$contextid = 1; // Fallback to system context.
foreach ($availablecontexts as $ctx) {
if ($ctx->count > 0) {
$contextid = $ctx->ctxid;
break;
}
if (count($availablecontexts) > 0) {
$contextid = $availablecontexts[0]->ctxid;
}
// Reload page with selected category.
$url = new \moodle_url('/local/treestudyplan/edit-plan.php', ["contextid" => $contextid]);