2024-12-30 01:51:28 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
2025-01-04 03:22:13 +02:00
|
|
|
/**
|
|
|
|
|
* @property int $tmdb_id
|
|
|
|
|
*/
|
2024-12-30 01:51:28 +02:00
|
|
|
class Show extends Model
|
|
|
|
|
{
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'adult',
|
|
|
|
|
'backdrop_path',
|
|
|
|
|
'episode_run_time',
|
|
|
|
|
'first_air_date',
|
|
|
|
|
'homepage',
|
|
|
|
|
'tmdb_id',
|
|
|
|
|
'in_production',
|
|
|
|
|
'languages',
|
|
|
|
|
'last_air_date',
|
|
|
|
|
'name',
|
|
|
|
|
'slug',
|
|
|
|
|
'number_of_episodes',
|
|
|
|
|
'number_of_seasons',
|
|
|
|
|
'origin_country',
|
|
|
|
|
'original_language',
|
|
|
|
|
'original_name',
|
|
|
|
|
'overview',
|
|
|
|
|
'popularity',
|
|
|
|
|
'poster_path',
|
|
|
|
|
'status',
|
|
|
|
|
'tagline',
|
|
|
|
|
'type',
|
|
|
|
|
'vote_average',
|
|
|
|
|
'vote_count',
|
|
|
|
|
];
|
2025-01-04 04:02:10 +02:00
|
|
|
|
2025-02-10 01:58:12 +02:00
|
|
|
protected $casts = [
|
|
|
|
|
'first_air_date' => 'date',
|
|
|
|
|
'last_air_date' => 'date',
|
|
|
|
|
'languages' => 'array',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
public function wasListedBy(string $listSlug, User $user)
|
|
|
|
|
{
|
|
|
|
|
$mediaList = MediaList::where('slug', $listSlug)->where('user_id', $user->id)->first();
|
|
|
|
|
|
|
|
|
|
if ($mediaList) {
|
|
|
|
|
$mediaListItem = MediaListItem::where('media_list_id', $mediaList->id)
|
|
|
|
|
->where('item_id', $this->id)
|
|
|
|
|
->where('item_type', 'show')
|
|
|
|
|
->first();
|
|
|
|
|
|
|
|
|
|
return !empty($mediaListItem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function ratingBy(User $user)
|
|
|
|
|
{
|
|
|
|
|
$rating = Rate::where('user_id', $user->id)
|
|
|
|
|
->where('item_id', $this->id)
|
|
|
|
|
->where('item_type', 'show')
|
|
|
|
|
->first();
|
|
|
|
|
|
|
|
|
|
return $rating ? $rating->rate : null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function externalIds()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasOne(ExternalId::class, 'entity_id', 'id')
|
|
|
|
|
->where('external_ids.entity_type', 'show');
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-04 04:02:10 +02:00
|
|
|
public function castList()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(Person::class, 'show_cast', 'show_id', 'person_id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function crewList()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(Person::class, 'show_crew', 'show_id', 'person_id');
|
|
|
|
|
}
|
2025-01-07 23:39:22 +02:00
|
|
|
|
2025-02-10 01:58:12 +02:00
|
|
|
public function images(string $type = 'posters')
|
2025-01-07 23:39:22 +02:00
|
|
|
{
|
2025-02-10 01:58:12 +02:00
|
|
|
if ($type === Image::TYPE_POSTER) {
|
|
|
|
|
return $this->belongsToMany(Image::class, 'show_images', 'show_id', 'image_id')
|
|
|
|
|
->where('type', Image::TYPE_POSTER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->belongsToMany(Image::class, 'show_images', 'show_id', 'image_id')
|
|
|
|
|
->where('type', '=', Image::TYPE_BACKDROP);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function posters()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(Image::class, 'show_images', 'show_id', 'image_id')
|
|
|
|
|
->where('type', Image::TYPE_POSTER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function backdrops()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(Image::class, 'show_images', 'show_id', 'image_id')
|
|
|
|
|
->where('type', '=', Image::TYPE_BACKDROP);
|
2025-01-07 23:39:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function videos()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(Video::class, 'show_videos', 'show_id', 'video_id');
|
|
|
|
|
}
|
2025-01-08 01:25:21 +02:00
|
|
|
|
|
|
|
|
public function keywords()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(Keyword::class, 'show_keywords', 'show_id', 'keyword_id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function watchProviders()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(WatchProvider::class, 'show_watch_providers', 'show_id', 'watch_provider_id');
|
|
|
|
|
}
|
2025-01-08 01:50:31 +02:00
|
|
|
|
|
|
|
|
public function contentRatings()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(ContentRating::class, 'show_content_ratings', 'show_id', 'content_rating_id');
|
|
|
|
|
}
|
2025-01-08 02:08:41 +02:00
|
|
|
|
|
|
|
|
public function genres()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(Genre::class, 'show_genres', 'show_id', 'genre_id');
|
|
|
|
|
}
|
2025-01-08 02:15:22 +02:00
|
|
|
|
|
|
|
|
public function networks()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(Network::class, 'show_networks', 'show_id', 'network_id');
|
|
|
|
|
}
|
2025-01-09 16:01:38 +02:00
|
|
|
|
|
|
|
|
public function productionCompanies()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(ProductionCompany::class, 'show_production_companies', 'show_id', 'production_company_id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function productionCountries()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(ProductionCountry::class, 'show_production_countries', 'show_id', 'production_country_id');
|
|
|
|
|
}
|
2024-12-30 01:51:28 +02:00
|
|
|
}
|