mirror of
https://github.com/devfake/flox.git
synced 2024-11-15 14:42:31 +01:00
5818026f67
* change parser fixtures * move alternativeTitle method to other class * refactor tests * start with alternative title * use app helper method * refactor add items * change fixtures structure * alternative title * episode service * item service * file parser test * flatten item controller * git ignorecase
69 lines
1.5 KiB
PHP
69 lines
1.5 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',
|
|
'src',
|
|
'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($seasons, $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);
|
|
}
|
|
|
|
public function scopeFindSeason($query, $tmdbId, $season)
|
|
{
|
|
return $query->where('tmdb_id', $tmdbId)
|
|
->where('season_number', $season);
|
|
}
|
|
}
|