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 resultReported(Tournament $tournament, Result $result, User $user) {
14 $protocol = static::create([
15 'tournament_id' => $tournament->id,
16 'user_id' => $user->id,
17 'type' => 'result.report',
19 'tournament' => static::tournamentMemo($tournament),
20 'result' => static::resultMemo($result),
23 ProtocolAdded::dispatch($protocol);
26 public static function roundAdded(Tournament $tournament, Round $round, User $user) {
27 $protocol = static::create([
28 'tournament_id' => $tournament->id,
29 'user_id' => $user->id,
30 'type' => 'round.create',
32 'tournament' => static::tournamentMemo($tournament),
33 'round' => static::roundMemo($round),
36 ProtocolAdded::dispatch($protocol);
39 public static function roundLocked(Tournament $tournament, Round $round, User $user = null) {
40 $protocol = static::create([
41 'tournament_id' => $tournament->id,
42 'user_id' => $user ? $user->id : null,
43 'type' => 'round.lock',
45 'tournament' => static::tournamentMemo($tournament),
46 'round' => static::roundMemo($round),
49 ProtocolAdded::dispatch($protocol);
52 public static function roundSeedSet(Tournament $tournament, Round $round, User $user) {
53 $protocol = static::create([
54 'tournament_id' => $tournament->id,
55 'user_id' => $user->id,
56 'type' => 'round.create',
58 'tournament' => static::tournamentMemo($tournament),
59 'round' => static::roundMemo($round),
62 ProtocolAdded::dispatch($protocol);
65 public static function tournamentCreated(Tournament $tournament, User $user) {
66 $protocol = static::create([
67 'tournament_id' => $tournament->id,
68 'user_id' => $user->id,
69 'type' => 'tournament.create',
71 'tournament' => static::tournamentMemo($tournament),
74 ProtocolAdded::dispatch($protocol);
77 public static function tournamentLocked(Tournament $tournament, User $user = null) {
78 $protocol = static::create([
79 'tournament_id' => $tournament->id,
80 'user_id' => $user ? $user->id : null,
81 'type' => 'tournament.lock',
83 'tournament' => static::tournamentMemo($tournament),
86 ProtocolAdded::dispatch($protocol);
90 protected static function resultMemo(Result $result) {
93 'forfeit' => $result->forfeit,
94 'time' => $result->time,
98 protected static function roundMemo(Round $round) {
101 'seed' => $round->seed,
105 protected static function tournamentMemo(Tournament $tournament) {
107 'id' => $tournament->id,
108 'title' => $tournament->title,
112 protected static function userMemo(User $user) {
115 'username' => $user->username,
116 'discriminator' => $user->discriminator,
117 'avatar' => $user->avatar,
122 public function tournament() {
123 return $this->belongsTo(Tournament::class);
126 public function user() {
127 return $this->belongsTo(User::class);
132 'details' => 'array',
135 protected $fillable = [