belongsToMany(Channel::class) ->using(Restream::class) ->withPivot('accept_comms', 'accept_tracker'); } public function crew() { return $this->hasMany(EpisodeCrew::class); } public function confirmedCrew() { 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); } public function players() { return $this->hasMany(EpisodePlayer::class); } public function getScheduledEventName(): string { $parts = []; if (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 { if ($this->comment != '') { return $this->comment; } return ''; } 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', ]; protected $hidden = [ 'created_at', 'updated_at', ]; }