diff --git a/edit-plan.php b/edit-plan.php index ff6cee1..4a8041d 100644 --- a/edit-plan.php +++ b/edit-plan.php @@ -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]);