Fixes for page base

This commit is contained in:
PMKuipers 2023-08-03 18:45:13 +02:00
parent 0a994d82bb
commit c855232ee4

View File

@ -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]);
}