X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FModels%2FEpisode.php;h=4b8a96a53e2061f527db4d88d089ac411f90e1d9;hb=HEAD;hp=1c16f7f4a9ac7f8fab1bf2719c666514fa2c45cc;hpb=4d1002bb1c326adfa751666e843d8af686069e13;p=alttp.git diff --git a/app/Models/Episode.php b/app/Models/Episode.php index 1c16f7f..df2418a 100644 --- a/app/Models/Episode.php +++ b/app/Models/Episode.php @@ -24,6 +24,10 @@ class Episode extends Model return $this->crew()->where('confirmed', true); } + public function confirmedCrewOfChannel(Channel $channel) { + return $this->confirmedCrew()->where('channel_id', '=', $channel->id); + } + public function event() { return $this->belongsTo(Event::class); } @@ -32,6 +36,60 @@ class Episode extends Model return $this->hasMany(EpisodePlayer::class); } + public function getScheduledEventName(): string { + $parts = []; + if (count($this->players) == 4) { + // $parts[] = $this->players[0]->getName().' and '.$this->players[2]->getName().' vs '.$this->players[1]->getName().' and '.$this->players[3]->getName(); + } elseif (count($this->players) > 1) { + $players = []; + foreach ($this->players as $player) { + $players[] = $player->getName(); + } + $parts[] = implode(' vs ', $players); + } + if ($this->title != '') { + $parts[] = $this->title; + } + if ($this->event->title != '') { + $parts[] = $this->event->title; + } + return implode(' - ', $parts); + } + + public function getScheduledEventDescription(): string { + $description = ''; + if (count($this->players) == 4) { + $description .= $this->players[0]->getName().' and '.$this->players[2]->getName() + .' vs '.$this->players[1]->getName().' and '.$this->players[3]->getName()."\n"; + } + if ($this->comment != '') { + $description .= $this->comment."\n"; + } + return $description; + } + + public function getRestreamLink(string $preferred_lang = ''): string { + if (count($this->channels) > 0) { + foreach ($this->channels as $channel) { + if (in_array($preferred_lang, $channel->languages)) { + return $channel->stream_link; + } + } + return $this->channels[0]->stream_link; + } + if (count($this->players) == 1) { + return $this->players[0]->getStreamLink(); + } + if (count($this->players) > 0) { + $link = 'https://multistre.am'; + foreach ($this->players as $player) { + $link .= '/'.$player->getTwitchName(); + } + return $link; + } + return ''; + } + protected $casts = [ 'confirmed' => 'boolean', 'start' => 'datetime', @@ -39,7 +97,6 @@ class Episode extends Model protected $hidden = [ 'created_at', - 'ext_id', 'updated_at', ];