[#2] networks
This commit is contained in:
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Network extends Model
|
||||||
|
{
|
||||||
|
protected $fillable = [
|
||||||
|
'tmdb_id',
|
||||||
|
'logo_path',
|
||||||
|
'name',
|
||||||
|
'slug',
|
||||||
|
'origin_country',
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -75,4 +75,9 @@ class Show extends Model
|
|||||||
{
|
{
|
||||||
return $this->belongsToMany(Genre::class, 'show_genres', 'show_id', 'genre_id');
|
return $this->belongsToMany(Genre::class, 'show_genres', 'show_id', 'genre_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function networks()
|
||||||
|
{
|
||||||
|
return $this->belongsToMany(Network::class, 'show_networks', 'show_id', 'network_id');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ use App\Models\Image;
|
|||||||
use App\Models\ItemToFetch;
|
use App\Models\ItemToFetch;
|
||||||
use App\Models\ItemToFetchJobs;
|
use App\Models\ItemToFetchJobs;
|
||||||
use App\Models\Keyword;
|
use App\Models\Keyword;
|
||||||
|
use App\Models\Network;
|
||||||
use App\Models\Person;
|
use App\Models\Person;
|
||||||
use App\Models\Season;
|
use App\Models\Season;
|
||||||
use App\Models\Show;
|
use App\Models\Show;
|
||||||
@@ -80,9 +81,11 @@ class ShowProcessingService implements ProcessingInterface
|
|||||||
$this->processGenres($item, $tmdbShow['genres']);
|
$this->processGenres($item, $tmdbShow['genres']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @todo process genres
|
if (!empty($tmdbShow['networks'])) {
|
||||||
|
$this->processNetworks($item, $tmdbShow['networks']);
|
||||||
|
}
|
||||||
|
|
||||||
// @todo process created_by
|
// @todo process created_by
|
||||||
// @todo process networks
|
|
||||||
// @todo process production countries
|
// @todo process production countries
|
||||||
// @todo process production companies
|
// @todo process production companies
|
||||||
|
|
||||||
@@ -762,4 +765,33 @@ class ShowProcessingService implements ProcessingInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function processNetworks($item, array $networks)
|
||||||
|
{
|
||||||
|
foreach ($networks as $tmdbNetwork) {
|
||||||
|
$network = Network::where('name', $tmdbNetwork['name'])
|
||||||
|
->where('tmdb_id', $tmdbNetwork['id'])
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (!$network) {
|
||||||
|
$network = Network::create([
|
||||||
|
'name' => $tmdbNetwork['name'],
|
||||||
|
'slug' => Str::slug($tmdbNetwork['name']),
|
||||||
|
'tmdb_id' => $tmdbNetwork['id'],
|
||||||
|
'logo_path' => $tmdbNetwork['logo_path'],
|
||||||
|
'origin_country' => $tmdbNetwork['origin_country'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$show = Show::where('tmdb_id', $item->tmdb_id)->first();
|
||||||
|
|
||||||
|
if ($show->whereHas('networks', function ($query) use ($network) {
|
||||||
|
$query->where('tmdb_id', '=', $network->tmdb_id);
|
||||||
|
})->exists()) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
$show->networks()->attach($network);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('show_networks', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->unsignedBigInteger('show_id');
|
||||||
|
$table->unsignedBigInteger('network_id');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('show_networks');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('networks', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->unsignedBigInteger('tmdb_id');
|
||||||
|
$table->string('logo_path')->nullable();
|
||||||
|
$table->string('name')->nullable();
|
||||||
|
$table->string('slug')->nullable();
|
||||||
|
$table->string('origin_country')->nullable();
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('networks');
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user