Auditionadmin 68 #85
|
|
@ -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);
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue