1<?php
2
3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
4// See the LICENCE file in the repository root for full licence text.
5
6namespace App\Models\LegacyMatch;
7
8use App\Models\User;
9
10/**
11 * @property mixed $detail
12 * @property int $event_id
13 * @property Game $game
14 * @property int|null $game_id
15 * @property LegacyMatch $legacyMatch
16 * @property int $match_id
17 * @property string|null $text
18 * @property \Carbon\Carbon|null $timestamp
19 * @property User $user
20 * @property int|null $user_id
21 */
22class Event extends Model
23{
24 public $timestamps = false;
25
26 protected $casts = [
27 'timestamp' => 'datetime',
28 ];
29 protected $primaryKey = 'event_id';
30
31 const EVENT_TYPES = [
32 'player-left' => 'PART',
33 'player-joined' => 'JOIN',
34 'player-kicked' => 'KICK',
35 'match-created' => 'CREATE',
36 'match-disbanded' => 'DISBAND',
37 'host-changed' => 'HOST',
38 ];
39
40 public function legacyMatch()
41 {
42 return $this->belongsTo(LegacyMatch::class, 'match_id');
43 }
44
45 public function game()
46 {
47 return $this->belongsTo(Game::class, 'game_id');
48 }
49
50 public function user()
51 {
52 return $this->belongsTo(User::class, 'user_id');
53 }
54
55 public function scopeDefault($query)
56 {
57 return $query->orderBy('event_id', 'asc');
58 }
59
60 public function getDetailAttribute()
61 {
62 $value = $this->text;
63
64 if (in_array($value, self::EVENT_TYPES, true)) {
65 return ['type' => array_search_null($value, self::EVENT_TYPES)];
66 } else {
67 return ['type' => 'other', 'text' => $value];
68 }
69 }
70}