37 lines
767 B
PHP
37 lines
767 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class SplitScoreDefinition extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $guarded = [];
|
|
|
|
protected $casts = [
|
|
'splits' => 'array',
|
|
];
|
|
|
|
public function audition()
|
|
{
|
|
return $this->belongsTo(Audition::class);
|
|
}
|
|
|
|
public function subscoresForJudge(User $judge): array
|
|
{
|
|
$validSubscores = [];
|
|
foreach ($this->splits as $split) {
|
|
if (in_array($judge->id, $split['judges'])) {
|
|
foreach ($split['subscores'] as $subscore) {
|
|
$validSubscores[] = $subscore;
|
|
}
|
|
}
|
|
}
|
|
|
|
return $validSubscores;
|
|
}
|
|
}
|