[#2] content ratings
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ContentRating extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'descriptors',
|
||||
'iso_3166',
|
||||
'rating',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'descriptors' => 'array',
|
||||
];
|
||||
}
|
||||
@@ -65,4 +65,9 @@ class Show extends Model
|
||||
{
|
||||
return $this->belongsToMany(WatchProvider::class, 'show_watch_providers', 'show_id', 'watch_provider_id');
|
||||
}
|
||||
|
||||
public function contentRatings()
|
||||
{
|
||||
return $this->belongsToMany(ContentRating::class, 'show_content_ratings', 'show_id', 'content_rating_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Service\MediaProcessing;
|
||||
|
||||
use App\Models\Comment;
|
||||
use App\Models\ContentRating;
|
||||
use App\Models\Episode;
|
||||
use App\Models\ExternalId;
|
||||
use App\Models\Image;
|
||||
@@ -491,7 +492,36 @@ class ShowProcessingService implements ProcessingInterface
|
||||
|
||||
private function getContentRatings($item)
|
||||
{
|
||||
$tmdbContentRatings = $this->showsApi->getContentRatings($item->tmdb_id);
|
||||
|
||||
if (empty($tmdbContentRatings) || empty($tmdbContentRatings['results'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$show = Show::where('tmdb_id', $item->tmdb_id)->first();
|
||||
|
||||
foreach ($tmdbContentRatings['results'] as $contentRating) {
|
||||
$existingContentRating = ContentRating::where('iso_3166', $contentRating['iso_3166_1'])
|
||||
->where('rating', $contentRating['rating'])
|
||||
->first();
|
||||
|
||||
if (!$existingContentRating) {
|
||||
$existingContentRating = ContentRating::create([
|
||||
'descriptors' => $contentRating['descriptors'],
|
||||
'iso_3166' => $contentRating['iso_3166_1'],
|
||||
'rating' => $contentRating['rating'],
|
||||
]);
|
||||
}
|
||||
|
||||
// attach if not attached
|
||||
if (!$show->whereHas('contentRatings', function ($query) use ($show) {
|
||||
$query->where('show_id', $show->id);
|
||||
})->exists()) {
|
||||
$show->contentRatings()->attach($existingContentRating);
|
||||
}
|
||||
}
|
||||
|
||||
$this->removeElementFromRemainingJobs($item->tmdb_id, ItemToFetchJobs::JOB_CONTENT_RATINGS);
|
||||
}
|
||||
|
||||
private function processSeasons(Show $show, array $seasons)
|
||||
|
||||
Reference in New Issue
Block a user