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 applicationAccepted(Tournament $tournament, Application $application, User $user) {
14 $protocol = static::create([
15 'tournament_id' => $tournament->id,
16 'user_id' => $user->id,
17 'type' => 'application.accepted',
19 'tournament' => static::tournamentMemo($tournament),
20 'application' => static::applicationMemo($application),
21 'user' => static::userMemo($application->user),
24 ProtocolAdded::dispatch($protocol);
27 public static function applicationReceived(Tournament $tournament, Application $application, User $user) {
28 $protocol = static::create([
29 'tournament_id' => $tournament->id,
30 'user_id' => $user->id,
31 'type' => 'application.received',
33 'tournament' => static::tournamentMemo($tournament),
34 'application' => static::applicationMemo($application),
35 'user' => static::userMemo($application->user),
38 ProtocolAdded::dispatch($protocol);
41 public static function applicationRejected(Tournament $tournament, Application $application, User $user) {
42 $protocol = static::create([
43 'tournament_id' => $tournament->id,
44 'user_id' => $user->id,
45 'type' => 'application.rejected',
47 'tournament' => static::tournamentMemo($tournament),
48 'application' => static::applicationMemo($application),
49 'user' => static::userMemo($application->user),
52 ProtocolAdded::dispatch($protocol);
55 public static function resultCommented(Tournament $tournament, Result $result, User $user) {
56 $protocol = static::create([
57 'tournament_id' => $tournament->id,
58 'user_id' => $user->id,
59 'type' => 'result.comment',
61 'tournament' => static::tournamentMemo($tournament),
62 'result' => static::resultMemo($result),
63 'round' => static::roundMemo($result->round),
66 ProtocolAdded::dispatch($protocol);
69 public static function resultReported(Tournament $tournament, Result $result, User $user) {
70 $protocol = static::create([
71 'tournament_id' => $tournament->id,
72 'user_id' => $user->id,
73 'type' => 'result.report',
75 'tournament' => static::tournamentMemo($tournament),
76 'result' => static::resultMemo($result),
77 'round' => static::roundMemo($result->round),
80 ProtocolAdded::dispatch($protocol);
83 public static function roundAdded(Tournament $tournament, Round $round, User $user) {
84 $protocol = static::create([
85 'tournament_id' => $tournament->id,
86 'user_id' => $user->id,
87 'type' => 'round.create',
89 'tournament' => static::tournamentMemo($tournament),
90 'round' => static::roundMemo($round),
93 ProtocolAdded::dispatch($protocol);
96 public static function roundLocked(Tournament $tournament, Round $round, User $user = null) {
97 $protocol = static::create([
98 'tournament_id' => $tournament->id,
99 'user_id' => $user ? $user->id : null,
100 'type' => 'round.lock',
102 'tournament' => static::tournamentMemo($tournament),
103 'round' => static::roundMemo($round),
106 ProtocolAdded::dispatch($protocol);
109 public static function roundSeedSet(Tournament $tournament, Round $round, User $user) {
110 $protocol = static::create([
111 'tournament_id' => $tournament->id,
112 'user_id' => $user->id,
113 'type' => 'round.create',
115 'tournament' => static::tournamentMemo($tournament),
116 'round' => static::roundMemo($round),
119 ProtocolAdded::dispatch($protocol);
122 public static function roundUnlocked(Tournament $tournament, Round $round, User $user = null) {
123 $protocol = static::create([
124 'tournament_id' => $tournament->id,
125 'user_id' => $user ? $user->id : null,
126 'type' => 'round.unlock',
128 'tournament' => static::tournamentMemo($tournament),
129 'round' => static::roundMemo($round),
132 ProtocolAdded::dispatch($protocol);
135 public static function tournamentCreated(Tournament $tournament, User $user) {
136 $protocol = static::create([
137 'tournament_id' => $tournament->id,
138 'user_id' => $user->id,
139 'type' => 'tournament.create',
141 'tournament' => static::tournamentMemo($tournament),
144 ProtocolAdded::dispatch($protocol);
147 public static function tournamentLocked(Tournament $tournament, User $user = null) {
148 $protocol = static::create([
149 'tournament_id' => $tournament->id,
150 'user_id' => $user ? $user->id : null,
151 'type' => 'tournament.lock',
153 'tournament' => static::tournamentMemo($tournament),
156 ProtocolAdded::dispatch($protocol);
160 protected static function applicationMemo(Application $application) {
162 'id' => $application->id,
163 'denied' => $application->denied,
167 protected static function resultMemo(Result $result) {
170 'comment' => $result->comment,
171 'forfeit' => $result->forfeit,
172 'time' => $result->time,
176 protected static function roundMemo(Round $round) {
179 'locked' => $round->locked,
180 'no_record' => $round->no_record,
181 'number' => $round->number,
182 'seed' => $round->seed,
186 protected static function tournamentMemo(Tournament $tournament) {
188 'id' => $tournament->id,
189 'accept_applications' => $tournament->accept_applications,
190 'locked' => $tournament->locked,
191 'no_record' => $tournament->no_record,
192 'title' => $tournament->title,
196 protected static function userMemo(User $user) {
199 'username' => $user->username,
200 'discriminator' => $user->discriminator,
201 'avatar' => $user->avatar,
202 'nickname' => $user->nickname,
207 public function tournament() {
208 return $this->belongsTo(Tournament::class);
211 public function user() {
212 return $this->belongsTo(User::class);
217 'details' => 'array',
220 protected $fillable = [