X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FModels%2FProtocol.php;fp=app%2FModels%2FProtocol.php;h=bbfea732fe97fecfc5a7a48da553580577bc78bf;hb=4388278823ac8a791641ac1d65fc675e9543b8e8;hp=fb93a374d744668941056175dcf5c8c383eb6428;hpb=2efd7613561696a3abb19ee9f42b15cf9b4058ad;p=alttp.git diff --git a/app/Models/Protocol.php b/app/Models/Protocol.php index fb93a37..bbfea73 100644 --- a/app/Models/Protocol.php +++ b/app/Models/Protocol.php @@ -2,6 +2,7 @@ namespace App\Models; +use App\Events\ProtocolAdded; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -9,6 +10,56 @@ class Protocol extends Model { use HasFactory; + public static function roundAdded(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 tournamentCreated(Tournament $tournament, User $user) { + $protocol = static::create([ + 'tournament_id' => $tournament->id, + 'user_id' => $user->id, + 'type' => 'tournament.create', + 'details' => [ + 'tournament' => static::tournamentMemo($tournament), + ], + ]); + ProtocolAdded::dispatch($protocol); + } + + + protected static function roundMemo(Round $round) { + return [ + 'id' => $round->id, + 'seed' => $round->seed, + ]; + } + + protected static function tournamentMemo(Tournament $tournament) { + return [ + 'id' => $tournament->id, + 'title' => $tournament->title, + ]; + } + + protected static function userMemo(User $user) { + return [ + 'id' => $user->id, + 'username' => $user->username, + 'discriminator' => $user->discriminator, + 'avatar' => $user->avatar, + ]; + } + + public function tournament() { return $this->belongsTo(Tournament::class); } @@ -17,4 +68,16 @@ class Protocol extends Model return $this->belongsTo(User::class); } + + protected $casts = [ + 'details' => 'array', + ]; + + protected $fillable = [ + 'details', + 'tournament_id', + 'type', + 'user_id', + ]; + }