Issues (864)

app/Http/Controllers/MyMoviesController.php (5 issues)

1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\Category;
6
use App\Models\Settings;
7
use App\Models\UserMovie;
8
use App\Services\Releases\ReleaseBrowseService;
9
use Blacklight\Movie;
10
use Illuminate\Http\Request;
11
12
class MyMoviesController extends BasePageController
13
{
14
    private ReleaseBrowseService $releaseBrowseService;
15
16
    public function __construct(ReleaseBrowseService $releaseBrowseService)
17
    {
18
        parent::__construct();
19
        $this->releaseBrowseService = $releaseBrowseService;
20
    }
21
22
    public function show(Request $request)
23
    {
24
        $mv = new Movie;
25
26
        $action = $request->input('id') ?? '';
27
        $imdbid = $request->input('imdb') ?? '';
28
29
        if ($request->has('from')) {
30
            $this->viewData['from'] = url($request->input('from'));
31
        } else {
32
            $this->viewData['from'] = url('/mymovies');
33
        }
34
35
        switch ($action) {
36
            case 'delete':
37
                $movie = UserMovie::getMovie($this->userdata->id, $imdbid);
38
                if (! $movie) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $movie of type App\Models\UserMovie[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
39
                    return redirect()->to('/mymovies');
40
                }
41
                UserMovie::delMovie($this->userdata->id, $imdbid);
42
                if ($request->has('from')) {
43
                    header('Location:'.url($request->input('from')));
0 ignored issues
show
Are you sure url($request->input('from')) of type Illuminate\Contracts\Routing\UrlGenerator|string can be used in concatenation? ( Ignorable by Annotation )

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

43
                    header('Location:'./** @scrutinizer ignore-type */ url($request->input('from')));
Loading history...
44
                } else {
45
                    return redirect()->to('/mymovies');
46
                }
47
48
                break;
49
            case 'add':
50
            case 'doadd':
51
                $movie = UserMovie::getMovie($this->userdata->id, $imdbid);
52
                if ($movie) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $movie of type App\Models\UserMovie[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
53
                    return redirect()->to('/mymovies');
54
                }
55
56
                $movie = $mv->getMovieInfo($imdbid);
57
                if (! $movie) {
0 ignored issues
show
$movie is of type App\Models\MovieInfo, thus it always evaluated to true.
Loading history...
58
                    return redirect()->to('/mymovies');
59
                }
60
61
                if ($action === 'doadd') {
62
                    $category = ($request->has('category') && \is_array($request->input('category')) && ! empty($request->input('category'))) ? $request->input('category') : [];
63
                    UserMovie::addMovie($this->userdata->id, $imdbid, $category);
64
                    if ($request->has('from')) {
65
                        return redirect()->to($request->input('from'));
66
                    }
67
68
                    return redirect()->to('/mymovies');
69
                }
70
71
                $tmpcats = Category::getChildren(Category::MOVIE_ROOT);
72
                $categories = [];
73
                foreach ($tmpcats as $c) {
74
                    // If MOVIE WEB-DL categorization is disabled, don't include it as an option
75
                    if ((int) $c['id'] === Category::MOVIE_WEBDL && (int) Settings::settingValue('catwebdl') === 0) {
76
                        continue;
77
                    }
78
                    $categories[$c['id']] = $c['title'];
79
                }
80
                $this->viewData['type'] = 'add';
81
                $this->viewData['cat_ids'] = array_keys($categories);
82
                $this->viewData['cat_names'] = $categories;
83
                $this->viewData['cat_selected'] = [];
84
                $this->viewData['imdbid'] = $imdbid;
85
                $this->viewData['movie'] = $movie;
86
                $this->viewData['content'] = view('mymovies.add', $this->viewData)->render();
87
88
                return $this->pagerender();
89
90
            case 'edit':
91
            case 'doedit':
92
                $movie = UserMovie::getMovie($this->userdata->id, $imdbid);
93
94
                if (! $movie) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $movie of type App\Models\UserMovie[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
95
                    return redirect()->to('/mymovies');
96
                }
97
98
                if ($action === 'doedit') {
99
                    $category = ($request->has('category') && \is_array($request->input('category')) && ! empty($request->input('category'))) ? $request->input('category') : [];
100
                    UserMovie::updateMovie($this->userdata->id, $imdbid, $category);
101
                    if ($request->has('from')) {
102
                        return redirect()->to($request->input('from'));
103
                    }
104
105
                    return redirect()->to('mymovies');
106
                }
107
108
                $tmpcats = Category::getChildren(Category::MOVIE_ROOT);
109
                $categories = [];
110
                foreach ($tmpcats as $c) {
111
                    $categories[$c['id']] = $c['title'];
112
                }
113
114
                $this->viewData['type'] = 'edit';
115
                $this->viewData['cat_ids'] = array_keys($categories);
116
                $this->viewData['cat_names'] = $categories;
117
                $this->viewData['cat_selected'] = explode('|', $movie['categories']);
118
                $this->viewData['imdbid'] = $imdbid;
119
                $this->viewData['movie'] = $movie;
120
                $this->viewData['content'] = view('mymovies.add', $this->viewData)->render();
121
122
                return $this->pagerender();
123
124
            case 'browse':
125
126
                $title = 'Browse My Movies';
127
                $meta_title = 'My Movies';
128
                $meta_keywords = 'search,add,to,cart,nzb,description,details';
129
                $meta_description = 'Browse Your Movies';
130
131
                $page = $request->has('page') && is_numeric($request->input('page')) ? $request->input('page') : 1;
132
133
                $offset = ($page - 1) * config('nntmux.items_per_cover_page');
134
135
                $movies = UserMovie::getMovies($this->userdata->id);
136
                $categories = $movie = [];
137
                foreach ($movies as $moviek => $movie) {
138
                    $showcats = explode('|', $movie['categories']);
139
                    if (\is_array($showcats) && \count($showcats) > 0) {
140
                        $catarr = [];
141
                        foreach ($showcats as $scat) {
142
                            if (! empty($scat)) {
143
                                $catarr[] = $categories[$scat];
144
                            }
145
                        }
146
                        $movie['categoryNames'] = implode(', ', $catarr);
147
                    } else {
148
                        $movie['categoryNames'] = '';
149
                    }
150
                }
151
152
                $ordering = $this->releaseBrowseService->getBrowseOrdering();
153
154
                $page = $request->has('page') && is_numeric($request->input('page')) ? $request->input('page') : 1;
155
156
                $results = $mv->getMovieRange($page, $movie['categoryNames'], $offset, config('nntmux.items_per_cover_page'), $ordering, -1, $this->userdata->categoryexclusions);
157
158
                $this->viewData['covgroup'] = '';
159
160
                foreach ($ordering as $ordertype) {
161
                    $this->viewData['orderby'.$ordertype] = url('/mymovies/browse?ob='.$ordertype.'&amp;offset=0');
162
                }
163
164
                $this->viewData['lastvisit'] = $this->userdata->lastlogin;
165
                $this->viewData['results'] = $results;
166
                $this->viewData['movies'] = true;
167
                $this->viewData['content'] = view('browse', $this->viewData)->render();
168
                $this->viewData = array_merge($this->viewData, compact('title', 'meta_title', 'meta_keywords', 'meta_description'));
169
170
                return $this->pagerender();
171
172
            default:
173
174
                $title = 'My Movies';
175
                $meta_title = 'My Movies';
176
                $meta_keywords = 'search,add,to,cart,nzb,description,details';
177
                $meta_description = 'Manage Your Movies';
178
179
                $tmpcats = Category::getChildren(Category::MOVIE_ROOT);
180
                $categories = [];
181
                foreach ($tmpcats as $c) {
182
                    $categories[$c['id']] = $c['title'];
183
                }
184
185
                $movies = UserMovie::getMovies($this->userdata->id);
186
                $results = [];
187
                foreach ($movies as $moviek => $movie) {
188
                    $showcats = explode('|', $movie['categories']);
189
                    if (\is_array($showcats) && \count($showcats) > 0) {
190
                        $catarr = [];
191
                        foreach ($showcats as $scat) {
192
                            if (! empty($scat)) {
193
                                $catarr[] = $categories[$scat];
194
                            }
195
                        }
196
                        $movie['categoryNames'] = implode(', ', $catarr);
197
                    } else {
198
                        $movie['categoryNames'] = '';
199
                    }
200
201
                    $results[$moviek] = $movie;
202
                }
203
                $this->viewData['movies'] = $results;
204
                $this->viewData['content'] = view('mymovies.index', $this->viewData)->render();
205
                $this->viewData = array_merge($this->viewData, compact('title', 'meta_title', 'meta_keywords', 'meta_description'));
206
207
                return $this->pagerender();
208
        }
209
210
        // Fallback return in case no case matches
211
        return redirect()->to('/mymovies');
212
    }
213
}
214