mirror of
https://github.com/devfake/flox.git
synced 2024-11-15 14:42:31 +01:00
1a1753181f
* create genres table and translate media_type * parse genres from TMDb and modify artisan db command * parse genres on migration * Save genres in new table (via relation) * Implode genres as string. Update genres in refresh. * add tests for genres * fix icon for src * display genres on own page include few ui tweaks
40 lines
979 B
PHP
40 lines
979 B
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Services\Models\ItemService;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class Subpage {
|
|
|
|
private $itemService;
|
|
private $tmdb;
|
|
|
|
public function __construct(ItemService $itemService, TMDB $tmdb)
|
|
{
|
|
$this->itemService = $itemService;
|
|
$this->tmdb = $tmdb;
|
|
}
|
|
|
|
public function item($tmdbId, $mediaType)
|
|
{
|
|
if($found = $this->itemService->findBy('tmdb_id', $tmdbId)) {
|
|
return $found;
|
|
}
|
|
|
|
$found = $this->tmdb->details($tmdbId, $mediaType);
|
|
|
|
if( ! (array) $found) {
|
|
return response('Not found', Response::HTTP_NOT_FOUND);
|
|
}
|
|
|
|
$found->genre_ids = collect($found->genres)->pluck('id')->all();
|
|
|
|
$item = $this->tmdb->createItem($found, $mediaType);
|
|
$item['youtube_key'] = $this->itemService->parseYoutubeKey($found, $mediaType);
|
|
$item['imdb_id'] = $this->itemService->parseImdbId($found);
|
|
|
|
return $item;
|
|
}
|
|
}
|