From c855232ee4dbbaf6d7c21264077b30a6136f637a Mon Sep 17 00:00:00 2001 From: PMKuipers Date: Thu, 3 Aug 2023 18:45:13 +0200 Subject: [PATCH] Fixes for page base --- classes/teachingfinder.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/classes/teachingfinder.php b/classes/teachingfinder.php index e3827e6..17fbb25 100644 --- a/classes/teachingfinder.php +++ b/classes/teachingfinder.php @@ -34,18 +34,18 @@ class teachingfinder { // First find all active study plans - $sql = "SELECT s.id FROM {local_treestudyplan} s + $sql = "SELECT p.id FROM {local_treestudyplan_page} p WHERE startdate <= NOW() and enddate >= NOW()"; - $plan_ids = $DB->get_fieldset_sql($sql, []); + $page_ids = $DB->get_fieldset_sql($sql, []); // then parse them to see if the user has the grading permission in any of them // (Which would make them a teacher for all intents and purposes) - foreach($plan_ids as $planid) { - $sql = "SELECT i.course_id FROM mdl_local_treestudyplan_item i - INNER JOIN mdl_local_treestudyplan_line l ON i.line_id = l.id - WHERE l.studyplan_id = :plan_id AND i.course_id IS NOT NULL"; - $course_ids = $DB->get_fieldset_sql($sql, ["plan_id" => $planid]); + foreach($page_ids as $page_id) { + $sql = "SELECT i.course_id FROM {local_treestudyplan_item} i + INNER JOIN {local_treestudyplan_line} l ON i.line_id = l.id + WHERE l.page_id = :page_id AND i.course_id IS NOT NULL"; + $course_ids = $DB->get_fieldset_sql($sql, ["page_id" => $page_id]); $linked = false; foreach($course_ids as $cid){ @@ -58,7 +58,7 @@ class teachingfinder { if($linked) { - $list[] = $planid; + $list[] = $page_id; } } @@ -67,7 +67,10 @@ class teachingfinder { $DB->delete_records(self::TABLE,["teacher_id"=>$userid]); // And add new records for the found studyplans $now = time(); - foreach($list as $planid){ + foreach($list as $page_id){ + // Retrieve the studyplan id from the page + //TODO: Change this when page management is implemented to return the page instead of the plan + $planid = $DB->get_field("local_treestudyplan_page","studyplan_id",["page_id" => $page_id]); $DB->insert_record(self::TABLE,["teacher_id"=>$userid,"studyplan_id"=>$planid,"update_time"=>$now]); }