Cleanup - and added proper check on available coaching studyplans

This commit is contained in:
PMKuipers 2024-05-22 22:16:47 +02:00
parent 39d184c2e9
commit 5bd10de529
2 changed files with 7 additions and 5 deletions

View File

@ -499,17 +499,14 @@ class studyplan {
if ($DB->count_records('local_treestudyplan_page', ['studyplan_id' => $this->id]) > 0) {
return success::fail('cannot delete studyplan that still has pages');
} else {
// Delete any coach links for this studyplan before deleting the studyplan itself.
// Delete any links to this studyplan before deleting the studyplan itself.
$DB->delete_records("local_treestudyplan_coach", ["studyplan_id" => $this->id]);
// TODO: Check if students and cohorts need to be removed at this time too..
$DB->delete_records("local_treestudyplan_cohort", ["studyplan_id" => $this->id]);
//
$DB->delete_records("local_treestudyplan_user", ["studyplan_id" => $this->id]);
//
$DB->delete_records('local_treestudyplan', ['id' => $this->id]);
return success::success();
}
}
/**

View File

@ -198,10 +198,15 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) {
} else {
$hideprimaryhrefs[] = "/local/treestudyplan/edit-plan.php";
}
$coachsql = "SELECT COUNT('id') FROM {local_treestudyplan_coach} as c
INNER JOIN {local_treestudyplan} AS t ON c.studyplan_id = t.id
WHERE c.user_id = :user_id";
if ( (premium::enabled() && \get_config("local_treestudyplan","enablecoach")) &&
(has_capability('local/treestudyplan:coach', context_system::instance())
|| webservicehelper::has_capability_in_any_category('local/treestudyplan:coach')
) && $DB->count_records("local_treestudyplan_coach",["user_id" => $USER->id]) > 0
) && $DB->count_records_sql($coachsql,["user_id" => $USER->id]) > 0
) {
$node = navigation_node::create(
get_string("link_coach", "local_treestudyplan"),