1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Models\Category; |
6
|
|
|
use Blacklight\Console; |
7
|
|
|
use Blacklight\Genres; |
8
|
|
|
use Illuminate\Http\Request; |
9
|
|
|
use Illuminate\Support\Arr; |
10
|
|
|
|
11
|
|
|
class ConsoleController extends BasePageController |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @throws \Exception |
15
|
|
|
*/ |
16
|
|
|
public function show(Request $request, string $id = ''): void |
17
|
|
|
{ |
18
|
|
|
$this->setPreferences(); |
19
|
|
|
if ($id === 'WiiVare') { |
20
|
|
|
$id = 'WiiVareVC'; |
21
|
|
|
} |
22
|
|
|
$console = new Console; |
23
|
|
|
$gen = new Genres; |
24
|
|
|
|
25
|
|
|
$concats = Category::getChildren(Category::GAME_ROOT); |
26
|
|
|
$ctmp = []; |
27
|
|
|
foreach ($concats as $ccat) { |
28
|
|
|
$ctmp[] = |
29
|
|
|
[ |
30
|
|
|
'id' => $ccat->id, |
31
|
|
|
'title' => $ccat->title, |
32
|
|
|
]; |
33
|
|
|
} |
34
|
|
|
$category = $request->has('t') ? $request->input('t') : Category::GAME_ROOT; |
35
|
|
|
if ($id && \in_array($id, Arr::pluck($ctmp, 'title'), false)) { |
36
|
|
|
$cat = Category::query() |
37
|
|
|
->where('title', $id) |
38
|
|
|
->where('root_categories_id', '=', Category::GAME_ROOT) |
39
|
|
|
->first(['id']); |
40
|
|
|
$category = $cat !== null ? $cat['id'] : Category::GAME_ROOT; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$catarray = []; |
44
|
|
|
$catarray[] = $category; |
45
|
|
|
|
46
|
|
|
$this->smarty->assign('catlist', $ctmp); |
47
|
|
|
$this->smarty->assign('category', $category); |
48
|
|
|
$this->smarty->assign('categorytitle', $id); |
49
|
|
|
|
50
|
|
|
$ordering = $console->getConsoleOrdering(); |
51
|
|
|
$orderby = $request->has('ob') && \in_array($request->input('ob'), $ordering, false) ? $request->input('ob') : ''; |
52
|
|
|
$page = $request->has('page') && is_numeric($request->input('page')) ? $request->input('page') : 1; |
53
|
|
|
$offset = ($page - 1) * config('nntmux.items_per_cover_page'); |
54
|
|
|
|
55
|
|
|
$consoles = []; |
56
|
|
|
$rslt = $console->getConsoleRange($page, $catarray, $offset, config('nntmux.items_per_cover_page'), $orderby, $this->userdata->categoryexclusions); |
|
|
|
|
57
|
|
|
$results = $this->paginate($rslt ?? [], $rslt[0]->_totalcount ?? 0, config('nntmux.items_per_cover_page'), $page, $request->url(), $request->query()); |
58
|
|
|
|
59
|
|
|
$maxwords = 50; |
60
|
|
|
foreach ($results as $result) { |
61
|
|
|
if (! empty($result->review)) { |
62
|
|
|
$words = explode(' ', $result->review); |
63
|
|
|
if (\count($words) > $maxwords) { |
64
|
|
|
$newwords = \array_slice($words, 0, $maxwords); |
65
|
|
|
$result->review = implode(' ', $newwords).'...'; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
$consoles[] = $result; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$platform = ($request->has('platform') && ! empty($request->input('platform'))) ? stripslashes($request->input('platform')) : ''; |
72
|
|
|
$this->smarty->assign('platform', $platform); |
73
|
|
|
|
74
|
|
|
$title = ($request->has('title') && ! empty($request->input('title'))) ? stripslashes($request->input('title')) : ''; |
75
|
|
|
$this->smarty->assign('title', $title); |
76
|
|
|
|
77
|
|
|
$genres = $gen->getGenres(Genres::CONSOLE_TYPE, true); |
78
|
|
|
$tmpgnr = []; |
79
|
|
|
foreach ($genres as $gn) { |
80
|
|
|
$tmpgnr[$gn->id] = $gn->title; |
81
|
|
|
} |
82
|
|
|
$genre = ($request->has('genre') && array_key_exists($request->input('genre'), $tmpgnr)) ? $request->input('genre') : ''; |
83
|
|
|
$this->smarty->assign('genres', $genres); |
84
|
|
|
$this->smarty->assign('genre', $genre); |
85
|
|
|
|
86
|
|
|
if ((int) $category === -1) { |
87
|
|
|
$this->smarty->assign('catname', 'All'); |
88
|
|
|
} else { |
89
|
|
|
$cdata = Category::find($category); |
90
|
|
|
if ($cdata !== null) { |
91
|
|
|
$this->smarty->assign('catname', $cdata); |
92
|
|
|
} else { |
93
|
|
|
$this->smarty->assign('catname', 'All'); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
$this->smarty->assign( |
98
|
|
|
[ |
99
|
|
|
'resultsadd' => $consoles, |
100
|
|
|
'results' => $results, |
101
|
|
|
'covgroup' => 'console', |
102
|
|
|
] |
103
|
|
|
); |
104
|
|
|
|
105
|
|
|
$meta_title = 'Browse Console'; |
106
|
|
|
$meta_keywords = 'browse,nzb,console,games,description,details'; |
107
|
|
|
$meta_description = 'Browse for Console Games'; |
108
|
|
|
$content = $this->smarty->fetch('console.tpl'); |
109
|
|
|
|
110
|
|
|
$this->smarty->assign(compact('content', 'meta_title', 'meta_keywords', 'meta_description')); |
111
|
|
|
|
112
|
|
|
$this->pagerender(); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|