e13df69885
API CI/CD / Validate (composer + pint) (push) Successful in 3m6s
API CI/CD / Test (PHPUnit) (push) Failing after 4m53s
API CI/CD / Build frontend assets (push) Successful in 1m2s
API CI/CD / Security audit (push) Failing after 59s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
87 lines
2.2 KiB
PHP
87 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
class Participation extends BaseModel
|
|
{
|
|
protected $table = 'participation';
|
|
|
|
/**
|
|
* legacy: 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', '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 numeric; change to 'integer' if it is whole number
|
|
'score' => 'decimal:2',
|
|
'max_points' => 'decimal:2',
|
|
'locked_by' => 'integer',
|
|
'locked_at' => 'datetime',
|
|
|
|
'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 legacy 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);
|
|
|
|
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;
|
|
}
|
|
}
|