Skip to content

Commit 4623f07

Browse files
authored
Merge pull request #6128 from christianbeeznest/palace-22455
Exercise: Add automatic feedback comments to email notification - refs BT#22455
2 parents d2c57d6 + 2f7f85c commit 4623f07

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

main/exercise/exercise_report.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,13 @@
312312
if (isset($_POST['send_notification'])) {
313313
//@todo move this somewhere else
314314
$subject = get_lang('ExamSheetVCC');
315-
$message = isset($_POST['notification_content']) ? $_POST['notification_content'] : '';
315+
$message = $_POST['notification_content'] ?? '';
316+
317+
$feedbackComments = ExerciseLib::getFeedbackComments($id);
318+
$message .= "<div style='padding:10px; border:1px solid #ddd; border-radius:5px;'>";
319+
$message .= $feedbackComments;
320+
$message .= "</div>";
321+
316322
MessageManager::send_message_simple(
317323
$student_id,
318324
$subject,

main/inc/lib/exercise.lib.php

+59
Original file line numberDiff line numberDiff line change
@@ -7416,4 +7416,63 @@ private static function subscribeSessionWhenFinishedFailure(int $exerciseId): vo
74167416
);
74177417
}
74187418
}
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+
}
74197478
}

0 commit comments

Comments
 (0)