5 use App\Events\ResultChanged;
6 use Illuminate\Database\Eloquent\Factories\HasFactory;
7 use Illuminate\Database\Eloquent\Model;
9 class Result extends Model
14 public function formatTime() {
15 $hours = floor($this->time / 60 / 60);
16 $minutes = floor(($this->time / 60) % 60);
17 $seconds = floor($this->time % 60);
18 return sprintf('%d:%02d:%02d', $hours, $minutes, $seconds);
21 public function updateResult($time, $forfeit) {
23 $this->forfeit = $forfeit;
25 if ($this->wasChanged()) {
26 ResultChanged::dispatch($this);
30 public function updatePlacement($score, $placement) {
31 $this->score = $score;
32 $this->placement = $placement;
34 if ($this->wasChanged()) {
35 ResultChanged::dispatch($this);
40 public function round() {
41 return $this->belongsTo(Round::class);
44 public function participant() {
45 return $this->belongsTo(Participant::class);
48 public function getHasFinishedAttribute() {
49 return $this->time > 0 || $this->forfeit;
54 'forfeit' => 'boolean',
58 protected $appends = [
62 protected $fillable = [