X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FModels%2FProtocol.php;h=4659665e87ffddeed7adcae097afcd0df81f3cd2;hb=d1f28ea443b090c7593791eba9631796ccaeafe1;hp=bbfea732fe97fecfc5a7a48da553580577bc78bf;hpb=4388278823ac8a791641ac1d65fc675e9543b8e8;p=alttp.git diff --git a/app/Models/Protocol.php b/app/Models/Protocol.php index bbfea73..4659665 100644 --- a/app/Models/Protocol.php +++ b/app/Models/Protocol.php @@ -10,6 +10,19 @@ class Protocol extends Model { use HasFactory; + public static function resultReported(Tournament $tournament, Result $result, User $user) { + $protocol = static::create([ + 'tournament_id' => $tournament->id, + 'user_id' => $user->id, + 'type' => 'result.report', + 'details' => [ + 'tournament' => static::tournamentMemo($tournament), + 'result' => static::resultMemo($result), + ], + ]); + ProtocolAdded::dispatch($protocol); + } + public static function roundAdded(Tournament $tournament, Round $round, User $user) { $protocol = static::create([ 'tournament_id' => $tournament->id, @@ -23,6 +36,45 @@ class Protocol extends Model ProtocolAdded::dispatch($protocol); } + public static function roundLocked(Tournament $tournament, Round $round, User $user = null) { + $protocol = static::create([ + 'tournament_id' => $tournament->id, + 'user_id' => $user ? $user->id : null, + 'type' => 'round.lock', + 'details' => [ + 'tournament' => static::tournamentMemo($tournament), + 'round' => static::roundMemo($round), + ], + ]); + ProtocolAdded::dispatch($protocol); + } + + public static function roundSeedSet(Tournament $tournament, Round $round, User $user) { + $protocol = static::create([ + 'tournament_id' => $tournament->id, + 'user_id' => $user->id, + 'type' => 'round.create', + 'details' => [ + 'tournament' => static::tournamentMemo($tournament), + 'round' => static::roundMemo($round), + ], + ]); + ProtocolAdded::dispatch($protocol); + } + + public static function roundUnlocked(Tournament $tournament, Round $round, User $user = null) { + $protocol = static::create([ + 'tournament_id' => $tournament->id, + 'user_id' => $user ? $user->id : null, + 'type' => 'round.unlock', + 'details' => [ + 'tournament' => static::tournamentMemo($tournament), + 'round' => static::roundMemo($round), + ], + ]); + ProtocolAdded::dispatch($protocol); + } + public static function tournamentCreated(Tournament $tournament, User $user) { $protocol = static::create([ 'tournament_id' => $tournament->id, @@ -35,10 +87,31 @@ class Protocol extends Model ProtocolAdded::dispatch($protocol); } + public static function tournamentLocked(Tournament $tournament, User $user = null) { + $protocol = static::create([ + 'tournament_id' => $tournament->id, + 'user_id' => $user ? $user->id : null, + 'type' => 'tournament.lock', + 'details' => [ + 'tournament' => static::tournamentMemo($tournament), + ], + ]); + ProtocolAdded::dispatch($protocol); + } + + + protected static function resultMemo(Result $result) { + return [ + 'id' => $result->id, + 'forfeit' => $result->forfeit, + 'time' => $result->time, + ]; + } protected static function roundMemo(Round $round) { return [ 'id' => $round->id, + 'number' => $round->number, 'seed' => $round->seed, ]; }