mirror of
https://github.com/devfake/flox.git
synced 2024-11-15 14:42:31 +01:00
7d7553088c
* move to local scope * start file parser * flatten controller * update tests * composer update * Update tests, include episodes * store src for tv episodes * simplify fixtures * refactor * refactor episode and alternative title * refactor item category * fix typo and remove exception
64 lines
1.4 KiB
PHP
64 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
use App\Services\TMDB;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Episode extends Model {
|
|
|
|
public $timestamps = false;
|
|
|
|
protected $fillable = [
|
|
'tmdb_id',
|
|
'name',
|
|
'season_number',
|
|
'episode_number',
|
|
'episode_tmdb_id',
|
|
'seen',
|
|
'season_tmdb_id',
|
|
'created_at'
|
|
];
|
|
|
|
/**
|
|
* Save all episodes of each season.
|
|
*
|
|
* @param $seasons
|
|
* @param $tmdbId
|
|
*/
|
|
public function store($tmdbId, TMDB $tmdb)
|
|
{
|
|
$seasons = $tmdb->tvEpisodes($tmdbId);
|
|
|
|
foreach($seasons as $season) {
|
|
foreach($season->episodes as $episode) {
|
|
$this->create([
|
|
'season_tmdb_id' => $season->id,
|
|
'episode_tmdb_id' => $episode->id,
|
|
'season_number' => $episode->season_number,
|
|
'episode_number' => $episode->episode_number,
|
|
'name' => $episode->name,
|
|
'tmdb_id' => $tmdbId,
|
|
'created_at' => time(),
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Scopes
|
|
*/
|
|
|
|
public function scopeFindByTmdbId($query, $tmdbId)
|
|
{
|
|
return $query->where('tmdb_id', $tmdbId);
|
|
}
|
|
|
|
public function scopeFindEpisode($query, $tmdbId, $episode)
|
|
{
|
|
return $query->where('tmdb_id', $tmdbId)
|
|
->where('season_number', $episode->season_number)
|
|
->where('episode_number', $episode->episode_number);
|
|
}
|
|
}
|