fix db tables to have school year

This commit is contained in:
root
2026-07-12 01:02:04 -04:00
parent ed11cccecc
commit ec9fca8c45
42 changed files with 988 additions and 195 deletions
+4 -19
View File
@@ -106,14 +106,12 @@ class WhatsappController extends BaseController
$existing = $this->linkModel->where([
'class_section_id' => $sectionId,
'school_year' => $this->schoolYear,
'semester' => $this->semester,
])->first();
$payload = [
'class_section_id' => $sectionId,
'class_section_name' => $sectionName,
'school_year' => $this->schoolYear,
'semester' => $this->semester,
'invite_link' => trim($inviteLink),
'active' => $active,
];
@@ -434,8 +432,6 @@ class WhatsappController extends BaseController
sp.secondparent_lastname AS sp_lastname,
sp.secondparent_email AS sp_email,
sp.secondparent_phone AS sp_phone,
sp.school_year AS sp_school_year,
sp.semester AS sp_semester,
u.id AS u_id,
u.firstname AS u_firstname,
@@ -448,14 +444,6 @@ class WhatsappController extends BaseController
$b->join('users u', 'u.id = sp.firstparent_id', 'left');
// Scope by term using parents table (authoritative for the pairing)
if ($schoolYear !== '') {
$b->where('sp.school_year', $schoolYear);
}
if ($semester !== '') {
$b->where('sp.semester', $semester);
}
$rows = $b->get()->getResultArray();
// Flatten into a single contacts list (primary + second parent as separate rows)
@@ -606,11 +594,10 @@ class WhatsappController extends BaseController
$pb->join('students s', 's.id = sc.student_id', 'inner'); // adjust if your table is named `student` (singular)
$pb->join('users u', 'u.id = s.parent_id', 'inner'); // primary parent lives on students.parent_id
// Second parent row for the same term (allow NULL/'' semester if you sometimes omit it)
// Second parent row for the primary parent.
$pb->join(
'parents sp',
"sp.firstparent_id = u.id
AND sp.school_year = sc.school_year",
'sp.firstparent_id = u.id',
'left'
);
@@ -1202,7 +1189,7 @@ class WhatsappController extends BaseController
/**
* Class mode:
* - Given classSectionId, find students (student_class) for the term
* - Given classSectionId, find students (student_class) for the year
* - Map to primaries (users) and second-parents (parents)
* - Return one bundle **per primary parent** (so each parent gets their own email)
*/
@@ -1215,7 +1202,6 @@ class WhatsappController extends BaseController
$stuRows = $this->db->table('student_class')
->select('student_id')
->where('school_year', $this->schoolYear)
->where('semester', $this->semester)
->where('class_section_id', $classSectionId)
->get()->getResultArray();
if (empty($stuRows)) return [];
@@ -1302,7 +1288,7 @@ class WhatsappController extends BaseController
/**
* All mode:
* - Iterate all distinct class_section_id in student_class (for the term)
* - Iterate all distinct class_section_id in student_class (for the year)
* - Reuse class bundles per section and flatten
*/
private function bundlesForAllParentsAllClasses(array $linkBySection): array
@@ -1310,7 +1296,6 @@ class WhatsappController extends BaseController
$secRows = $this->db->table('student_class')
->select('DISTINCT class_section_id', false)
->where('school_year', $this->schoolYear)
->where('semester', $this->semester)
->orderBy('class_section_id', 'ASC')
->get()->getResultArray();