96 lines
2.2 KiB
PHP
96 lines
2.2 KiB
PHP
<?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;
|
|
use App\Models\User;
|
|
use App\Models\EvaluationLock;
|
|
use App\Models\EvaluationRunEvent;
|
|
|
|
class EvaluationRun extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'evaluation_runs';
|
|
|
|
protected $fillable = [
|
|
'round_id',
|
|
'rule_set_id',
|
|
'name',
|
|
'rules_version',
|
|
'result_type',
|
|
'is_official',
|
|
'notes',
|
|
'status',
|
|
'batch_id',
|
|
'current_step',
|
|
'progress_total',
|
|
'progress_done',
|
|
'scope',
|
|
'error',
|
|
'started_at',
|
|
'finished_at',
|
|
'created_by_user_id',
|
|
];
|
|
|
|
protected $casts = [
|
|
'round_id' => 'integer',
|
|
'rule_set_id' => 'integer',
|
|
'is_official' => 'boolean',
|
|
'result_type' => 'string',
|
|
'progress_total' => 'integer',
|
|
'progress_done' => 'integer',
|
|
'scope' => 'array',
|
|
'started_at' => 'datetime',
|
|
'finished_at' => 'datetime',
|
|
];
|
|
|
|
public function round(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Round::class);
|
|
}
|
|
|
|
public function logResults(): HasMany
|
|
{
|
|
return $this->hasMany(LogResult::class);
|
|
}
|
|
|
|
public function qsoResults(): HasMany
|
|
{
|
|
return $this->hasMany(QsoResult::class);
|
|
}
|
|
|
|
public function evaluationLocks(): HasMany
|
|
{
|
|
return $this->hasMany(EvaluationLock::class);
|
|
}
|
|
|
|
public function events(): HasMany
|
|
{
|
|
return $this->hasMany(EvaluationRunEvent::class);
|
|
}
|
|
|
|
public function ruleSet(): BelongsTo
|
|
{
|
|
return $this->belongsTo(EvaluationRuleSet::class, 'rule_set_id');
|
|
}
|
|
|
|
public function createdBy(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'created_by_user_id');
|
|
}
|
|
|
|
public function isCanceled(): bool
|
|
{
|
|
return strtoupper((string) $this->status) === 'CANCELED';
|
|
}
|
|
|
|
public static function isCanceledRun(int $runId): bool
|
|
{
|
|
return static::where('id', $runId)->value('status') === 'CANCELED';
|
|
}
|
|
}
|