Passed
Push — dev ( 9d591d...c59ba0 )
by Darko
22:01
created

BrowseController::index()   B

Complexity

Conditions 7
Paths 64

Size

Total Lines 42
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
c 1
b 0
f 0
dl 0
loc 42
rs 8.5866
cc 7
nc 64
nop 0
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\Category;
6
use App\Models\RootCategory;
7
use Blacklight\Releases;
8
use Illuminate\Http\Request;
9
10
class BrowseController extends BasePageController
11
{
12
    /**
13
     * @throws \Exception
14
     */
15
    public function index()
16
    {
17
        $this->setPrefs();
18
        $releases = new Releases();
19
20
        $this->smarty->assign('category', -1);
0 ignored issues
show
Bug introduced by
The method assign() does not exist on Illuminate\Foundation\Application. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

20
        $this->smarty->/** @scrutinizer ignore-call */ 
21
                       assign('category', -1);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
21
22
        $ordering = $releases->getBrowseOrdering();
23
        $orderBy = request()->has('ob') && ! empty(request()->input('ob')) ? request()->input('ob') : '';
24
        $page = request()->has('page') && is_numeric(request()->input('page')) ? request()->input('page') : 1;
25
        $offset = ($page - 1) * config('nntmux.items_per_page');
26
27
        $rslt = $releases->getBrowseRange($page, [-1], $offset, config('nntmux.items_per_page'), $orderBy, -1, $this->userdata->categoryexclusions, -1);
0 ignored issues
show
Bug introduced by
The property categoryexclusions does not seem to exist on App\Models\User. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
28
        $results = $this->paginate($rslt ?? [], $rslt[0]->_totalcount ?? 0, config('nntmux.items_per_page'), $page, request()->url(), request()->query());
29
30
        $this->smarty->assign('catname', 'All');
31
32
        $this->smarty->assign('lastvisit', $this->userdata->lastlogin);
33
34
        $browse = [];
35
        foreach ($results as $result) {
36
            $browse[] = $result;
37
        }
38
39
        $this->smarty->assign(
40
            [
41
                'results' => $results,
42
                'resultsadd' => $browse,
43
            ]
44
        );
45
46
        foreach ($ordering as $orderType) {
47
            $this->smarty->assign('orderby'.$orderType, url('browse/All?ob='.$orderType));
48
        }
49
50
        $meta_title = 'Browse All Releases';
51
        $meta_keywords = 'browse,nzb,description,details';
52
        $meta_description = 'Browse for Nzbs';
53
54
        $content = $this->smarty->fetch('browse.tpl');
0 ignored issues
show
Bug introduced by
The method fetch() does not exist on Illuminate\Foundation\Application. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

54
        /** @scrutinizer ignore-call */ 
55
        $content = $this->smarty->fetch('browse.tpl');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
55
        $this->smarty->assign(compact('content', 'meta_title', 'meta_keywords', 'meta_description'));
56
        $this->pagerender();
57
    }
58
59
    /**
60
     * @param string $parentCategory
61
     * @param string $id
62
     * @throws \Exception
63
     */
64
    public function show(string $parentCategory, string $id = 'All')
65
    {
66
        $this->setPrefs();
67
        $releases = new Releases();
68
69
        $parentId = RootCategory::query()->where('title', $parentCategory)->value('id');
70
71
        $query = Category::query()->where('title', $id)->where('root_categories_id', $parentId);
72
        if ($id !== 'All') {
73
            $cat = $query->first();
74
            $category = $cat !== null ? $cat->id : -1;
75
        } else {
76
            $category = $parentId ?? -1;
77
        }
78
79
        $grp = -1;
80
81
        $catarray = [];
82
        $catarray[] = $category;
83
84
        $this->smarty->assign('parentcat', ucfirst($parentCategory));
85
        $this->smarty->assign('category', $category);
86
87
        $ordering = $releases->getBrowseOrdering();
88
        $orderBy = request()->has('ob') && ! empty(request()->input('ob')) ? request()->input('ob') : '';
89
        $page = request()->has('page') && is_numeric(request()->input('page')) ? request()->input('page') : 1;
90
        $offset = ($page - 1) * config('nntmux.items_per_page');
91
92
        $rslt = $releases->getBrowseRange($page, $catarray, $offset, config('nntmux.items_per_page'), $orderBy, -1, $this->userdata->categoryexclusions, $grp);
0 ignored issues
show
Bug introduced by
The property categoryexclusions does not seem to exist on App\Models\User. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
93
        $results = $this->paginate($rslt ?? [], $rslt[0]->_totalcount ?? 0, config('nntmux.items_per_page'), $page, request()->url(), request()->query());
94
95
        $browse = [];
96
97
        foreach ($results as $result) {
98
            $browse[] = $result;
99
        }
100
101
        $this->smarty->assign('catname', $id);
102
103
        $this->smarty->assign('lastvisit', $this->userdata->lastlogin);
104
105
        $this->smarty->assign(
106
            [
107
                'results' => $results,
108
                'resultsadd' => $browse,
109
            ]
110
        );
111
112
        $covgroup = '';
113
        if ($category === -1 && $grp === -1) {
114
            $this->smarty->assign('catname', 'All');
115
        } elseif ($category !== -1 && $grp === -1) {
116
            $cdata = Category::find($category);
117
            if ($cdata !== null) {
118
                if ($cdata->root_categories_id === Category::GAME_ROOT) {
119
                    $covgroup = 'console';
120
                } elseif ($cdata->root_categories_id === Category::MOVIE_ROOT) {
121
                    $covgroup = 'movies';
122
                } elseif ($cdata->root_categories_id === Category::XXX_ROOT) {
123
                    $covgroup = 'xxx';
124
                } elseif ($cdata->root_categories_id === Category::PC_ROOT) {
125
                    $covgroup = 'games';
126
                } elseif ($cdata->root_categories_id === Category::MUSIC_ROOT) {
127
                    $covgroup = 'music';
128
                } elseif ($cdata->root_categories_id === Category::BOOKS_ROOT) {
129
                    $covgroup = 'books';
130
                }
131
            }
132
        } elseif ($grp !== -1) {
133
            $this->smarty->assign('catname', $grp);
134
        }
135
136
        if ($id === 'All' && $parentCategory === 'All') {
137
            $meta_title = 'Browse '.$parentCategory.' releases';
138
            foreach ($ordering as $orderType) {
139
                $this->smarty->assign('orderby'.$orderType, url('browse/'.$parentCategory.'?ob='.$orderType));
140
            }
141
        } else {
142
            $meta_title = 'Browse '.$parentCategory.' / '.$id.' releases';
143
            foreach ($ordering as $orderType) {
144
                $this->smarty->assign('orderby'.$orderType, url('browse/'.$parentCategory.'/'.$id.'?ob='.$orderType));
145
            }
146
        }
147
        $meta_keywords = 'browse,nzb,description,details';
148
        $meta_description = 'Browse for Nzbs';
149
150
        $content = $this->smarty->fetch('browse.tpl');
151
        $this->smarty->assign(compact('content', 'covgroup', 'meta_title', 'meta_keywords', 'meta_description'));
152
        $this->pagerender();
153
    }
154
155
    /**
156
     * @param \Illuminate\Http\Request $request
157
     * @throws \Exception
158
     */
159
    public function group(Request $request)
160
    {
161
        $this->setPrefs();
162
        $releases = new Releases();
163
        if ($request->has('g')) {
164
            $group = $request->input('g');
165
            $page = request()->has('page') && is_numeric(request()->input('page')) ? request()->input('page') : 1;
166
            $offset = ($page - 1) * config('nntmux.items_per_page');
167
            $rslt = $releases->getBrowseRange($page, [-1], $offset, config('nntmux.items_per_page'), '', -1, $this->userdata->categoryexclusions, $group);
0 ignored issues
show
Bug introduced by
The property categoryexclusions does not seem to exist on App\Models\User. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
168
            $results = $this->paginate($rslt ?? [], $rslt[0]->_totalcount ?? 0, config('nntmux.items_per_page'), $page, request()->url(), request()->query());
169
170
            $browse = [];
171
172
            foreach ($results as $result) {
173
                $browse[] = $result;
174
            }
175
176
            $this->smarty->assign(
177
                [
178
                    'results' => $results,
179
                    'resultsadd' => $browse,
180
                    'parentcat' => $group,
181
                    'catname' => 'all',
182
                ]
183
            );
184
            $meta_title = 'Browse Groups';
185
            $meta_keywords = 'browse,nzb,description,details';
186
            $meta_description = 'Browse Groups';
187
            $content = $this->smarty->fetch('browse.tpl');
188
189
            $this->smarty->assign(compact('content', 'meta_title', 'meta_keywords', 'meta_description'));
190
191
            $this->pagerender();
192
        }
193
    }
194
195
    /**
196
     * @param \Illuminate\Http\Request $request
197
     * @throws \Exception
198
     */
199
    public function tags(Request $request)
200
    {
201
        $this->setPrefs();
202
        $releases = new Releases();
203
        if ($request->has('tags')) {
204
            $tags = explode(',', $request->input('tags'));
205
            $page = request()->has('page') && is_numeric(request()->input('page')) ? request()->input('page') : 1;
206
            $offset = ($page - 1) * config('nntmux.items_per_page');
207
            $rslt = $releases->getBrowseRange($page, [-1], $offset, config('nntmux.items_per_page'), '', -1, $this->userdata->categoryexclusions, -1, 0, $tags);
0 ignored issues
show
Bug introduced by
The property categoryexclusions does not seem to exist on App\Models\User. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
208
            $results = $this->paginate($rslt ?? [], $rslt[0]->_totalcount ?? 0, config('nntmux.items_per_page'), $page, request()->url(), request()->query());
209
210
            $browse = [];
211
212
            foreach ($results as $result) {
213
                $browse[] = $result;
214
            }
215
216
            $this->smarty->assign(
217
                [
218
                    'results' => $results,
219
                    'resultsadd' => $browse,
220
                    'catname' => 'all',
221
                ]
222
            );
223
            $meta_title = 'Browse Groups';
224
            $meta_keywords = 'browse,nzb,description,details';
225
            $meta_description = 'Browse Groups';
226
            $content = $this->smarty->fetch('browse.tpl');
227
228
            $this->smarty->assign(compact('content', 'meta_title', 'meta_keywords', 'meta_description'));
229
230
            $this->pagerender();
231
        }
232
    }
233
}
234