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
+50 -42
View File
@@ -7,10 +7,13 @@ use App\Models\BaseModel;
class FinalExam extends BaseModel
{
protected $table = 'final_exam';
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
protected $useSoftDeletes = false;
protected $protectFields = true;
/**
* CI: useTimestamps = false (even though table has created_at/updated_at fields).
* So we keep timestamps OFF and you can set created_at/updated_at manually if needed.
*/
public $timestamps = true;
protected $fillable = [
'student_id',
'school_id',
@@ -23,46 +26,51 @@ class FinalExam extends BaseModel
'updated_at',
];
protected bool $allowEmptyInserts = false;
protected bool $updateOnlyChanged = true;
protected $casts = [
'student_id' => 'integer',
'school_id' => 'integer',
'class_section_id' => 'integer',
'updated_by' => 'integer',
protected $casts = [];
protected $castHandlers = [];
// score is often numeric; adjust if yours is integer
'score' => 'decimal:2',
// Dates
public $timestamps = true;
protected $dateFormat = 'datetime';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $deletedField = 'deleted_at';
'created_at' => 'datetime',
'updated_at' => 'datetime',
];
// Validation
protected $validationRules = [];
protected $validationMessages = [];
protected $skipValidation = false;
protected $cleanValidationRules = true;
// Callbacks
protected $allowCallbacks = true;
protected $beforeInsert = [];
protected $afterInsert = [];
protected $beforeUpdate = [];
protected $afterUpdate = [];
protected $beforeFind = [];
protected $afterFind = [];
protected $beforeDelete = [];
protected $afterDelete = [];
public function getFinalExamScore($studentId, string $semester, $schoolYear)
/* Optional relationships */
public function student()
{
// Query the final_score table for the final exam score based on student ID, semester, and school year
$result = $this->select('score') // We only need the score
->where('student_id', $studentId)
->where('semester', $semester)
->where('school_year', $schoolYear)
->first(); // Get the first matching result
// Return the score, or null if no result is found
return $result ? $result['score'] : null;
return $this->belongsTo(Student::class, 'student_id');
}
}
public function classSection()
{
return $this->belongsTo(ClassSection::class, 'class_section_id');
}
/**
* Equivalent of CI getFinalExamScore()
*/
public static function getFinalExamScore(
int $studentId,
string $semester,
string $schoolYear,
?int $classSectionId = null
) {
$q = static::query()
->select('score')
->where('student_id', $studentId)
->where('semester', $semester)
->where('school_year', $schoolYear);
if ($classSectionId !== null) {
$q->where('class_section_id', $classSectionId);
}
$row = $q->first();
return $row?->score;
}
}