Cleanup - and added proper check on available coaching studyplans
This commit is contained in:
parent
39d184c2e9
commit
5bd10de529
2 changed files with 7 additions and 5 deletions
|
@ -499,17 +499,14 @@ class studyplan {
|
||||||
if ($DB->count_records('local_treestudyplan_page', ['studyplan_id' => $this->id]) > 0) {
|
if ($DB->count_records('local_treestudyplan_page', ['studyplan_id' => $this->id]) > 0) {
|
||||||
return success::fail('cannot delete studyplan that still has pages');
|
return success::fail('cannot delete studyplan that still has pages');
|
||||||
} else {
|
} 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]);
|
$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_cohort", ["studyplan_id" => $this->id]);
|
||||||
//
|
|
||||||
$DB->delete_records("local_treestudyplan_user", ["studyplan_id" => $this->id]);
|
$DB->delete_records("local_treestudyplan_user", ["studyplan_id" => $this->id]);
|
||||||
//
|
//
|
||||||
$DB->delete_records('local_treestudyplan', ['id' => $this->id]);
|
$DB->delete_records('local_treestudyplan', ['id' => $this->id]);
|
||||||
return success::success();
|
return success::success();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
7
lib.php
7
lib.php
|
@ -198,10 +198,15 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) {
|
||||||
} else {
|
} else {
|
||||||
$hideprimaryhrefs[] = "/local/treestudyplan/edit-plan.php";
|
$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")) &&
|
if ( (premium::enabled() && \get_config("local_treestudyplan","enablecoach")) &&
|
||||||
(has_capability('local/treestudyplan:coach', context_system::instance())
|
(has_capability('local/treestudyplan:coach', context_system::instance())
|
||||||
|| webservicehelper::has_capability_in_any_category('local/treestudyplan:coach')
|
|| 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(
|
$node = navigation_node::create(
|
||||||
get_string("link_coach", "local_treestudyplan"),
|
get_string("link_coach", "local_treestudyplan"),
|
||||||
|
|
Loading…
Reference in a new issue