2016-10-10 10:57:39 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Item;
|
2017-01-23 22:26:04 +01:00
|
|
|
use App\Services\Models\AlternativeTitleService;
|
|
|
|
use App\Services\Models\EpisodeService;
|
|
|
|
use App\Services\Models\ItemService;
|
2016-10-18 14:26:24 +02:00
|
|
|
use App\Services\Storage;
|
2016-10-10 10:57:39 +02:00
|
|
|
use App\Services\TMDB;
|
|
|
|
use Illuminate\Support\Facades\Input;
|
|
|
|
|
|
|
|
class ItemController {
|
|
|
|
|
|
|
|
private $item;
|
2016-10-18 14:26:24 +02:00
|
|
|
private $storage;
|
2017-01-23 22:26:04 +01:00
|
|
|
private $tmdb;
|
2016-10-10 10:57:39 +02:00
|
|
|
|
|
|
|
/**
|
2017-01-24 16:11:47 +01:00
|
|
|
* Get the amount of loading items and create an instance for 'item'.
|
2016-10-10 10:57:39 +02:00
|
|
|
*
|
2017-01-06 13:00:18 +01:00
|
|
|
* @param Item $item
|
2016-10-18 14:26:24 +02:00
|
|
|
* @param Storage $storage
|
2017-01-23 22:26:04 +01:00
|
|
|
* @param TMDB $tmdb
|
2016-10-10 10:57:39 +02:00
|
|
|
*/
|
2017-01-23 22:26:04 +01:00
|
|
|
public function __construct(Item $item, Storage $storage, TMDB $tmdb)
|
2016-10-10 10:57:39 +02:00
|
|
|
{
|
|
|
|
$this->item = $item;
|
2016-10-18 14:26:24 +02:00
|
|
|
$this->storage = $storage;
|
2017-01-23 22:26:04 +01:00
|
|
|
$this->tmdb = $tmdb;
|
2016-10-10 10:57:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-11-28 08:48:12 +01:00
|
|
|
* Return all items with pagination.
|
2016-10-10 10:57:39 +02:00
|
|
|
*
|
2017-01-23 22:26:04 +01:00
|
|
|
* @param ItemService $item
|
|
|
|
* @param $type
|
|
|
|
* @param $orderBy
|
2016-10-10 10:57:39 +02:00
|
|
|
* @return mixed
|
|
|
|
*/
|
2017-01-23 22:26:04 +01:00
|
|
|
public function items(ItemService $itemService, $type, $orderBy)
|
2016-10-10 10:57:39 +02:00
|
|
|
{
|
2017-01-23 22:26:04 +01:00
|
|
|
return $itemService->getWithPagination($type, $orderBy);
|
2016-11-28 08:48:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all Episodes of an tv show.
|
|
|
|
*
|
2017-01-23 22:26:04 +01:00
|
|
|
* @param EpisodeService $episodeService
|
|
|
|
* @param $tmdbId
|
|
|
|
* @return array
|
2016-11-28 08:48:12 +01:00
|
|
|
*/
|
2017-01-23 22:26:04 +01:00
|
|
|
public function episodes(EpisodeService $episodeService, $tmdbId)
|
2016-11-28 08:48:12 +01:00
|
|
|
{
|
2017-01-23 22:26:04 +01:00
|
|
|
return $episodeService->getAllByTmdbId($tmdbId);
|
2016-10-10 10:57:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Search for items by 'title' in database or with Laravel Scout.
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function search()
|
|
|
|
{
|
|
|
|
$title = Input::get('q');
|
|
|
|
|
|
|
|
if(config('scout.driver')) {
|
2017-02-13 18:47:30 +01:00
|
|
|
return $this->item->search($title)->with('latestEpisode')->get();
|
2016-10-10 10:57:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// We don't have an smart search driver and return an simple 'like' query.
|
2017-02-13 18:47:30 +01:00
|
|
|
return $this->item->findByTitle($title)->with('latestEpisode')->get();
|
2016-10-10 10:57:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update rating for an movie.
|
|
|
|
*
|
2017-01-23 22:26:04 +01:00
|
|
|
* @param ItemService $itemService
|
|
|
|
* @param $itemId
|
2016-10-10 10:57:39 +02:00
|
|
|
* @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
|
|
|
|
*/
|
2017-01-23 22:26:04 +01:00
|
|
|
public function changeRating(ItemService $itemService, $itemId)
|
2016-10-10 10:57:39 +02:00
|
|
|
{
|
2017-01-31 10:03:58 +01:00
|
|
|
return $itemService->changeRating($itemId, Input::get('rating'));
|
2016-10-10 10:57:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-06 13:00:18 +01:00
|
|
|
* Create a new movie / tv show.
|
2016-10-10 10:57:39 +02:00
|
|
|
*
|
2017-01-23 22:26:04 +01:00
|
|
|
* @param ItemService $item
|
2016-10-10 10:57:39 +02:00
|
|
|
* @return Item
|
|
|
|
*/
|
2017-01-23 22:26:04 +01:00
|
|
|
public function add(ItemService $item)
|
2016-10-10 10:57:39 +02:00
|
|
|
{
|
2017-01-23 22:26:04 +01:00
|
|
|
return $item->create(Input::get('item'));
|
2016-10-10 10:57:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-23 22:26:04 +01:00
|
|
|
* Delete movie or tv show (with episodes and alternative titles).
|
|
|
|
* Also remove the poster image file.
|
2016-10-10 10:57:39 +02:00
|
|
|
*
|
2017-01-23 22:26:04 +01:00
|
|
|
* @param ItemService $itemService
|
|
|
|
* @param $itemId
|
2016-10-10 10:57:39 +02:00
|
|
|
* @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
|
|
|
|
*/
|
2017-01-23 22:26:04 +01:00
|
|
|
public function remove(ItemService $itemService, $itemId)
|
2016-10-10 10:57:39 +02:00
|
|
|
{
|
2017-01-23 22:26:04 +01:00
|
|
|
return $itemService->remove($itemId);
|
|
|
|
}
|
2016-11-28 08:48:12 +01:00
|
|
|
|
2017-01-23 22:26:04 +01:00
|
|
|
/**
|
|
|
|
* Update alternative titles for all tv shows and movies or specific item.
|
|
|
|
* For old versions of flox or to keep all alternative titles up to date.
|
|
|
|
*
|
|
|
|
* @param AlternativeTitleService $alternativeTitle
|
|
|
|
* @param null $tmdbID
|
|
|
|
*/
|
|
|
|
public function updateAlternativeTitles(AlternativeTitleService $alternativeTitle, $tmdbID = null)
|
|
|
|
{
|
|
|
|
$alternativeTitle->update($tmdbID);
|
2016-10-10 10:57:39 +02:00
|
|
|
}
|
|
|
|
|
2016-11-30 15:26:38 +01:00
|
|
|
/**
|
2017-01-23 22:26:04 +01:00
|
|
|
* Set an episode as seen / unseen.
|
2016-11-30 15:26:38 +01:00
|
|
|
*
|
2017-01-23 22:26:04 +01:00
|
|
|
* @param EpisodeService $episode
|
|
|
|
* @param $id
|
2016-11-30 15:26:38 +01:00
|
|
|
* @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
|
|
|
|
*/
|
2017-01-23 22:26:04 +01:00
|
|
|
public function toggleEpisode(EpisodeService $episode, $id)
|
2016-11-28 08:48:12 +01:00
|
|
|
{
|
2017-01-23 22:26:04 +01:00
|
|
|
if( ! $episode->toggleSeen($id)) {
|
2016-11-28 08:48:12 +01:00
|
|
|
return response('Server Error', 500);
|
|
|
|
}
|
|
|
|
|
2017-01-23 22:26:04 +01:00
|
|
|
return response('Success', 200);
|
2017-01-06 09:40:27 +01:00
|
|
|
}
|
|
|
|
|
2016-11-30 15:26:38 +01:00
|
|
|
/**
|
2017-01-23 22:26:04 +01:00
|
|
|
* Toggle all episodes of an season as seen / unseen.
|
2016-11-30 15:26:38 +01:00
|
|
|
*/
|
2017-01-23 22:26:04 +01:00
|
|
|
public function toggleSeason(EpisodeService $episode)
|
2016-11-30 15:26:38 +01:00
|
|
|
{
|
2017-01-06 09:40:27 +01:00
|
|
|
$tmdbId = Input::get('tmdb_id');
|
2016-11-30 15:26:38 +01:00
|
|
|
$season = Input::get('season');
|
|
|
|
$seen = Input::get('seen');
|
|
|
|
|
2017-01-23 22:26:04 +01:00
|
|
|
$episode->toggleSeason($tmdbId, $season, $seen);
|
2016-11-30 15:26:38 +01:00
|
|
|
}
|
2017-01-06 09:40:27 +01:00
|
|
|
}
|