60 lines
1.6 KiB
PHP
60 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Exceptions\TabulationException;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
|
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
|
|
|
|
class Entry extends Model
|
|
{
|
|
use HasFactory;
|
|
protected $guarded = [];
|
|
protected $hasCheckedScoreSheets = false;
|
|
public $final_scores_array; // Set by TabulationService
|
|
public $scoring_complete; // Set by TabulationService
|
|
public $is_doubler; // Set by DoublerService
|
|
|
|
public function student(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Student::class);
|
|
}
|
|
|
|
public function audition(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Audition::class);
|
|
}
|
|
|
|
public function school(): HasOneThrough
|
|
{
|
|
return $this->hasOneThrough(
|
|
School::class,
|
|
Student::class,
|
|
'id',
|
|
'id',
|
|
'student_id',
|
|
'school_id');
|
|
}
|
|
|
|
public function scoreSheets(): HasMany
|
|
{
|
|
return $this->hasMany(ScoreSheet::class);
|
|
|
|
}
|
|
|
|
/*
|
|
* Ensures score_sheets_count property is always available
|
|
*/
|
|
public function getScoreSheetsCountAttribute()
|
|
{
|
|
if (!isset($this->attributes['score_sheets_count'])) {
|
|
$this->attributes['score_sheets_count'] = $this->scoreSheets()->count();
|
|
}
|
|
return $this->attributes['score_sheets_count'];
|
|
}
|
|
}
|