]> git.localhorst.tv Git - alttp.git/blobdiff - app/Models/Protocol.php
application admin UI
[alttp.git] / app / Models / Protocol.php
index 995f9c02ab8707f33825d88147ba0191efa54cad..7a90851a706c43b0d0b5e0ce417eb30fdbe6df35 100644 (file)
@@ -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,
@@ -115,6 +157,13 @@ 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,
@@ -137,6 +186,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 +199,7 @@ class Protocol extends Model
                        'username' => $user->username,
                        'discriminator' => $user->discriminator,
                        'avatar' => $user->avatar,
+                       'nickname' => $user->nickname,
                ];
        }