1
0
mirror of https://github.com/devfake/flox.git synced 2024-11-16 07:02:31 +01:00
flox/backend/app/Services/Models/AlternativeTitleService.php
Viktor Geringer 5818026f67 Refactor models (#27)
* 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
2017-02-13 21:17:25 +01:00

60 lines
1.1 KiB
PHP

<?php
namespace App\Services\Models;
use App\AlternativeTitle as Model;
use App\Item;
use App\Services\TMDB;
class AlternativeTitleService {
private $model;
private $item;
private $tmdb;
/**
* @param Model $model
* @param Item $item
* @param TMDB $tmdb
*/
public function __construct(Model $model, Item $item, TMDB $tmdb)
{
$this->model = $model;
$this->item = $item;
$this->tmdb = $tmdb;
}
/**
* @param $item
*/
public function create($item)
{
$titles = $this->tmdb->getAlternativeTitles($item);
$this->model->store($titles, $item->tmdb_id);
}
/**
* Remove all titles by tmdb_id.
*
* @param $tmdbId
*/
public function remove($tmdbId)
{
$this->model->where('tmdb_id', $tmdbId)->delete();
}
/**
* @param null $tmdbId
*/
public function update($tmdbId = null)
{
set_time_limit(3000);
$items = $tmdbId ? $this->item->findByTmdbId($tmdbId)->get() : $this->item->all();
$items->each(function($item) {
$this->create($item);
});
}
}