X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FModels%2FProtocol.php;h=ce081e77dded2c6bf7f92af76381d1a0364e54e6;hb=4f4b2fd64141cbbff953881e2705602a00b85df5;hp=995f9c02ab8707f33825d88147ba0191efa54cad;hpb=a4260a00251cef4ad806c9d5c44d4c444d6ab831;p=alttp.git diff --git a/app/Models/Protocol.php b/app/Models/Protocol.php index 995f9c0..ce081e7 100644 --- a/app/Models/Protocol.php +++ b/app/Models/Protocol.php @@ -10,6 +10,48 @@ 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, @@ -51,6 +93,19 @@ class Protocol extends Model ProtocolAdded::dispatch($protocol); } + public static function roundEdited(Tournament $tournament, Round $round, User $user) { + $protocol = static::create([ + 'tournament_id' => $tournament->id, + 'user_id' => $user->id, + 'type' => 'round.edit', + 'details' => [ + 'tournament' => static::tournamentMemo($tournament), + 'round' => static::roundMemo($round), + ], + ]); + ProtocolAdded::dispatch($protocol); + } + public static function roundLocked(Tournament $tournament, Round $round, User $user = null) { $protocol = static::create([ 'tournament_id' => $tournament->id, @@ -68,7 +123,7 @@ class Protocol extends Model $protocol = static::create([ 'tournament_id' => $tournament->id, 'user_id' => $user->id, - 'type' => 'round.create', + 'type' => 'round.seed', 'details' => [ 'tournament' => static::tournamentMemo($tournament), 'round' => static::roundMemo($round), @@ -90,6 +145,18 @@ class Protocol extends Model ProtocolAdded::dispatch($protocol); } + public static function tournamentClosed(Tournament $tournament, User $user = null) { + $protocol = static::create([ + 'tournament_id' => $tournament->id, + 'user_id' => $user ? $user->id : null, + 'type' => 'tournament.close', + 'details' => [ + 'tournament' => static::tournamentMemo($tournament), + ], + ]); + ProtocolAdded::dispatch($protocol); + } + public static function tournamentCreated(Tournament $tournament, User $user) { $protocol = static::create([ 'tournament_id' => $tournament->id, @@ -102,6 +169,30 @@ class Protocol extends Model ProtocolAdded::dispatch($protocol); } + public static function tournamentDiscord(Tournament $tournament, User $user = null) { + $protocol = static::create([ + 'tournament_id' => $tournament->id, + 'user_id' => $user ? $user->id : null, + 'type' => 'tournament.discord', + 'details' => [ + 'tournament' => static::tournamentMemo($tournament), + ], + ]); + ProtocolAdded::dispatch($protocol); + } + + public static function tournamentDiscordSettings(Tournament $tournament, User $user = null) { + $protocol = static::create([ + 'tournament_id' => $tournament->id, + 'user_id' => $user ? $user->id : null, + 'type' => 'tournament.discordSettings', + 'details' => [ + 'tournament' => static::tournamentMemo($tournament), + ], + ]); + ProtocolAdded::dispatch($protocol); + } + public static function tournamentLocked(Tournament $tournament, User $user = null) { $protocol = static::create([ 'tournament_id' => $tournament->id, @@ -114,6 +205,37 @@ class Protocol extends Model ProtocolAdded::dispatch($protocol); } + public static function tournamentOpened(Tournament $tournament, User $user = null) { + $protocol = static::create([ + 'tournament_id' => $tournament->id, + 'user_id' => $user ? $user->id : null, + 'type' => 'tournament.open', + 'details' => [ + 'tournament' => static::tournamentMemo($tournament), + ], + ]); + ProtocolAdded::dispatch($protocol); + } + + public static function tournamentUnlocked(Tournament $tournament, User $user = null) { + $protocol = static::create([ + 'tournament_id' => $tournament->id, + 'user_id' => $user ? $user->id : null, + 'type' => 'tournament.unlock', + 'details' => [ + 'tournament' => static::tournamentMemo($tournament), + ], + ]); + ProtocolAdded::dispatch($protocol); + } + + + protected static function applicationMemo(Application $application) { + return [ + 'id' => $application->id, + 'denied' => $application->denied, + ]; + } protected static function resultMemo(Result $result) { return [ @@ -137,6 +259,7 @@ 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, @@ -149,6 +272,7 @@ class Protocol extends Model 'username' => $user->username, 'discriminator' => $user->discriminator, 'avatar' => $user->avatar, + 'nickname' => $user->nickname, ]; }