5 use App\Events\ProtocolAdded;
6 use Illuminate\Database\Eloquent\Factories\HasFactory;
7 use Illuminate\Database\Eloquent\Model;
9 class Protocol extends Model
13 public static function resultCommented(Tournament $tournament, Result $result, User $user) {
14 $protocol = static::create([
15 'tournament_id' => $tournament->id,
16 'user_id' => $user->id,
17 'type' => 'result.comment',
19 'tournament' => static::tournamentMemo($tournament),
20 'result' => static::resultMemo($result),
21 'round' => static::roundMemo($result->round),
24 ProtocolAdded::dispatch($protocol);
27 public static function resultReported(Tournament $tournament, Result $result, User $user) {
28 $protocol = static::create([
29 'tournament_id' => $tournament->id,
30 'user_id' => $user->id,
31 'type' => 'result.report',
33 'tournament' => static::tournamentMemo($tournament),
34 'result' => static::resultMemo($result),
35 'round' => static::roundMemo($result->round),
38 ProtocolAdded::dispatch($protocol);
41 public static function roundAdded(Tournament $tournament, Round $round, User $user) {
42 $protocol = static::create([
43 'tournament_id' => $tournament->id,
44 'user_id' => $user->id,
45 'type' => 'round.create',
47 'tournament' => static::tournamentMemo($tournament),
48 'round' => static::roundMemo($round),
51 ProtocolAdded::dispatch($protocol);
54 public static function roundLocked(Tournament $tournament, Round $round, User $user = null) {
55 $protocol = static::create([
56 'tournament_id' => $tournament->id,
57 'user_id' => $user ? $user->id : null,
58 'type' => 'round.lock',
60 'tournament' => static::tournamentMemo($tournament),
61 'round' => static::roundMemo($round),
64 ProtocolAdded::dispatch($protocol);
67 public static function roundSeedSet(Tournament $tournament, Round $round, User $user) {
68 $protocol = static::create([
69 'tournament_id' => $tournament->id,
70 'user_id' => $user->id,
71 'type' => 'round.create',
73 'tournament' => static::tournamentMemo($tournament),
74 'round' => static::roundMemo($round),
77 ProtocolAdded::dispatch($protocol);
80 public static function roundUnlocked(Tournament $tournament, Round $round, User $user = null) {
81 $protocol = static::create([
82 'tournament_id' => $tournament->id,
83 'user_id' => $user ? $user->id : null,
84 'type' => 'round.unlock',
86 'tournament' => static::tournamentMemo($tournament),
87 'round' => static::roundMemo($round),
90 ProtocolAdded::dispatch($protocol);
93 public static function tournamentCreated(Tournament $tournament, User $user) {
94 $protocol = static::create([
95 'tournament_id' => $tournament->id,
96 'user_id' => $user->id,
97 'type' => 'tournament.create',
99 'tournament' => static::tournamentMemo($tournament),
102 ProtocolAdded::dispatch($protocol);
105 public static function tournamentLocked(Tournament $tournament, User $user = null) {
106 $protocol = static::create([
107 'tournament_id' => $tournament->id,
108 'user_id' => $user ? $user->id : null,
109 'type' => 'tournament.lock',
111 'tournament' => static::tournamentMemo($tournament),
114 ProtocolAdded::dispatch($protocol);
118 protected static function resultMemo(Result $result) {
121 'comment' => $result->comment,
122 'forfeit' => $result->forfeit,
123 'time' => $result->time,
127 protected static function roundMemo(Round $round) {
130 'locked' => $round->locked,
131 'no_record' => $round->no_record,
132 'number' => $round->number,
133 'seed' => $round->seed,
137 protected static function tournamentMemo(Tournament $tournament) {
139 'id' => $tournament->id,
140 'locked' => $tournament->locked,
141 'no_record' => $tournament->no_record,
142 'title' => $tournament->title,
146 protected static function userMemo(User $user) {
149 'username' => $user->username,
150 'discriminator' => $user->discriminator,
151 'avatar' => $user->avatar,
156 public function tournament() {
157 return $this->belongsTo(Tournament::class);
160 public function user() {
161 return $this->belongsTo(User::class);
166 'details' => 'array',
169 protected $fillable = [