reconstruction of the project

This commit is contained in:
root
2026-03-08 16:33:24 -04:00
parent 23b7db1107
commit c8de5f7edc
9157 changed files with 77877 additions and 1073823 deletions
+71 -96
View File
@@ -3,11 +3,15 @@
namespace App\Models;
use App\Models\BaseModel;
use Illuminate\Support\Facades\DB;
class Enrollment extends BaseModel
{
protected $table = 'enrollments';
protected $primaryKey = 'id';
// ✅ CI: useTimestamps = true
public $timestamps = true;
protected $fillable = [
'student_id',
'class_section_id',
@@ -22,125 +26,96 @@ class Enrollment extends BaseModel
'created_at',
'updated_at',
];
public $timestamps = true;
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $validationRules = [
'student_id' => 'required|integer',
'class_section_id' => 'permit_empty|integer',
'parent_id' => 'required|integer',
'school_year' => 'required|string|max_length[25]',
'enrollment_date' => 'required|valid_date',
'withdrawal_date' => 'permit_empty|valid_date',
'is_withdrawn' => 'permit_empty|in_list[0,1]',
'enrollment_status' => 'required|in_list[admission under review,payment pending,enrolled,withdraw under review,refund pending,withdrawn]',
'admission_status' => 'required|in_list[pending,accepted,denied]',
'semester' => 'permit_empty|string|max_length[25]',
protected $casts = [
'student_id' => 'integer',
'class_section_id' => 'integer',
'parent_id' => 'integer',
'is_withdrawn' => 'boolean',
// change to 'datetime' if your columns are DATETIME
'enrollment_date' => 'date',
'withdrawal_date' => 'date',
];
protected $validationMessages = [
'student_id' => [
'required' => 'Student ID is required',
'integer' => 'Student ID must be an integer',
],
'class_section_id' => [
'integer' => 'Class Section ID must be an integer',
],
'parent_id' => [
'required' => 'Parent ID is required',
'integer' => 'Parent ID must be an integer',
],
'school_year' => [
'required' => 'School year is required',
'string' => 'School year must be a string',
'max_length' => 'School year must not exceed 25 characters',
],
'enrollment_date' => [
'required' => 'Enrollment date is required',
'valid_date' => 'Enrollment date must be a valid date',
],
'withdrawal_date' => [
'valid_date' => 'Withdrawal date must be a valid date',
],
'is_withdrawn' => [
'in_list' => 'Withdrawal status must be 0 (not withdrawn) or 1 (withdrawn)',
],
'enrollment_status' => [
'required' => 'Enrollment status is required',
'in_list' => 'Enrollment status must be one of: admission under review, payment pending, enrolled, withdraw under review, refund pending, withdrawn',
],
'admission_status' => [
'required' => 'Admission status is required',
'in_list' => 'Admission status must be one of: pending, accepted, denied',
],
'semester' => [
'max_length' => 'Semester must not exceed 25 characters',
],
];
/* Optional relationships */
public function student()
{
return $this->belongsTo(Student::class, 'student_id');
}
protected $skipValidation = false;
public function classSection()
{
return $this->belongsTo(ClassSection::class, 'class_section_id');
}
public function parent()
{
return $this->belongsTo(User::class, 'parent_id');
}
/* =========================
* CI method equivalents
* ========================= */
/**
* Get all enrolled students (full student info) for a given parent.
* Returns a collection of Student rows.
*/
public function getEnrolledStudents(int $parentId, string $schoolYear = null, string $semester = null): array
public static function getEnrolledStudents(int $parentId, ?string $schoolYear = null, ?string $semester = null)
{
$builder = $this->select('students.*')
->join('students', 'students.id = enrollments.student_id')
->where('enrollments.parent_id', $parentId);
$q = DB::table('enrollments')
->join('students', 'students.id', '=', 'enrollments.student_id')
->select('students.*')
->where('enrollments.parent_id', $parentId);
if ($schoolYear) {
$builder->where('enrollments.school_year', $schoolYear);
if (!empty($schoolYear)) {
$q->where('enrollments.school_year', $schoolYear);
}
if ($semester) {
$builder->where('enrollments.semester', $semester);
if (!empty($semester)) {
$q->where('enrollments.semester', $semester);
}
return $builder->findAll();
return $q->get();
}
/**
* Get student basic info (ID, name, grade) for a given parent where status is enrolled or Payment pending.
* Get student basic info (ID, name, grade) for a given parent
* where status is enrolled or payment pending.
*/
public function getenrolledStudentDetails(int $parentId, string $schoolYear = null): array
public static function getEnrolledStudentDetails(int $parentId, ?string $schoolYear = null): array
{
$builder = $this->db->table('enrollments')
->select('students.id, students.firstname, students.lastname, students.grade_level')
->join('students', 'students.id = enrollments.student_id')
$q = DB::table('enrollments')
->join('students', 'students.id', '=', 'enrollments.student_id')
->select('students.id', 'students.firstname', 'students.lastname', 'students.grade_level')
->where('enrollments.parent_id', $parentId)
->groupStart()
->where('enrollments.enrollment_status', 'enrolled')
->orWhere('enrollments.enrollment_status', 'payment pending')
->groupEnd();
->where(function ($w) {
$w->where('enrollments.enrollment_status', 'enrolled')
->orWhere('enrollments.enrollment_status', 'payment pending');
});
if ($schoolYear) {
$builder->where('enrollments.school_year', $schoolYear);
if (!empty($schoolYear)) {
$q->where('enrollments.school_year', $schoolYear);
}
return $builder->get()->getResultArray();
return $q->get()->map(fn ($r) => (array) $r)->all();
}
/**
* Get the latest enrollment_status for a student in a given school year.
*
* @param int $studentId
* @param string $schoolYear e.g. "2025-2026"
* @return string|null e.g. "enrolled", "pending", "denied", or null if not found
*/
public function getEnrollmentStatus(int $studentId, string $schoolYear): ?string
{
$row = $this->select('enrollment_status')
->where('student_id', $studentId)
->where('school_year', $schoolYear)
// prefer most recently updated, then most recent enrollment_date, then newest id
->orderBy('updated_at', 'DESC')
->orderBy('enrollment_date', 'DESC')
->orderBy('id', 'DESC')
->first();
* Get the latest enrollment_status for a student in a given school year.
*/
public static function getEnrollmentStatus(int $studentId, string $schoolYear): ?string
{
$row = static::query()
->select('enrollment_status')
->where('student_id', $studentId)
->where('school_year', $schoolYear)
->orderByDesc('updated_at')
->orderByDesc('enrollment_date')
->orderByDesc('id')
->first();
return $row['enrollment_status'] ?? null;
}
}
return $row?->enrollment_status;
}
}