diff --git a/main/exercise/exercise_report.php b/main/exercise/exercise_report.php index e3494aef79d..9b027b00ef3 100755 --- a/main/exercise/exercise_report.php +++ b/main/exercise/exercise_report.php @@ -312,7 +312,13 @@ if (isset($_POST['send_notification'])) { //@todo move this somewhere else $subject = get_lang('ExamSheetVCC'); - $message = isset($_POST['notification_content']) ? $_POST['notification_content'] : ''; + $message = $_POST['notification_content'] ?? ''; + + $feedbackComments = ExerciseLib::getFeedbackComments($id); + $message .= "
"; + $message .= $feedbackComments; + $message .= "
"; + MessageManager::send_message_simple( $student_id, $subject, diff --git a/main/inc/lib/exercise.lib.php b/main/inc/lib/exercise.lib.php index 58eec857987..32d53a14a97 100644 --- a/main/inc/lib/exercise.lib.php +++ b/main/inc/lib/exercise.lib.php @@ -7416,4 +7416,63 @@ private static function subscribeSessionWhenFinishedFailure(int $exerciseId): vo ); } } + + /** + * Get formatted feedback comments for an exam attempt. + */ + public static function getFeedbackComments(int $examId): string + { + $TBL_TRACK_ATTEMPT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); + $TBL_QUIZ_QUESTION = Database::get_course_table(TABLE_QUIZ_QUESTION); + + $sql = "SELECT ta.question_id, ta.teacher_comment, q.question AS title + FROM $TBL_TRACK_ATTEMPT ta + INNER JOIN $TBL_QUIZ_QUESTION q ON ta.question_id = q.iid + WHERE ta.exe_id = $examId + AND ta.teacher_comment IS NOT NULL + AND ta.teacher_comment != '' + GROUP BY ta.question_id + ORDER BY q.position ASC, ta.id ASC"; + + $result = Database::query($sql); + $commentsByQuestion = []; + + while ($row = Database::fetch_array($result)) { + $questionId = $row['question_id']; + $questionTitle = Security::remove_XSS($row['title']); + $comment = Security::remove_XSS(trim(strip_tags($row['teacher_comment']))); + + if (!empty($comment)) { + if (!isset($commentsByQuestion[$questionId])) { + $commentsByQuestion[$questionId] = [ + 'title' => $questionTitle, + 'comments' => [], + ]; + } + $commentsByQuestion[$questionId]['comments'][] = $comment; + } + } + + if (empty($commentsByQuestion)) { + return "

" . get_lang('NoAdditionalComments') . "

"; + } + + $output = "

" . get_lang('TeacherFeedback') . "

"; + $output .= ""; + + foreach ($commentsByQuestion as $questionId => $data) { + $output .= " + + "; + foreach ($data['comments'] as $comment) { + $output .= " + + "; + } + } + + $output .= "
" . get_lang('Question') . " #$questionId: " . $data['title'] . "
" . get_lang('Feedback') . ": $comment
"; + + return $output; + } }