@@ -7416,4 +7416,63 @@ private static function subscribeSessionWhenFinishedFailure(int $exerciseId): vo
7416
7416
);
7417
7417
}
7418
7418
}
7419
+
7420
+ /**
7421
+ * Get formatted feedback comments for an exam attempt.
7422
+ */
7423
+ public static function getFeedbackComments (int $ examId ): string
7424
+ {
7425
+ $ TBL_TRACK_ATTEMPT = Database::get_main_table (TABLE_STATISTIC_TRACK_E_ATTEMPT );
7426
+ $ TBL_QUIZ_QUESTION = Database::get_course_table (TABLE_QUIZ_QUESTION );
7427
+
7428
+ $ sql = "SELECT ta.question_id, ta.teacher_comment, q.question AS title
7429
+ FROM $ TBL_TRACK_ATTEMPT ta
7430
+ INNER JOIN $ TBL_QUIZ_QUESTION q ON ta.question_id = q.iid
7431
+ WHERE ta.exe_id = $ examId
7432
+ AND ta.teacher_comment IS NOT NULL
7433
+ AND ta.teacher_comment != ''
7434
+ GROUP BY ta.question_id
7435
+ ORDER BY q.position ASC, ta.id ASC " ;
7436
+
7437
+ $ result = Database::query ($ sql );
7438
+ $ commentsByQuestion = [];
7439
+
7440
+ while ($ row = Database::fetch_array ($ result )) {
7441
+ $ questionId = $ row ['question_id ' ];
7442
+ $ questionTitle = Security::remove_XSS ($ row ['title ' ]);
7443
+ $ comment = Security::remove_XSS (trim (strip_tags ($ row ['teacher_comment ' ])));
7444
+
7445
+ if (!empty ($ comment )) {
7446
+ if (!isset ($ commentsByQuestion [$ questionId ])) {
7447
+ $ commentsByQuestion [$ questionId ] = [
7448
+ 'title ' => $ questionTitle ,
7449
+ 'comments ' => [],
7450
+ ];
7451
+ }
7452
+ $ commentsByQuestion [$ questionId ]['comments ' ][] = $ comment ;
7453
+ }
7454
+ }
7455
+
7456
+ if (empty ($ commentsByQuestion )) {
7457
+ return "<p> " . get_lang ('NoAdditionalComments ' ) . "</p> " ;
7458
+ }
7459
+
7460
+ $ output = "<h3> " . get_lang ('TeacherFeedback ' ) . "</h3> " ;
7461
+ $ output .= "<table border='1' cellpadding='5' cellspacing='0' width='100%' style='border-collapse: collapse;'> " ;
7462
+
7463
+ foreach ($ commentsByQuestion as $ questionId => $ data ) {
7464
+ $ output .= "<tr>
7465
+ <td><b> " . get_lang ('Question ' ) . " # $ questionId:</b> " . $ data ['title ' ] . "</td>
7466
+ </tr> " ;
7467
+ foreach ($ data ['comments ' ] as $ comment ) {
7468
+ $ output .= "<tr>
7469
+ <td style='padding-left: 20px;'><i> " . get_lang ('Feedback ' ) . ":</i> $ comment</td>
7470
+ </tr> " ;
7471
+ }
7472
+ }
7473
+
7474
+ $ output .= "</table> " ;
7475
+
7476
+ return $ output ;
7477
+ }
7419
7478
}
0 commit comments