Auditionadmin 68 #85

Merged
okorpheus merged 11 commits from auditionadmin-68 into master 2024-10-31 17:22:49 +00:00
2 changed files with 30 additions and 0 deletions
Showing only changes of commit e93ae750e4 - Show all commits

View File

@ -121,6 +121,11 @@ class Entry extends Model
return $this->hasOne(Seat::class); return $this->hasOne(Seat::class);
} }
public function calculatedScores(): HasMany
{
return $this->hasMany(CalculatedScore::class);
}
public function scopeForSeating(Builder $query): void public function scopeForSeating(Builder $query): void
{ {
$query->where('for_seating', 1); $query->where('for_seating', 1);

View File

@ -16,6 +16,22 @@ class ScoreSheet extends Model
protected $casts = ['subscores' => 'json']; protected $casts = ['subscores' => 'json'];
protected static function boot()
{
parent::boot();
static::created(function ($scoreSheet) {
$scoreSheet->deleteRelatedCalculatedScores();
});
static::updated(function ($scoreSheet) {
$scoreSheet->deleteRelatedCalculatedScores();
});
static::deleted(function ($scoreSheet) {
$scoreSheet->deleteRelatedCalculatedScores();
});
}
public function entry(): BelongsTo public function entry(): BelongsTo
{ {
return $this->belongsTo(Entry::class); return $this->belongsTo(Entry::class);
@ -37,9 +53,18 @@ class ScoreSheet extends Model
'audition_id' // Local key on the intermediate model (Entry) 'audition_id' // Local key on the intermediate model (Entry)
); );
} }
public function getSubscore($id) public function getSubscore($id)
{ {
return $this->subscores[$id]['score'] ?? false; return $this->subscores[$id]['score'] ?? false;
// this function is used at resources/views/tabulation/entry_score_sheet.blade.php // this function is used at resources/views/tabulation/entry_score_sheet.blade.php
} }
public function deleteRelatedCalculatedScores(): void
{
$entry = $this->entry;
if ($entry) {
$entry->calculatedScores()->delete();
}
}
} }