]> git.localhorst.tv Git - alttp.git/blobdiff - app/Models/Protocol.php
result comments
[alttp.git] / app / Models / Protocol.php
index fee8b881b492b0e0739df1289d3cde53c7575a19..995f9c02ab8707f33825d88147ba0191efa54cad 100644 (file)
@@ -10,6 +10,20 @@ class Protocol extends Model
 {
        use HasFactory;
 
+       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 +32,7 @@ class Protocol extends Model
                        'details' => [
                                'tournament' => static::tournamentMemo($tournament),
                                'result' => static::resultMemo($result),
+                               'round' => static::roundMemo($result->round),
                        ],
                ]);
                ProtocolAdded::dispatch($protocol);
@@ -62,6 +77,19 @@ class Protocol extends Model
                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,
@@ -74,10 +102,23 @@ 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,
+                       'comment' => $result->comment,
                        'forfeit' => $result->forfeit,
                        'time' => $result->time,
                ];
@@ -86,6 +127,9 @@ 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,
                ];
        }
@@ -93,6 +137,8 @@ class Protocol extends Model
        protected static function tournamentMemo(Tournament $tournament) {
                return [
                        'id' => $tournament->id,
+                       'locked' => $tournament->locked,
+                       'no_record' => $tournament->no_record,
                        'title' => $tournament->title,
                ];
        }