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; $studyplancontext = $systemcontext;
} }
} else { } 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"); $availablecontexts = courseservice::list_accessible_categories_with_usage("edit");
$contextid = 1; // Fallback to system context. $contextid = 1; // Fallback to system context.
foreach ($availablecontexts as $ctx) { if (count($availablecontexts) > 0) {
if ($ctx->count > 0) { $contextid = $availablecontexts[0]->ctxid;
$contextid = $ctx->ctxid;
break;
}
} }
// Reload page with selected category. // Reload page with selected category.
$url = new \moodle_url('/local/treestudyplan/edit-plan.php', ["contextid" => $contextid]); $url = new \moodle_url('/local/treestudyplan/edit-plan.php', ["contextid" => $contextid]);