update homework tracking

This commit is contained in:
root
2026-04-07 18:42:39 -04:00
parent 05dad52e10
commit 2611730ec6
6 changed files with 117 additions and 65 deletions
@@ -86,6 +86,7 @@ class HomeworkTrackingController extends BaseController
$hasHomework = []; $hasHomework = [];
$hwEnteredAt = []; $hwEnteredAt = [];
$homeworkSubmissionCounts = [];
foreach ($rows as $r) { foreach ($rows as $r) {
$csid = (int)($r['class_section_id'] ?? 0); $csid = (int)($r['class_section_id'] ?? 0);
$hi = (int)($r['homework_index'] ?? 0); $hi = (int)($r['homework_index'] ?? 0);
@@ -94,6 +95,7 @@ class HomeworkTrackingController extends BaseController
$hasHomework[$csid][$hi] = true; $hasHomework[$csid][$hi] = true;
$dateStr = substr((string)($r['first_created'] ?? ''), 0, 10); $dateStr = substr((string)($r['first_created'] ?? ''), 0, 10);
$hwEnteredAt[$csid][$hi] = $dateStr ?: null; $hwEnteredAt[$csid][$hi] = $dateStr ?: null;
$homeworkSubmissionCounts[$csid] = ($homeworkSubmissionCounts[$csid] ?? 0) + 1;
} }
} }
@@ -217,6 +219,7 @@ class HomeworkTrackingController extends BaseController
'teachers' => $teachersPage, 'teachers' => $teachersPage,
'hasHomework' => $hasHomework, 'hasHomework' => $hasHomework,
'hwEnteredAt' => $hwEnteredAt, 'hwEnteredAt' => $hwEnteredAt,
'homeworkSubmissionCounts' => $homeworkSubmissionCounts,
'hasHomeworkByDate' => $hasHomeworkByDate, 'hasHomeworkByDate' => $hasHomeworkByDate,
'hwEnteredAtByDate' => $hwEnteredAtByDate, 'hwEnteredAtByDate' => $hwEnteredAtByDate,
'page' => $page, 'page' => $page,
+5 -1
View File
@@ -297,7 +297,8 @@ class TeacherController extends BaseController
$schoolYear = $forYear ?: ((string)($this->schoolYear ?? 'Not Set')); $schoolYear = $forYear ?: ((string)($this->schoolYear ?? 'Not Set'));
$teachers = $this->teacherModel->getTeachersAndTAs(); $teachers = $this->teacherModel->getTeachersAndTAs();
// Prefer class sections for the selected year, fallback to all if none // Prefer class sections for the selected year if the column exists, otherwise fallback to all.
if ($this->db->fieldExists('school_year', 'classSection')) {
$classSections = $classSectionModel $classSections = $classSectionModel
->where('school_year', $schoolYear) ->where('school_year', $schoolYear)
->orderBy('class_section_name', 'ASC') ->orderBy('class_section_name', 'ASC')
@@ -305,6 +306,9 @@ class TeacherController extends BaseController
if (empty($classSections)) { if (empty($classSections)) {
$classSections = $classSectionModel->orderBy('class_section_name', 'ASC')->findAll(); $classSections = $classSectionModel->orderBy('class_section_name', 'ASC')->findAll();
} }
} else {
$classSections = $classSectionModel->orderBy('class_section_name', 'ASC')->findAll();
}
$classNames = []; $classNames = [];
foreach ($classSections as $section) { foreach ($classSections as $section) {
+2 -2
View File
@@ -34,11 +34,11 @@ class TeacherModel extends Model
public function getTeachersAndTAs(): array public function getTeachersAndTAs(): array
{ {
return $this->db->table('users u') return $this->db->table('users u')
->select('u.id, u.firstname, u.lastname, u.email, u.cellphone, r.name as role') ->select('u.id, u.firstname, u.lastname, u.email, u.cellphone, MIN(r.name) as role')
->join('user_roles ur', 'ur.user_id = u.id') ->join('user_roles ur', 'ur.user_id = u.id')
->join('roles r', 'r.id = ur.role_id') ->join('roles r', 'r.id = ur.role_id')
->whereIn('r.name', ['teacher', 'teacher_assistant']) // ✅ Filter only relevant roles ->whereIn('r.name', ['teacher', 'teacher_assistant']) // ✅ Filter only relevant roles
->groupBy('u.id') ->groupBy('u.id, u.firstname, u.lastname, u.email, u.cellphone')
->orderBy('u.lastname', 'ASC') ->orderBy('u.lastname', 'ASC')
->get() ->get()
->getResultArray(); ->getResultArray();
+37 -9
View File
@@ -144,11 +144,40 @@
<span class="text-muted small"><?= count($entries) ?> record<?= count($entries) === 1 ? '' : 's' ?></span> <span class="text-muted small"><?= count($entries) ?> record<?= count($entries) === 1 ? '' : 's' ?></span>
</div> </div>
<div class="card-body"> <div class="card-body">
<?php if (empty($entries)): ?>
<div class="text-center text-muted">No curriculum records yet.</div>
<?php else: ?>
<?php
$entriesByClass = [];
foreach ($entries as $entry) {
$className = ($entry['class_name'] ?? '') ?: '—';
if (!isset($entriesByClass[$className])) {
$entriesByClass[$className] = [];
}
$entriesByClass[$className][] = $entry;
}
?>
<div class="accordion" id="curriculumAccordion">
<?php $accIndex = 0; ?>
<?php foreach ($entriesByClass as $className => $classEntries): ?>
<?php
$accIndex++;
$collapseId = 'curriculum-class-' . $accIndex;
$headingId = 'curriculum-heading-' . $accIndex;
?>
<div class="accordion-item mb-2">
<h2 class="accordion-header" id="<?= esc($headingId) ?>">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#<?= esc($collapseId) ?>" aria-expanded="false" aria-controls="<?= esc($collapseId) ?>">
<?= esc($className) ?>
<span class="badge bg-secondary ms-2"><?= count($classEntries) ?> entries</span>
</button>
</h2>
<div id="<?= esc($collapseId) ?>" class="accordion-collapse collapse" aria-labelledby="<?= esc($headingId) ?>" data-bs-parent="#curriculumAccordion">
<div class="accordion-body">
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-bordered table-hover align-middle mb-0" data-no-mgmt-sticky> <table class="table table-bordered table-hover align-middle mb-0" data-no-mgmt-sticky>
<thead class="table-light"> <thead class="table-light">
<tr> <tr>
<th>Class</th>
<th>Subject</th> <th>Subject</th>
<th>Unit</th> <th>Unit</th>
<th>Unit title</th> <th>Unit title</th>
@@ -158,12 +187,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php if (empty($entries)): ?> <?php foreach ($classEntries as $entry): ?>
<tr>
<td colspan="7" class="text-center text-muted">No curriculum records yet.</td>
</tr>
<?php else: ?>
<?php foreach ($entries as $entry): ?>
<?php <?php
$subjectLabel = $subjectLabels[$entry['subject']] ?? ucfirst($entry['subject'] ?? ''); $subjectLabel = $subjectLabels[$entry['subject']] ?? ucfirst($entry['subject'] ?? '');
$updatedAt = $entry['updated_at'] ?? $entry['created_at'] ?? ''; $updatedAt = $entry['updated_at'] ?? $entry['created_at'] ?? '';
@@ -177,7 +201,6 @@
} }
?> ?>
<tr> <tr>
<td><?= esc(($entry['class_name'] ?? '') ?: '—') ?></td>
<td><?= esc($subjectLabel) ?></td> <td><?= esc($subjectLabel) ?></td>
<td><?= $entry['unit_number'] ? esc((string)$entry['unit_number']) : '—' ?></td> <td><?= $entry['unit_number'] ? esc((string)$entry['unit_number']) : '—' ?></td>
<td><?= esc(($entry['unit_title'] ?? '') ?: '—') ?></td> <td><?= esc(($entry['unit_title'] ?? '') ?: '—') ?></td>
@@ -192,13 +215,18 @@
</td> </td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
<?php endif; ?>
</tbody> </tbody>
</table> </table>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div> </div>
</div> </div>
@@ -63,7 +63,15 @@
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
<td colspan="9" class="text-center text-muted">Loading...</td> <td class="text-center text-muted">Loading...</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
@@ -198,10 +206,12 @@ document.addEventListener('DOMContentLoaded', function () {
if (!teachers || teachers.length === 0) { if (!teachers || teachers.length === 0) {
var emptyRow = document.createElement('tr'); var emptyRow = document.createElement('tr');
var emptyCell = document.createElement('td'); var emptyCell = document.createElement('td');
emptyCell.colSpan = 9;
emptyCell.className = 'text-center text-muted'; emptyCell.className = 'text-center text-muted';
emptyCell.textContent = 'No teachers found.'; emptyCell.textContent = 'No teachers found.';
emptyRow.appendChild(emptyCell); emptyRow.appendChild(emptyCell);
for (var i = 0; i < 8; i++) {
emptyRow.appendChild(document.createElement('td'));
}
tbody.appendChild(emptyRow); tbody.appendChild(emptyRow);
} else { } else {
teachers.forEach(function (teacher, index) { teachers.forEach(function (teacher, index) {
@@ -312,7 +322,10 @@ document.addEventListener('DOMContentLoaded', function () {
return; return;
} }
tbody.innerHTML = '<tr><td colspan="9" class="text-center text-muted">Loading...</td></tr>'; tbody.innerHTML = '<tr>'
+ '<td class="text-center text-muted">Loading...</td>'
+ '<td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>'
+ '</tr>';
var url = apiList + (selectedYear ? ('?schoolYear=' + encodeURIComponent(selectedYear)) : ''); var url = apiList + (selectedYear ? ('?schoolYear=' + encodeURIComponent(selectedYear)) : '');
fetch(url, { fetch(url, {
+4
View File
@@ -70,6 +70,7 @@ $todayYmd = local_date(utc_now(), 'Y-m-d');
<tr> <tr>
<th class="sticky-col">Grade</th> <th class="sticky-col">Grade</th>
<th class="sticky-col-2" style="min-width:300px; width:300px;">Teacher &amp; TAs</th> <th class="sticky-col-2" style="min-width:300px; width:300px;">Teacher &amp; TAs</th>
<th class="text-center">HW Submitted</th>
<?php foreach (($headerDates ?? []) as $i => $label): $ymd = $sundays[$i] ?? ''; ?> <?php foreach (($headerDates ?? []) as $i => $label): $ymd = $sundays[$i] ?? ''; ?>
<?php $isCal = !empty($eventDays[$ymd]); $isFuture = ($ymd > $todayYmd); ?> <?php $isCal = !empty($eventDays[$ymd]); $isFuture = ($ymd > $todayYmd); ?>
<th class="text-center <?= $isCal ? 'bg-warning' : ($isFuture ? 'bg-future' : '') ?>" title="<?= esc($ymd) ?>"><?= esc($label) ?></th> <th class="text-center <?= $isCal ? 'bg-warning' : ($isFuture ? 'bg-future' : '') ?>" title="<?= esc($ymd) ?>"><?= esc($label) ?></th>
@@ -100,6 +101,9 @@ $todayYmd = local_date(utc_now(), 'Y-m-d');
<?php endif; ?> <?php endif; ?>
<div><strong>TA<?= count($taNames) !== 1 ? 's' : '' ?>:</strong> <?= !empty($taNames) ? esc(implode(', ', $taNames)) : '—' ?></div> <div><strong>TA<?= count($taNames) !== 1 ? 's' : '' ?>:</strong> <?= !empty($taNames) ? esc(implode(', ', $taNames)) : '—' ?></div>
</td> </td>
<td class="text-center">
<?= (int)($homeworkSubmissionCounts[$csid] ?? 0) ?>
</td>
<?php foreach (($sundays ?? []) as $ymd): ?> <?php foreach (($sundays ?? []) as $ymd): ?>
<?php if (!empty($eventDays[$ymd])): ?> <?php if (!empty($eventDays[$ymd])): ?>
<td class="bg-warning text-center">—</td> <td class="bg-warning text-center">—</td>