Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion main/exercise/exercise_report.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 .= "<div style='padding:10px; border:1px solid #ddd; border-radius:5px;'>";
$message .= $feedbackComments;
$message .= "</div>";

MessageManager::send_message_simple(
$student_id,
$subject,
Expand Down
59 changes: 59 additions & 0 deletions main/inc/lib/exercise.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<p>" . get_lang('NoAdditionalComments') . "</p>";
}

$output = "<h3>" . get_lang('TeacherFeedback') . "</h3>";
$output .= "<table border='1' cellpadding='5' cellspacing='0' width='100%' style='border-collapse: collapse;'>";

foreach ($commentsByQuestion as $questionId => $data) {
$output .= "<tr>
<td><b>" . get_lang('Question') . " #$questionId:</b> " . $data['title'] . "</td>
</tr>";
foreach ($data['comments'] as $comment) {
$output .= "<tr>
<td style='padding-left: 20px;'><i>" . get_lang('Feedback') . ":</i> $comment</td>
</tr>";
}
}

$output .= "</table>";

return $output;
}
}
Loading