fix is_active student flag and apply it in all pages
This commit is contained in:
+109
-21
@@ -292,25 +292,42 @@ class StudentModel extends Model
|
||||
|
||||
public function getByClassAndYear($class_section_id, $school_year, ?string $semester = null): array
|
||||
{
|
||||
$studentClassModel = new \App\Models\StudentClassModel();
|
||||
$school_year = trim((string) $school_year);
|
||||
|
||||
$builder = $studentClassModel
|
||||
->select('student_id')
|
||||
->where('class_section_id', $class_section_id)
|
||||
->where('school_year', $school_year);
|
||||
$builder = $this->select('students.*, e.enrollment_status, e.is_withdrawn')
|
||||
->join('student_class sc', 'sc.student_id = students.id', 'inner')
|
||||
->join(
|
||||
'enrollments e',
|
||||
'e.student_id = students.id AND e.school_year = ' . $this->db->escape($school_year),
|
||||
'left'
|
||||
)
|
||||
->where('sc.class_section_id', $class_section_id)
|
||||
->where('sc.school_year', $school_year)
|
||||
->groupStart()
|
||||
->where('students.is_active', 1)
|
||||
->orWhere("LOWER(TRIM(e.enrollment_status)) IN ('denied','withdrawn','widthran','widthrawan','withdrawan','waitlist')", null, false)
|
||||
->orWhere('e.is_withdrawn', 1)
|
||||
->groupEnd();
|
||||
|
||||
$studentIds = $builder->findAll();
|
||||
return $builder
|
||||
->distinct()
|
||||
->orderBy('students.firstname', 'ASC')
|
||||
->orderBy('students.lastname', 'ASC')
|
||||
->findAll();
|
||||
}
|
||||
|
||||
$studentIds = array_column($studentIds, 'student_id');
|
||||
public function getActiveByClassAndYear($class_section_id, $school_year, ?string $semester = null): array
|
||||
{
|
||||
$school_year = trim((string) $school_year);
|
||||
|
||||
if (empty($studentIds)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $this->whereIn('id', $studentIds)
|
||||
->where('is_active', 1)
|
||||
->orderBy('firstname', 'ASC')
|
||||
->orderBy('lastname', 'ASC')
|
||||
return $this->select('students.*')
|
||||
->join('student_class sc', 'sc.student_id = students.id', 'inner')
|
||||
->where('sc.class_section_id', $class_section_id)
|
||||
->where('sc.school_year', $school_year)
|
||||
->where('students.is_active', 1)
|
||||
->distinct()
|
||||
->orderBy('students.firstname', 'ASC')
|
||||
->orderBy('students.lastname', 'ASC')
|
||||
->findAll();
|
||||
}
|
||||
|
||||
@@ -322,12 +339,36 @@ class StudentModel extends Model
|
||||
return [];
|
||||
}
|
||||
|
||||
return $this->select('students.id, students.school_id, students.firstname, students.lastname')
|
||||
return $this->select('students.id, students.school_id, students.firstname, students.lastname, students.is_active, e.enrollment_status, e.is_withdrawn')
|
||||
->join('student_class', 'student_class.student_id = students.id', 'inner')
|
||||
->join('enrollments e', 'e.student_id = students.id AND e.school_year = ' . $this->db->escape($schoolYear), 'left')
|
||||
->where('students.parent_id', $parentId)
|
||||
->where('student_class.school_year', $schoolYear)
|
||||
->groupStart()
|
||||
->where('students.is_active', 1)
|
||||
->orWhere("LOWER(TRIM(e.enrollment_status)) IN ('denied','withdrawn','widthran','widthrawan','withdrawan','waitlist')", null, false)
|
||||
->orWhere('e.is_withdrawn', 1)
|
||||
->groupEnd()
|
||||
->groupBy('students.id, students.school_id, students.firstname, students.lastname, students.is_active, e.enrollment_status, e.is_withdrawn')
|
||||
->orderBy('students.lastname', 'ASC')
|
||||
->orderBy('students.firstname', 'ASC')
|
||||
->findAll();
|
||||
}
|
||||
|
||||
public function getActiveByParentAndYear(int $parentId, string $schoolYear): array
|
||||
{
|
||||
$schoolYear = trim($schoolYear);
|
||||
|
||||
if ($parentId <= 0 || $schoolYear === '') {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $this->select('students.id, students.school_id, students.firstname, students.lastname, students.is_active')
|
||||
->join('student_class', 'student_class.student_id = students.id', 'inner')
|
||||
->where('students.parent_id', $parentId)
|
||||
->where('students.is_active', 1)
|
||||
->where('student_class.school_year', $schoolYear)
|
||||
->groupBy('students.id, students.school_id, students.firstname, students.lastname')
|
||||
->where('students.is_active', 1)
|
||||
->groupBy('students.id, students.school_id, students.firstname, students.lastname, students.is_active')
|
||||
->orderBy('students.lastname', 'ASC')
|
||||
->orderBy('students.firstname', 'ASC')
|
||||
->findAll();
|
||||
@@ -443,16 +484,28 @@ class StudentModel extends Model
|
||||
$builder = $this->builder();
|
||||
|
||||
$builder
|
||||
->select('students.id AS student_id, students.school_id, students.firstname, students.lastname, sc.class_section_id')
|
||||
->select('students.id AS student_id, students.school_id, students.firstname, students.lastname, students.is_active, sc.class_section_id, e.enrollment_status, e.is_withdrawn')
|
||||
->join('student_class sc', 'sc.student_id = students.id', 'inner')
|
||||
->where('sc.class_section_id', $classSectionId)
|
||||
->where('students.is_active', 1);
|
||||
->where('sc.class_section_id', $classSectionId);
|
||||
|
||||
// Optional term scoping (safe no-ops if null)
|
||||
if ($schoolYear !== null) {
|
||||
$builder->where('sc.school_year', $schoolYear);
|
||||
$builder->join(
|
||||
'enrollments e',
|
||||
'e.student_id = students.id AND e.school_year = ' . $this->db->escape($schoolYear),
|
||||
'left'
|
||||
);
|
||||
} else {
|
||||
$builder->join('enrollments e', 'e.student_id = students.id', 'left');
|
||||
}
|
||||
|
||||
$builder->groupStart()
|
||||
->where('students.is_active', 1)
|
||||
->orWhere("LOWER(TRIM(e.enrollment_status)) IN ('denied','withdrawn','widthran','widthrawan','withdrawan','waitlist')", null, false)
|
||||
->orWhere('e.is_withdrawn', 1)
|
||||
->groupEnd();
|
||||
|
||||
// Prevent accidental dupes if student_class has multiple rows
|
||||
$builder->distinct();
|
||||
$builder->orderBy('students.lastname', 'ASC')
|
||||
@@ -472,6 +525,41 @@ class StudentModel extends Model
|
||||
return $results ?: [];
|
||||
}
|
||||
|
||||
public function getActiveStudentInfoByClassSectionId($classSectionId, ?string $semester = null, ?string $schoolYear = null): array
|
||||
{
|
||||
$classSectionId = (int) $classSectionId;
|
||||
if ($classSectionId <= 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$builder = $this->builder();
|
||||
$builder
|
||||
->select('students.id AS student_id, students.school_id, students.firstname, students.lastname, students.is_active, sc.class_section_id')
|
||||
->join('student_class sc', 'sc.student_id = students.id', 'inner')
|
||||
->where('sc.class_section_id', $classSectionId)
|
||||
->where('students.is_active', 1);
|
||||
|
||||
if ($schoolYear !== null) {
|
||||
$builder->where('sc.school_year', $schoolYear);
|
||||
}
|
||||
|
||||
$builder->distinct();
|
||||
$builder->orderBy('students.lastname', 'ASC')
|
||||
->orderBy('students.firstname', 'ASC');
|
||||
|
||||
$results = $builder->get()->getResultArray();
|
||||
|
||||
$userId = (int) (session()->get('user_id') ?? 0);
|
||||
if (!empty($results)) {
|
||||
foreach ($results as &$row) {
|
||||
$row['updated_by'] = $userId;
|
||||
}
|
||||
unset($row);
|
||||
}
|
||||
|
||||
return $results ?: [];
|
||||
}
|
||||
|
||||
|
||||
// In your existing StudentModel
|
||||
public function getStudentBasic(int $studentId): ?array
|
||||
|
||||
Reference in New Issue
Block a user