87 lines
2.3 KiB
PHP
87 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Spatie\Translatable\HasTranslations;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use App\Models\EvaluationRuleSet;
|
|
|
|
class Contest extends Model
|
|
{
|
|
protected $table = 'contests';
|
|
|
|
use HasFactory;
|
|
use HasTranslations;
|
|
|
|
public array $translatable = [
|
|
'name',
|
|
'description'
|
|
];
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'description',
|
|
'url',
|
|
'evaluator',
|
|
'email',
|
|
'email2',
|
|
'is_mcr',
|
|
'is_test',
|
|
'is_sixhr',
|
|
'is_active',
|
|
'start_time',
|
|
'duration',
|
|
'logs_deadline_days',
|
|
'rule_set_id',
|
|
];
|
|
|
|
protected $casts = [
|
|
'name' => 'array',
|
|
'description' => 'array',
|
|
'is_mcr' => 'boolean',
|
|
'is_test' => 'boolean',
|
|
'is_sixhr' => 'boolean',
|
|
'is_active' => 'boolean',
|
|
'duration' => 'integer',
|
|
'logs_deadline_days' => 'integer',
|
|
'rule_set_id' => 'integer',
|
|
// 'start_time' => 'string', // pokud chceš čistý string; pro fancy práci s časem můžeš dát vlastní cast
|
|
];
|
|
|
|
public function ruleSet(): BelongsTo
|
|
{
|
|
return $this->belongsTo(EvaluationRuleSet::class, 'rule_set_id');
|
|
}
|
|
|
|
public function rounds(): HasMany
|
|
{
|
|
return $this->hasMany(Round::class, 'contest_id')
|
|
->orderByDesc('start_time')
|
|
->orderByDesc('end_time');
|
|
}
|
|
|
|
public function parameters(): HasMany
|
|
{
|
|
return $this->hasMany(ContestParameter::class, 'contest_id');
|
|
}
|
|
|
|
public function bands(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Band::class, 'contests_bands', 'contest_id', 'band_id');
|
|
}
|
|
|
|
public function categories(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Category::class, 'contests_categories', 'contest_id', 'category_id');
|
|
}
|
|
|
|
public function powerCategories(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(PowerCategory::class, 'contests_power_categories', 'contest_id', 'power_category_id');
|
|
}
|
|
}
|