Files
alrahma_sunday_school_api/app/Models/GradingLock.php
T
root 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
fix unittests issues
2026-07-07 20:56:32 -04:00

59 lines
1.5 KiB
PHP

<?php
namespace App\Models;
class GradingLock extends BaseModel
{
protected $table = 'grading_locks';
// ✅ legacy: useTimestamps = true
public $timestamps = true;
protected $fillable = ['class_section_id', 'semester', 'school_year', 'is_locked', 'locked_by', 'locked_at', 'created_at', 'updated_at'];
protected $casts = [
'class_section_id' => 'integer',
'is_locked' => 'boolean',
'locked_by' => 'integer',
'locked_at' => 'datetime',
];
/* Optional relationships */
public function classSection()
{
return $this->belongsTo(ClassSection::class, 'class_section_id');
}
public function lockedByUser()
{
return $this->belongsTo(User::class, 'locked_by');
}
/**
* Equivalent of legacy getLock()
*/
public static function getLock(int $classSectionId, string $semester, string $schoolYear): ?self
{
if ($classSectionId <= 0 || $semester === '' || $schoolYear === '') {
return null;
}
return static::query()
->where('class_section_id', $classSectionId)
->where('semester', $semester)
->where('school_year', $schoolYear)
->orderByDesc('id')
->first();
}
/**
* Equivalent of legacy isLocked()
*/
public static function isLocked(int $classSectionId, string $semester, string $schoolYear): bool
{
$row = static::getLock($classSectionId, $semester, $schoolYear);
return (bool) ($row?->is_locked ?? false);
}
}