|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
|
|
|
|
|
|
|
|
class Competition extends Model
|
|
|
|
|
|
{
|
|
|
|
|
|
use HasFactory;
|
|
|
|
|
|
|
|
|
|
|
|
public const STATUSES = [
|
|
|
|
|
|
'draft',
|
|
|
|
|
|
'published',
|
|
|
|
|
|
'signup_open',
|
|
|
|
|
|
'signup_closed',
|
|
|
|
|
|
'reviewing',
|
|
|
|
|
|
'ended',
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
|
'slug',
|
|
|
|
|
|
'name',
|
|
|
|
|
|
'description',
|
|
|
|
|
|
'pledge_content_html',
|
|
|
|
|
|
'status',
|
|
|
|
|
|
'published',
|
|
|
|
|
|
'signup_open_at',
|
|
|
|
|
|
'signup_close_at',
|
|
|
|
|
|
'form_schema_id',
|
|
|
|
|
|
'review_form_schema_id',
|
|
|
|
|
|
'branding_json',
|
|
|
|
|
|
'settings',
|
|
|
|
|
|
'scoring_rules_json',
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @var array<string, string>
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected $casts = [
|
|
|
|
|
|
'published' => 'boolean',
|
|
|
|
|
|
'signup_open_at' => 'datetime',
|
|
|
|
|
|
'signup_close_at' => 'datetime',
|
|
|
|
|
|
'branding_json' => 'array',
|
|
|
|
|
|
'settings' => 'array',
|
|
|
|
|
|
'scoring_rules_json' => 'array',
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
public function tracks(): HasMany
|
|
|
|
|
|
{
|
|
|
|
|
|
return $this->hasMany(CompetitionTrack::class)->orderBy('sort');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function formSchemaDefinitions(): HasMany
|
|
|
|
|
|
{
|
|
|
|
|
|
return $this->hasMany(FormSchemaDefinition::class, 'competition_id');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 嵌套路由参数 `{form_schema}` 的隐式绑定约定关系名为 formSchemas(见 Model::childRouteBindingRelationshipName)。
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function formSchemas(): HasMany
|
|
|
|
|
|
{
|
|
|
|
|
|
return $this->formSchemaDefinitions();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function formSchema(): BelongsTo
|
|
|
|
|
|
{
|
|
|
|
|
|
return $this->belongsTo(FormSchemaDefinition::class, 'form_schema_id');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function reviewFormSchema(): BelongsTo
|
|
|
|
|
|
{
|
|
|
|
|
|
return $this->belongsTo(FormSchemaDefinition::class, 'review_form_schema_id');
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|