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
+56 -38
View File
@@ -7,10 +7,13 @@ use App\Models\BaseModel;
class Participation extends BaseModel
{
protected $table = 'participation';
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
protected $useSoftDeletes = false;
protected $protectFields = true;
/**
* CI: useTimestamps = false (even though created_at/updated_at columns exist).
* Keep OFF to match behavior (you can still set created_at/updated_at manually).
*/
public $timestamps = true;
protected $fillable = [
'student_id',
'school_id',
@@ -24,45 +27,60 @@ class Participation 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 numeric; change to 'integer' if it is whole number
'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 = [];
// 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
/* Optional relationships */
public function student()
{
$result = $this->select('score')
return $this->belongsTo(Student::class, 'student_id');
}
public function classSection()
{
return $this->belongsTo(ClassSection::class, 'class_section_id');
}
/**
* Equivalent of CI getParticipationScore()
* Returns null if missing/blank/non-numeric.
*/
public static function getParticipationScore(
int $studentId,
string $semester,
string $schoolYear,
?int $classSectionId = null
): ?float {
$q = static::query()
->select('score')
->where('student_id', $studentId)
->where('semester', $semester)
->where('school_year', $schoolYear)
->first();
->where('school_year', $schoolYear);
return $result ? floatval($result['score']) : null;
if ($classSectionId !== null) {
$q->where('class_section_id', $classSectionId);
}
$row = $q->first();
if (!$row) return null;
$score = $row->score;
if ($score === null) return null;
if (is_string($score) && trim($score) === '') return null;
if ($score === '') return null;
if (!is_numeric($score)) return null;
return (float) $score;
}
}
}