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
+40 -13
View File
@@ -7,8 +7,11 @@ use App\Models\BaseModel;
class FinalScore extends BaseModel
{
protected $table = 'final_score';
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
// CI model didn't specify timestamps behavior; table includes created_at/updated_at.
// If you want Laravel to auto-manage them, keep true (recommended).
public $timestamps = true;
protected $fillable = [
'student_id',
'school_id',
@@ -22,19 +25,43 @@ class FinalScore extends BaseModel
'updated_at',
'semester',
];
public $timestamps = true;
// Function to get the final exam score for a specific student, semester, and school year
public function getFinalExamScore($studentId, $semester, $schoolYear)
protected $casts = [
'student_id' => 'integer',
'school_id' => 'integer',
'class_section_id' => 'integer',
'teacher_id' => 'integer',
'score' => 'decimal:2', // change to 'integer' if score is whole number
];
/* 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 $this->belongsTo(Student::class, 'student_id');
}
// Return the score, or null if no result is found
return $result ? $result['score'] : null;
public function teacher()
{
return $this->belongsTo(User::class, 'teacher_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)
{
$row = static::query()
->select('score')
->where('student_id', $studentId)
->where('semester', $semester)
->where('school_year', $schoolYear)
->first();
return $row?->score;
}
}