Files
alrahma_sunday_school_api/app/Models/Participation.php
T
2026-03-05 12:29:37 -05:00

69 lines
1.9 KiB
PHP

<?php
namespace App\Models;
use App\Models\BaseModel;
class Participation extends BaseModel
{
protected $table = 'participation';
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
protected $useSoftDeletes = false;
protected $protectFields = true;
protected $fillable = [
'student_id',
'school_id',
'class_section_id',
'updated_by',
'score',
'comment',
'semester',
'school_year',
'created_at',
'updated_at',
];
protected bool $allowEmptyInserts = false;
protected bool $updateOnlyChanged = true;
protected $casts = [];
protected $castHandlers = [];
// Dates
public $timestamps = true;
protected $dateFormat = 'datetime';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $deletedField = 'deleted_at';
// 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 = [];
// Function to get the final exam score for a specific student, semester, and school year
public function getParticipationScore(int $studentId, string $semester, string $schoolYear): ?float
{
$result = $this->select('score')
->where('student_id', $studentId)
->where('semester', $semester)
->where('school_year', $schoolYear)
->first();
return $result ? floatval($result['score']) : null;
}
}