X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FModels%2FProtocol.php;h=7a90851a706c43b0d0b5e0ce417eb30fdbe6df35;hb=cd36cb0ba2718e6bfa08765e7702d57dfe7fd733;hp=4659665e87ffddeed7adcae097afcd0df81f3cd2;hpb=d1f28ea443b090c7593791eba9631796ccaeafe1;p=alttp.git diff --git a/app/Models/Protocol.php b/app/Models/Protocol.php index 4659665..7a90851 100644 --- a/app/Models/Protocol.php +++ b/app/Models/Protocol.php @@ -10,6 +10,62 @@ class Protocol extends Model { use HasFactory; + public static function applicationAccepted(Tournament $tournament, Application $application, User $user) { + $protocol = static::create([ + 'tournament_id' => $tournament->id, + 'user_id' => $user->id, + 'type' => 'application.accepted', + 'details' => [ + 'tournament' => static::tournamentMemo($tournament), + 'application' => static::applicationMemo($application), + 'user' => static::userMemo($application->user), + ], + ]); + ProtocolAdded::dispatch($protocol); + } + + public static function applicationReceived(Tournament $tournament, Application $application, User $user) { + $protocol = static::create([ + 'tournament_id' => $tournament->id, + 'user_id' => $user->id, + 'type' => 'application.received', + 'details' => [ + 'tournament' => static::tournamentMemo($tournament), + 'application' => static::applicationMemo($application), + 'user' => static::userMemo($application->user), + ], + ]); + ProtocolAdded::dispatch($protocol); + } + + public static function applicationRejected(Tournament $tournament, Application $application, User $user) { + $protocol = static::create([ + 'tournament_id' => $tournament->id, + 'user_id' => $user->id, + 'type' => 'application.rejected', + 'details' => [ + 'tournament' => static::tournamentMemo($tournament), + 'application' => static::applicationMemo($application), + 'user' => static::userMemo($application->user), + ], + ]); + ProtocolAdded::dispatch($protocol); + } + + public static function resultCommented(Tournament $tournament, Result $result, User $user) { + $protocol = static::create([ + 'tournament_id' => $tournament->id, + 'user_id' => $user->id, + 'type' => 'result.comment', + 'details' => [ + 'tournament' => static::tournamentMemo($tournament), + 'result' => static::resultMemo($result), + 'round' => static::roundMemo($result->round), + ], + ]); + ProtocolAdded::dispatch($protocol); + } + public static function resultReported(Tournament $tournament, Result $result, User $user) { $protocol = static::create([ 'tournament_id' => $tournament->id, @@ -18,6 +74,7 @@ class Protocol extends Model 'details' => [ 'tournament' => static::tournamentMemo($tournament), 'result' => static::resultMemo($result), + 'round' => static::roundMemo($result->round), ], ]); ProtocolAdded::dispatch($protocol); @@ -100,9 +157,17 @@ class Protocol extends Model } + protected static function applicationMemo(Application $application) { + return [ + 'id' => $application->id, + 'denied' => $application->denied, + ]; + } + protected static function resultMemo(Result $result) { return [ 'id' => $result->id, + 'comment' => $result->comment, 'forfeit' => $result->forfeit, 'time' => $result->time, ]; @@ -111,6 +176,8 @@ class Protocol extends Model protected static function roundMemo(Round $round) { return [ 'id' => $round->id, + 'locked' => $round->locked, + 'no_record' => $round->no_record, 'number' => $round->number, 'seed' => $round->seed, ]; @@ -119,6 +186,9 @@ class Protocol extends Model protected static function tournamentMemo(Tournament $tournament) { return [ 'id' => $tournament->id, + 'accept_applications' => $tournament->accept_applications, + 'locked' => $tournament->locked, + 'no_record' => $tournament->no_record, 'title' => $tournament->title, ]; } @@ -129,6 +199,7 @@ class Protocol extends Model 'username' => $user->username, 'discriminator' => $user->discriminator, 'avatar' => $user->avatar, + 'nickname' => $user->nickname, ]; }