| 
					
				 | 
			
			
				@@ -17,49 +17,53 @@ class Teacherview { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private $cmid; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private $gradeimporterid; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private $context; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private $table; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private $cellstyle = "border:1px solid black"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public function __construct(int $cmid, int $gradeimporterid) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $this->$cmid = $cmid; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $this->$gradeimporterid = $gradeimporterid; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $this->context = context_module::instance($this->get_cmid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $this->$table = make_table($cmid, $gradeimporterid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private $cellstyle = "border:1px solid black; text-align:center"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public function __construct (int $cmid, int $gradeimporterid) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $this->cmid = $cmid; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $this->gradeimporterid = $gradeimporterid; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $this->context = context_module::instance($cmid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private function get_cmid() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private function get_cmid () { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return $this->cmid; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private function get_gradeimporterid() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private function get_gradeimporterid () { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return $this->gradeimporterid; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private function get_context() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private function get_context () { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return $this->context; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private function get_cellstyle() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private function get_cellstyle () { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return $this->cellstyle; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public function get_table() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return $this->table; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private function make_table() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public function make_table () { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         global $DB, $CFG; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // Prepare variables 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $studentlist = get_studentlist(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $studentlist = $this->get_studentlist(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $submissions = $this->get_submissions(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // Create table 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         $table = new html_table(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         $table->align = array('center'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         $table->attributes = array('class' => 'generaltable mod_index'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $table->head = get_table_head(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return $table; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $submissions = $this->get_submissions(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (!$submissions) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $this->no_submissions(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $table->data[] = $this->get_table_head($submissions); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        foreach ($studentlist as $student) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $table->data[] = $this->get_studentsubmissions($student, $submissions); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return html_writer::table($table); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private function get_studentlist() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private function get_studentlist () { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // Get students list with userid as key and fullname as value 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         $enrolledusers = get_enrolled_users($this->get_context(), 'mod/gradeimporter:view', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                         0, 'u.id, u.firstname, u.lastname', 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -67,38 +71,93 @@ class Teacherview { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                     ); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         $studentlist = array(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         foreach ($enrolledusers as $user) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $userslist[$user->id] = array('name' => $user->firstname." ".$user->lastname); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $studentlist[$user->id] = array('name' => $user->firstname." ".$user->lastname, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                            'id' => $user->id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return $studentlist; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private function get_table_head() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        global $CFG; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $tp = $CFG->prefix; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private function get_table_head ($submissions) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // Creates teacher view table head 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $head = new html_table_row(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        // Creates name column header 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $cell = new html_table_cell(get_string('nameCol', 'gradeimporter')); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $cell->style = $this->get_cellstyle(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $cell->colspan = 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $header = new html_table_row(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // Add name header to header row 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $header->cells[] = $cell; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $header->cells[] = $this->make_cell(get_string('nameCol', 'gradeimporter'), 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        // Get Submissions names and ids 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $sql = "SELECT id, name, type 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                FROM {$tp}gradeimporter_submission 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                WHERE gradeimporterid = {$this->get_gradeimporterid()} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                ORDER BY type, id"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $submissions = $DB->get_records($sql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         foreach ($submissions as $submission) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             // $subname = editSub($submission->name, $gradeimporterid, $cmid, $submission->id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $cell = new html_table_cell($submission->name); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $cell->colspan = 2; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $cell->style = $this->get_cellstyle(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $header->cells[] = $cell; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $header->cells[] = $this->make_cell($submission->name, 2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return $header; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private function get_studentsubmissions ($student, $submissions) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        global $DB; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // Create new row for the student 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $row = new html_table_row(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // Set first cell of the row as the students fullname 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $row->cells[] = $this->make_cell($student["name"], 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // Foreach submission checks if student has a feedback for it 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // If they have, fill it with grade + filename (possibly grade+link to full feedback) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // If they don't have fill it with grade and filename as - 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        foreach ($submissions as $submission) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $feedback = $DB->get_record('gradeimporter_feedback', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                        ['submissionid' => $submission->id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                            'studentid' => $student['id']] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                        ); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if ($feedback) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                $fileurl = $this->feedback_url($feedback); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                $grade = $feedback->grade; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                $fileurl = '-'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                $grade = '-'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $row->cells[] = $this->make_cell($grade, 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $row->cells[] = $this->make_cell($fileurl, 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return $row; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private function get_submissions () { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        global $CFG, $DB; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // Get table prefix 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $tp = $CFG->prefix; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // Build Query 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $sql = "SELECT id, name, type 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                FROM {$tp}gradeimporter_submission 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                WHERE gradeimporterid ={$this->get_gradeimporterid()} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                ORDER BY type, id"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // Query DB 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $submissions = $DB->get_records_sql($sql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // Return submissions 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return $submissions; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private function no_submissions () { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        echo "No submissions"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private function feedback_url ($feedback) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $url = moodle_url::make_pluginfile_url($feedback->contextid, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                            'mod_gradeimporter', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                            'submissionfiles', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                            0, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                            "/", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                            $feedback->name, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                            true 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                        ); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return "<a href='{$url}'>$feedback->name</a>"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private function make_cell ($text, $colspan) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $cell = new html_table_cell($text); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $cell->style = $this->get_cellstyle(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $cell->colspan = $colspan; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return $cell; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |