1
0
mirror of https://github.com/devfake/flox.git synced 2024-11-15 14:42:31 +01:00
flox/backend/app/Http/Controllers/ItemController.php

154 lines
4.1 KiB
PHP
Raw Normal View History

2016-10-10 10:57:39 +02:00
<?php
namespace App\Http\Controllers;
use App\Item;
use App\Services\Models\AlternativeTitleService;
use App\Services\Models\EpisodeService;
use App\Services\Models\ItemService;
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;
private $storage;
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
*
* @param Item $item
* @param Storage $storage
* @param TMDB $tmdb
2016-10-10 10:57:39 +02:00
*/
public function __construct(Item $item, Storage $storage, TMDB $tmdb)
2016-10-10 10:57:39 +02:00
{
$this->item = $item;
$this->storage = $storage;
$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
*
* @param ItemService $itemService
* @param $type
* @param $orderBy
2016-10-10 10:57:39 +02:00
* @return mixed
* @internal param ItemService $item
2016-10-10 10:57:39 +02:00
*/
public function items(ItemService $itemService, $type, $orderBy)
2016-10-10 10:57:39 +02:00
{
return $itemService->getWithPagination($type, $orderBy);
2016-11-28 08:48:12 +01:00
}
/**
* Get all Episodes of an tv show.
*
* @param EpisodeService $episodeService
* @param $tmdbId
* @return array
2016-11-28 08:48:12 +01:00
*/
public function episodes(EpisodeService $episodeService, $tmdbId)
2016-11-28 08:48:12 +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')) {
return $this->item->search($title)->with('latestEpisode')->withCount('episodesWithSrc')->get();
2016-10-10 10:57:39 +02:00
}
// We don't have an smart search driver and return an simple 'like' query.
return $this->item->findByTitle($title)->with('latestEpisode')->withCount('episodesWithSrc')->get();
2016-10-10 10:57:39 +02:00
}
/**
* Update rating for an movie.
*
* @param ItemService $itemService
* @param $itemId
2016-10-10 10:57:39 +02:00
* @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
*/
public function changeRating(ItemService $itemService, $itemId)
2016-10-10 10:57:39 +02:00
{
return $itemService->changeRating($itemId, Input::get('rating'));
2016-10-10 10:57:39 +02:00
}
/**
* Create a new movie / tv show.
2016-10-10 10:57:39 +02:00
*
* @param ItemService $item
2016-10-10 10:57:39 +02:00
* @return Item
*/
public function add(ItemService $item)
2016-10-10 10:57:39 +02:00
{
return $item->create(Input::get('item'));
2016-10-10 10:57:39 +02: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
*
* @param ItemService $itemService
* @param $itemId
2016-10-10 10:57:39 +02:00
* @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
*/
public function remove(ItemService $itemService, $itemId)
2016-10-10 10:57:39 +02:00
{
return $itemService->remove($itemId);
}
2016-11-28 08:48:12 +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
/**
* Set an episode as seen / unseen.
2016-11-30 15:26:38 +01:00
*
* @param EpisodeService $episode
* @param $id
2016-11-30 15:26:38 +01:00
* @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
*/
public function toggleEpisode(EpisodeService $episode, $id)
2016-11-28 08:48:12 +01:00
{
if( ! $episode->toggleSeen($id)) {
2016-11-28 08:48:12 +01:00
return response('Server Error', 500);
}
return response('Success', 200);
}
2016-11-30 15:26:38 +01:00
/**
* Toggle all episodes of an season as seen / unseen.
*
* @param EpisodeService $episode
2016-11-30 15:26:38 +01:00
*/
public function toggleSeason(EpisodeService $episode)
2016-11-30 15:26:38 +01:00
{
$tmdbId = Input::get('tmdb_id');
2016-11-30 15:26:38 +01:00
$season = Input::get('season');
$seen = Input::get('seen');
$episode->toggleSeason($tmdbId, $season, $seen);
2016-11-30 15:26:38 +01:00
}
}