Fixes for page base
This commit is contained in:
		
							parent
							
								
									0a994d82bb
								
							
						
					
					
						commit
						c855232ee4
					
				
					 1 changed files with 12 additions and 9 deletions
				
			
		| 
						 | 
					@ -34,18 +34,18 @@ class teachingfinder {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // First find all active study plans
 | 
					        // 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()";
 | 
					            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 
 | 
					        // 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)
 | 
					        // (Which would make them a teacher for all intents and purposes)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        foreach($plan_ids as $planid) {
 | 
					        foreach($page_ids as $page_id) {
 | 
				
			||||||
            $sql = "SELECT i.course_id FROM mdl_local_treestudyplan_item i 
 | 
					            $sql = "SELECT i.course_id FROM {local_treestudyplan_item} i 
 | 
				
			||||||
                    INNER JOIN mdl_local_treestudyplan_line l ON i.line_id = l.id 
 | 
					                    INNER JOIN {local_treestudyplan_line} l ON i.line_id = l.id 
 | 
				
			||||||
                    WHERE l.studyplan_id = :plan_id AND i.course_id IS NOT NULL";
 | 
					                    WHERE l.page_id = :page_id AND i.course_id IS NOT NULL";
 | 
				
			||||||
            $course_ids = $DB->get_fieldset_sql($sql, ["plan_id" => $planid]);
 | 
					            $course_ids = $DB->get_fieldset_sql($sql, ["page_id" => $page_id]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $linked = false;
 | 
					            $linked = false;
 | 
				
			||||||
            foreach($course_ids as $cid){
 | 
					            foreach($course_ids as $cid){
 | 
				
			||||||
| 
						 | 
					@ -58,7 +58,7 @@ class teachingfinder {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if($linked)
 | 
					            if($linked)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                $list[] = $planid;
 | 
					                $list[] = $page_id;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -67,7 +67,10 @@ class teachingfinder {
 | 
				
			||||||
        $DB->delete_records(self::TABLE,["teacher_id"=>$userid]);
 | 
					        $DB->delete_records(self::TABLE,["teacher_id"=>$userid]);
 | 
				
			||||||
        // And add new records for the found studyplans
 | 
					        // And add new records for the found studyplans
 | 
				
			||||||
        $now = time();
 | 
					        $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]);
 | 
					            $DB->insert_record(self::TABLE,["teacher_id"=>$userid,"studyplan_id"=>$planid,"update_time"=>$now]);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Reference in a new issue