Files
alrahma_sunday_school_api/app/Models/FinalExam.php
T
2026-04-23 00:04:35 -04:00

77 lines
1.8 KiB
PHP

<?php
namespace App\Models;
use App\Models\BaseModel;
class FinalExam extends BaseModel
{
protected $table = 'final_exam';
/**
* 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 = false;
protected $fillable = [
'student_id',
'school_id',
'class_section_id',
'updated_by',
'score',
'comment',
'semester',
'school_year',
'created_at',
'updated_at',
];
protected $casts = [
'student_id' => 'integer',
'school_id' => 'integer',
'class_section_id' => 'integer',
'updated_by' => 'integer',
// score is often numeric; adjust if yours is integer
'score' => 'decimal:2',
'created_at' => 'datetime',
'updated_at' => 'datetime',
];
/* Optional relationships */
public function student()
{
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;
}
}