Add MyShowsController, adjust rest of the controllers and classes

This commit is contained in:
DariusIII
2018-04-13 13:47:03 +02:00
parent da476649c6
commit 624a5d7a5f
6 changed files with 276 additions and 103 deletions
+50 -99
View File
@@ -370,120 +370,71 @@ class Releases
/**
* Get TV for my shows page.
*
* @param $userShows
* @param int|bool $offset
* @param int $limit
* @param string|array $orderBy
* @param int $maxAge
* @param array $excludedCats
*
* @return array
* @param $userShows
* @param $orderBy
* @param int $maxAge
* @param array $excludedCats
*
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|mixed
* @throws \Exception
*/
public function getShowsRange($userShows, $offset, $limit, $orderBy, $maxAge = -1, array $excludedCats = []): array
public function getShowsRange($userShows, $orderBy, $maxAge = -1, array $excludedCats = [])
{
$orderBy = $this->getBrowseOrder($orderBy);
$sql = sprintf(
"SELECT r.*,
CONCAT(cp.title, '-', c.title) AS category_name,
%s AS category_ids,
g.name AS group_name,
rn.releases_id AS nfoid, re.releases_id AS reid,
tve.firstaired,
(SELECT df.failed) AS failed
FROM releases r
LEFT OUTER JOIN video_data re ON re.releases_id = r.id
LEFT JOIN groups g ON g.id = r.groups_id
LEFT OUTER JOIN release_nfos rn ON rn.releases_id = r.id
LEFT OUTER JOIN tv_episodes tve ON tve.videos_id = r.videos_id
LEFT JOIN categories c ON c.id = r.categories_id
LEFT JOIN categories cp ON cp.id = c.parentid
LEFT OUTER JOIN dnzb_failures df ON df.release_id = r.id
WHERE r.categories_id BETWEEN 5000 AND 5999 %s %s
AND r.nzbstatus = %d
AND r.passwordstatus %s
%s
GROUP BY r.id
ORDER BY %s %s %s",
$this->getConcatenatedCategoryIDs(),
$this->uSQL($userShows, 'videos_id'),
(\count($excludedCats) ? ' AND r.categories_id NOT IN ('.implode(',', $excludedCats).')' : ''),
NZB::NZB_ADDED,
$this->showPasswords,
($maxAge > 0 ? sprintf(' AND r.postdate > NOW() - INTERVAL %d DAY ', $maxAge) : ''),
$orderBy[0],
$orderBy[1],
($offset === false ? '' : (' LIMIT '.$limit.' OFFSET '.$offset))
);
$releases = Cache::get(md5($sql));
$sql = Release::query()
->with('group as g', 'nfo as rn', 'category as c', 'failed as df', 'episode as tve')
->select(
[
'r.*',
\Illuminate\Support\Facades\DB::raw("CONCAT(cp.title, '-', c.title) AS category_name"),
'g.name as group_name',
'rn.releases_id as nfoid',
're.releases_id as reid',
'tve.firstaired',
'df.failed as failed',
]
)
->leftJoin('video_date as re', 're.releases_id', '=', 'releases.id')
->leftJoin('categories as cp', 'cp.id', '=', 'c.parentid')
->whereBetween('releases.categories_id', [5000, 5999])
->where('releases.nzbstatus', NZB::NZB_ADDED);
self::showPasswords($sql, true);
foreach ($userShows as $query) {
$sql->orWhere('releases.videos_id', '=', $query['videos_id']);
if ($query['categories'] !== '') {
$catsArr = explode('|', $query['categories']);
if (\count($catsArr) > 1) {
$sql->whereIn('releases.categories_id', $catsArr);
} else {
$sql->where('releases.categories_id', $catsArr[0]);
}
}
}
if (\count($excludedCats) > 0) {
$sql->whereNotIn('releases.categories_id', $excludedCats);
}
if ($maxAge > 0) {
$sql->where('releases.postdate', '>', Carbon::now()->subDays($maxAge));
}
$sql->orderBy($orderBy[0], $orderBy[1]);
$releases = Cache::get(md5(implode('.', $userShows).implode('.', $orderBy).$maxAge.implode('.', $excludedCats)));
if ($releases !== null) {
return $releases;
}
$releases = $this->pdo->query($sql);
$releases = $sql->paginate(config('nntmux.items_per_page'));
$expiresAt = Carbon::now()->addSeconds(config('nntmux.cache_expiry_medium'));
Cache::put(md5($sql), $releases, $expiresAt);
Cache::put(md5(implode('.', $userShows).implode('.', $orderBy).$maxAge.implode('.', $excludedCats)), $releases, $expiresAt);
return $releases;
}
/**
* Get count for my shows page pagination.
*
* @param $userShows
* @param int $maxAge
* @param array $excludedCats
*
* @return int
*/
public function getShowsCount($userShows, $maxAge = -1, array $excludedCats = []): int
{
return $this->getPagerCount(
sprintf(
'SELECT r.id
FROM releases r
WHERE r.categories_id BETWEEN 5000 AND 5999 %s %s
AND r.nzbstatus = %d
AND r.passwordstatus %s
%s',
$this->uSQL($userShows, 'videos_id'),
(\count($excludedCats) ? ' AND r.categories_id NOT IN ('.implode(',', $excludedCats).')' : ''),
NZB::NZB_ADDED,
$this->showPasswords,
($maxAge > 0 ? sprintf(' AND r.postdate > NOW() - INTERVAL %d DAY ', $maxAge) : '')
)
);
}
/**
* Get count for my shows page pagination.
*
* @param $userMovies
* @param int $maxAge
* @param array $excludedCats
*
* @return int
*/
public function getMovieCount($userMovies, $maxAge = -1, array $excludedCats = []): int
{
return $this->getPagerCount(
sprintf(
'SELECT r.id
FROM releases r
WHERE r.categories_id BETWEEN 3000 AND 3999 %s %s
AND r.nzbstatus = %d
AND r.passwordstatus %s
%s',
$this->uSQL($userMovies, 'imdbid'),
(\count($excludedCats) ? ' AND r.categories_id NOT IN ('.implode(',', $excludedCats).')' : ''),
NZB::NZB_ADDED,
$this->showPasswords,
($maxAge > 0 ? sprintf(' AND r.postdate > NOW() - INTERVAL %d DAY ', $maxAge) : '')
)
);
}
/**
* Delete multiple releases, or a single by ID.
*
+1
View File
@@ -1,4 +1,5 @@
2018-04-13 DariusIII
* Chg: Add MyShowsController, adjust rest of the controllers and classes
* Chg: Add MyMoviesController
* Fix: Fix search
2018-04-12 DariusIII
+10 -2
View File
@@ -153,10 +153,18 @@ class BasePageController extends Controller
/**
* Show 404 page.
*
* @param $message
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function show404(): void
public function show404($message = null)
{
abort(404);
if ($message !== null) {
return view('errors.404')->with('Message', $message);
}
return view('errors.404');
}
/**
+1 -1
View File
@@ -56,7 +56,7 @@ class DetailsController extends BasePageController
$reAudio = $re->getAudio($data['id']);
$reSubs = $re->getSubs($data['id']);
$comments = ReleaseComment::getComments($data['id']);
$similars = $releases->searchSimilar($data['id'], $data['searchname'], 6, $this->userdata['categoryexclusions']);
$similars = $releases->searchSimilar($data['id'], $data['searchname'], $this->userdata['categoryexclusions']);
$failed = DnzbFailure::getFailedCount($data['id']);
$showInfo = '';
+209
View File
@@ -0,0 +1,209 @@
<?php
namespace App\Http\Controllers;
use App\Models\Category;
use App\Models\Settings;
use App\Models\UserSerie;
use App\Models\Video;
use Blacklight\Releases;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class MyShowsController extends BasePageController
{
/**
* @param \Illuminate\Http\Request $request
*
* @throws \Exception
*/
public function show(Request $request)
{
$this->setPrefs();
$action = $request->input('id') ?? '';
$videoId = $request->input('subpage') ?? '';
if ($request->has('from')) {
$this->smarty->assign('from', WWW_TOP.$request->input('from'));
} else {
$this->smarty->assign('from', WWW_TOP.'/myshows');
}
switch ($action) {
case 'delete':
$show = UserSerie::getShow(Auth::id(), $videoId);
if ($request->has('from')) {
header('Location:'.WWW_TOP.$request->input('from'));
} else {
return redirect('myshows');
}
if (! $show) {
$this->show404();
} else {
UserSerie::delShow(Auth::id(), $videoId);
}
break;
case 'add':
case 'doadd':
$show = UserSerie::getShow(Auth::id(), $videoId);
if ($show) {
$this->show404('Already subscribed');
} else {
$show = Video::getByVideoID($videoId);
if (! $show) {
$this->show404('No matching show.');
}
}
if ($action === 'doadd') {
$category = ($request->has('category') && is_array($request->input('category')) && ! empty($request->input('category'))) ? $request->input('category') : [];
UserSerie::addShow(Auth::id(), $videoId, $category);
if ($request->has('from')) {
header('Location:'.WWW_TOP.$request->input('from'));
} else {
return redirect('myshows');
}
} else {
$tmpcats = Category::getChildren(Category::TV_ROOT);
$categories = [];
foreach ($tmpcats as $c) {
// If TV WEB-DL categorization is disabled, don't include it as an option
if ((int) $c['id'] === Category::TV_WEBDL && (int) Settings::settingValue('indexer.categorise.catwebdl') === 0) {
continue;
}
$categories[$c['id']] = $c['title'];
}
$this->smarty->assign('type', 'add');
$this->smarty->assign('cat_ids', array_keys($categories));
$this->smarty->assign('cat_names', $categories);
$this->smarty->assign('cat_selected', []);
$this->smarty->assign('video', $videoId);
$this->smarty->assign('show', $show);
$content = $this->smarty->fetch('myshows-add.tpl');
$this->smarty->assign([
'content' => $content,
]);
$this->pagerender();
}
break;
case 'edit':
case 'doedit':
$show = UserSerie::getShow(Auth::id(), $videoId);
if (! $show) {
$this->show404();
}
if ($action === 'doedit') {
$category = ($request->has('category') && \is_array($request->input('category')) && ! empty($request->input('category'))) ? $request->input('category') : [];
UserSerie::updateShow(Auth::id(), $videoId, $category);
if ($request->has('from')) {
return redirect($request->input('from'));
}
return redirect('myshows');
}
$tmpcats = Category::getChildren(Category::TV_ROOT);
$categories = [];
foreach ($tmpcats as $c) {
$categories[$c['id']] = $c['title'];
}
$this->smarty->assign('type', 'edit');
$this->smarty->assign('cat_ids', array_keys($categories));
$this->smarty->assign('cat_names', $categories);
$this->smarty->assign('cat_selected', explode('|', $show['categories']));
$this->smarty->assign('video', $videoId);
$this->smarty->assign('show', $show);
$content = $this->smarty->fetch('myshows-add.tpl');
$this->smarty->assign([
'content' => $content,
]);
$this->pagerender();
break;
case 'browse':
$title = 'Browse My Shows';
$meta_title = 'My Shows';
$meta_keywords = 'search,add,to,cart,nzb,description,details';
$meta_description = 'Browse Your Shows';
$shows = UserSerie::getShows(Auth::id());
$releases = new Releases(['Settings' => $this->settings]);
$ordering = $releases->getBrowseOrdering();
$orderby = $request->has('ob') && \in_array($request->input('ob'), $ordering, false) ? $request->input('ob') : '';
$results = $releases->getShowsRange($shows, $orderby, -1, $this->userdata['categoryexclusions']);
$this->smarty->assign('covgroup', '');
foreach ($ordering as $ordertype) {
$this->smarty->assign('orderby'.$ordertype, WWW_TOP.'/myshows/browse?ob='.$ordertype.'&amp;offset=0');
}
$this->smarty->assign('lastvisit', $this->userdata['lastlogin']);
$this->smarty->assign('results', $results);
$this->smarty->assign('shows', true);
$content = $this->smarty->fetch('browse.tpl');
$this->smarty->assign([
'content' => $content,
'title' => $title,
'meta_title' => $meta_title,
'meta_keywords' => $meta_keywords,
'meta_description' => $meta_description,
]);
$this->pagerender();
break;
default:
$title = 'My Shows';
$meta_title = 'My Shows';
$meta_keywords = 'search,add,to,cart,nzb,description,details';
$meta_description = 'Manage Your Shows';
$tmpcats = Category::getChildren(Category::TV_ROOT);
$categories = [];
foreach ($tmpcats as $c) {
$categories[$c['id']] = $c['title'];
}
$shows = UserSerie::getShows(Auth::id());
$results = [];
foreach ($shows as $showk => $show) {
$showcats = explode('|', $show['categories']);
if (\is_array($showcats) && \count($showcats) > 0) {
$catarr = [];
foreach ($showcats as $scat) {
if (! empty($scat)) {
$catarr[] = $categories[$scat];
}
}
$show['categoryNames'] = implode(', ', $catarr);
} else {
$show['categoryNames'] = '';
}
$results[$showk] = $show;
}
$this->smarty->assign('shows', $results);
$content = $this->smarty->fetch('myshows.tpl');
$this->smarty->assign([
'content' => $content,
'title' => $title,
'meta_title' => $meta_title,
'meta_keywords' => $meta_keywords,
'meta_description' => $meta_description,
]);
$this->pagerender();
break;
}
}
}
+5 -1
View File
@@ -139,7 +139,11 @@ Route::post('search', 'SearchController@search');
Route::get('mymovies', 'MyMoviesController@show');
Route::post('mymovies', 'MymoviesController@show');
Route::post('mymovies', 'MyMoviesController@show');
Route::get('myshows', 'MyShowsController@show');
Route::post('myshows', 'MyShowsController@show');
Route::get('filelist/{guid}', 'FileListController@show');