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 = [];
$hwEnteredAt = [];
$homeworkSubmissionCounts = [];
foreach ($rows as $r) {
$csid = (int)($r['class_section_id'] ?? 0);
$hi = (int)($r['homework_index'] ?? 0);
@@ -94,6 +95,7 @@ class HomeworkTrackingController extends BaseController
$hasHomework[$csid][$hi] = true;
$dateStr = substr((string)($r['first_created'] ?? ''), 0, 10);
$hwEnteredAt[$csid][$hi] = $dateStr ?: null;
$homeworkSubmissionCounts[$csid] = ($homeworkSubmissionCounts[$csid] ?? 0) + 1;
}
}
@@ -217,6 +219,7 @@ class HomeworkTrackingController extends BaseController
'teachers' => $teachersPage,
'hasHomework' => $hasHomework,
'hwEnteredAt' => $hwEnteredAt,
'homeworkSubmissionCounts' => $homeworkSubmissionCounts,
'hasHomeworkByDate' => $hasHomeworkByDate,
'hwEnteredAtByDate' => $hwEnteredAtByDate,
'page' => $page,
+10 -6
View File
@@ -297,12 +297,16 @@ class TeacherController extends BaseController
$schoolYear = $forYear ?: ((string)($this->schoolYear ?? 'Not Set'));
$teachers = $this->teacherModel->getTeachersAndTAs();
// Prefer class sections for the selected year, fallback to all if none
$classSections = $classSectionModel
->where('school_year', $schoolYear)
->orderBy('class_section_name', 'ASC')
->findAll();
if (empty($classSections)) {
// Prefer class sections for the selected year if the column exists, otherwise fallback to all.
if ($this->db->fieldExists('school_year', 'classSection')) {
$classSections = $classSectionModel
->where('school_year', $schoolYear)
->orderBy('class_section_name', 'ASC')
->findAll();
if (empty($classSections)) {
$classSections = $classSectionModel->orderBy('class_section_name', 'ASC')->findAll();
}
} else {
$classSections = $classSectionModel->orderBy('class_section_name', 'ASC')->findAll();
}
+3 -3
View File
@@ -34,11 +34,11 @@ class TeacherModel extends Model
public function getTeachersAndTAs(): array
{
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('roles r', 'r.id = ur.role_id')
->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')
->get()
->getResultArray();
@@ -72,4 +72,4 @@ public function getTeachersAndTAs(): array
->get()
->getResultArray();
}
}
}
+80 -52
View File
@@ -144,58 +144,86 @@
<span class="text-muted small"><?= count($entries) ?> record<?= count($entries) === 1 ? '' : 's' ?></span>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered table-hover align-middle mb-0" data-no-mgmt-sticky>
<thead class="table-light">
<tr>
<th>Class</th>
<th>Subject</th>
<th>Unit</th>
<th>Unit title</th>
<th>Chapter / Surah</th>
<th>Updated</th>
<th style="min-width: 170px;">Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($entries)): ?>
<tr>
<td colspan="7" class="text-center text-muted">No curriculum records yet.</td>
</tr>
<?php else: ?>
<?php foreach ($entries as $entry): ?>
<?php
$subjectLabel = $subjectLabels[$entry['subject']] ?? ucfirst($entry['subject'] ?? '');
$updatedAt = $entry['updated_at'] ?? $entry['created_at'] ?? '';
$updatedDisplay = '';
if ($updatedAt) {
try {
$updatedDisplay = (new \DateTime($updatedAt))->format('M d, Y H:i');
} catch (\Exception $e) {
$updatedDisplay = $updatedAt;
}
}
?>
<tr>
<td><?= esc(($entry['class_name'] ?? '') ?: '—') ?></td>
<td><?= esc($subjectLabel) ?></td>
<td><?= $entry['unit_number'] ? esc((string)$entry['unit_number']) : '—' ?></td>
<td><?= esc(($entry['unit_title'] ?? '') ?: '—') ?></td>
<td><?= esc(($entry['chapter_name'] ?? '') ?: '—') ?></td>
<td><?= esc($updatedDisplay ?: '—') ?></td>
<td class="d-flex gap-2 flex-wrap">
<a href="<?= site_url('administrator/subject-curriculum/edit/' . $entry['id']) ?>" class="btn btn-sm btn-outline-primary">Edit</a>
<form action="<?= site_url('administrator/subject-curriculum/delete/' . $entry['id']) ?>" method="post" onsubmit="return confirm('Remove this curriculum entry?');">
<?= csrf_field() ?>
<button type="submit" class="btn btn-sm btn-outline-danger">Delete</button>
</form>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
<?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">
<table class="table table-bordered table-hover align-middle mb-0" data-no-mgmt-sticky>
<thead class="table-light">
<tr>
<th>Subject</th>
<th>Unit</th>
<th>Unit title</th>
<th>Chapter / Surah</th>
<th>Updated</th>
<th style="min-width: 170px;">Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($classEntries as $entry): ?>
<?php
$subjectLabel = $subjectLabels[$entry['subject']] ?? ucfirst($entry['subject'] ?? '');
$updatedAt = $entry['updated_at'] ?? $entry['created_at'] ?? '';
$updatedDisplay = '';
if ($updatedAt) {
try {
$updatedDisplay = (new \DateTime($updatedAt))->format('M d, Y H:i');
} catch (\Exception $e) {
$updatedDisplay = $updatedAt;
}
}
?>
<tr>
<td><?= esc($subjectLabel) ?></td>
<td><?= $entry['unit_number'] ? esc((string)$entry['unit_number']) : '—' ?></td>
<td><?= esc(($entry['unit_title'] ?? '') ?: '—') ?></td>
<td><?= esc(($entry['chapter_name'] ?? '') ?: '—') ?></td>
<td><?= esc($updatedDisplay ?: '—') ?></td>
<td class="d-flex gap-2 flex-wrap">
<a href="<?= site_url('administrator/subject-curriculum/edit/' . $entry['id']) ?>" class="btn btn-sm btn-outline-primary">Edit</a>
<form action="<?= site_url('administrator/subject-curriculum/delete/' . $entry['id']) ?>" method="post" onsubmit="return confirm('Remove this curriculum entry?');">
<?= csrf_field() ?>
<button type="submit" class="btn btn-sm btn-outline-danger">Delete</button>
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
</div>
</div>
@@ -63,7 +63,15 @@
</thead>
<tbody>
<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>
</tbody>
</table>
@@ -198,10 +206,12 @@ document.addEventListener('DOMContentLoaded', function () {
if (!teachers || teachers.length === 0) {
var emptyRow = document.createElement('tr');
var emptyCell = document.createElement('td');
emptyCell.colSpan = 9;
emptyCell.className = 'text-center text-muted';
emptyCell.textContent = 'No teachers found.';
emptyRow.appendChild(emptyCell);
for (var i = 0; i < 8; i++) {
emptyRow.appendChild(document.createElement('td'));
}
tbody.appendChild(emptyRow);
} else {
teachers.forEach(function (teacher, index) {
@@ -312,7 +322,10 @@ document.addEventListener('DOMContentLoaded', function () {
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)) : '');
fetch(url, {
+5 -1
View File
@@ -70,7 +70,8 @@ $todayYmd = local_date(utc_now(), 'Y-m-d');
<tr>
<th class="sticky-col">Grade</th>
<th class="sticky-col-2" style="min-width:300px; width:300px;">Teacher &amp; TAs</th>
<?php foreach (($headerDates ?? []) as $i => $label): $ymd = $sundays[$i] ?? ''; ?>
<th class="text-center">HW Submitted</th>
<?php foreach (($headerDates ?? []) as $i => $label): $ymd = $sundays[$i] ?? ''; ?>
<?php $isCal = !empty($eventDays[$ymd]); $isFuture = ($ymd > $todayYmd); ?>
<th class="text-center <?= $isCal ? 'bg-warning' : ($isFuture ? 'bg-future' : '') ?>" title="<?= esc($ymd) ?>"><?= esc($label) ?></th>
<?php endforeach; ?>
@@ -100,6 +101,9 @@ $todayYmd = local_date(utc_now(), 'Y-m-d');
<?php endif; ?>
<div><strong>TA<?= count($taNames) !== 1 ? 's' : '' ?>:</strong> <?= !empty($taNames) ? esc(implode(', ', $taNames)) : '—' ?></div>
</td>
<td class="text-center">
<?= (int)($homeworkSubmissionCounts[$csid] ?? 0) ?>
</td>
<?php foreach (($sundays ?? []) as $ymd): ?>
<?php if (!empty($eventDays[$ymd])): ?>
<td class="bg-warning text-center">—</td>