fix score comments
This commit is contained in:
@@ -231,18 +231,36 @@ class ScoreCommentController extends BaseController
|
||||
$rawCommentsBuilder->groupEnd();
|
||||
}
|
||||
|
||||
if (!$isAllSections && $classSectionId > 0) {
|
||||
// Prefer the exact class-section row over legacy NULL class-section rows.
|
||||
// Without this, duplicate rows can overwrite each other unpredictably.
|
||||
$rawCommentsBuilder
|
||||
->orderBy("CASE WHEN class_section_id = {$classSectionId} THEN 0 ELSE 1 END", '', false)
|
||||
->orderBy('id', 'DESC');
|
||||
} else {
|
||||
$rawCommentsBuilder->orderBy('id', 'DESC');
|
||||
}
|
||||
|
||||
$rawComments = $rawCommentsBuilder->findAll();
|
||||
|
||||
$existingAttendance = [];
|
||||
foreach ($rawComments as $c) {
|
||||
$sid = (int)$c['student_id'];
|
||||
$typ = (string)$c['score_type'];
|
||||
$sid = (int) $c['student_id'];
|
||||
$typ = strtolower(trim((string) $c['score_type']));
|
||||
|
||||
// The query is ordered with the best row first. Do not let legacy/older
|
||||
// duplicate rows overwrite the selected comment/review.
|
||||
if (isset($comments[$sid][$typ])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$comments[$sid][$typ] = [
|
||||
'comment' => $c['comment'] ?? null,
|
||||
'comment_review' => $c['comment_review'] ?? null,
|
||||
'commented_by' => $c['commented_by'] ?? null,
|
||||
'reviewed_by' => $c['reviewed_by'] ?? null,
|
||||
];
|
||||
|
||||
if ($typ === 'attendance') {
|
||||
$existingAttendance[$sid] = $c;
|
||||
}
|
||||
@@ -435,6 +453,16 @@ class ScoreCommentController extends BaseController
|
||||
$existingQuery->groupEnd();
|
||||
}
|
||||
|
||||
if (is_int($classSectionId) && $classSectionId > 0) {
|
||||
// Prefer updating the real class-section row. If only a legacy NULL row
|
||||
// exists, it will be picked next and migrated to the class section below.
|
||||
$existingQuery
|
||||
->orderBy("CASE WHEN class_section_id = {$classSectionId} THEN 0 ELSE 1 END", '', false)
|
||||
->orderBy('id', 'DESC');
|
||||
} else {
|
||||
$existingQuery->orderBy('id', 'DESC');
|
||||
}
|
||||
|
||||
$existing = $existingQuery->first();
|
||||
|
||||
$data = [
|
||||
|
||||
Reference in New Issue
Block a user