angelov /
donut
| 1 | <?php |
||||
| 2 | |||||
| 3 | /** |
||||
| 4 | * Donut Social Network - Yet another experimental social network. |
||||
| 5 | * Copyright (C) 2016-2018, Dejan Angelov <[email protected]> |
||||
| 6 | * |
||||
| 7 | * This file is part of Donut Social Network. |
||||
| 8 | * |
||||
| 9 | * Donut Social Network is free software: you can redistribute it and/or modify |
||||
| 10 | * it under the terms of the GNU General Public License as published by |
||||
| 11 | * the Free Software Foundation, either version 3 of the License, or |
||||
| 12 | * (at your option) any later version. |
||||
| 13 | * |
||||
| 14 | * Donut Social Network is distributed in the hope that it will be useful, |
||||
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
| 17 | * GNU General Public License for more details. |
||||
| 18 | * |
||||
| 19 | * You should have received a copy of the GNU General Public License |
||||
| 20 | * along with Donut Social Network. If not, see <http://www.gnu.org/licenses/>. |
||||
| 21 | * |
||||
| 22 | * @package Donut Social Network |
||||
| 23 | * @copyright Copyright (C) 2016-2018, Dejan Angelov <[email protected]> |
||||
| 24 | * @license https://github.com/angelov/donut/blob/master/LICENSE |
||||
| 25 | * @author Dejan Angelov <[email protected]> |
||||
| 26 | */ |
||||
| 27 | |||||
| 28 | namespace AppBundle\Controller; |
||||
| 29 | |||||
| 30 | use Angelov\Donut\Core\ResultLists\Sorting\OrderDirection; |
||||
| 31 | use Angelov\Donut\Movies\MoviesList\MoviesListInterface; |
||||
| 32 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
||||
| 33 | use Angelov\Donut\Core\ResultLists\Sorting\OrderField; |
||||
| 34 | use Angelov\Donut\Movies\Genre; |
||||
| 35 | use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
||||
| 36 | use Symfony\Component\HttpFoundation\Request; |
||||
| 37 | use Symfony\Component\HttpFoundation\Response; |
||||
| 38 | |||||
| 39 | class MoviesController extends AbstractController |
||||
| 40 | { |
||||
| 41 | /** |
||||
| 42 | * @Route("/movies", name="app.movies.index") |
||||
| 43 | */ |
||||
| 44 | public function indexAction(Request $request, MoviesListInterface $moviesList) : Response |
||||
| 45 | { |
||||
| 46 | $selectedGenres = []; |
||||
| 47 | foreach ($request->query->all() as $item => $value) { |
||||
| 48 | $p = explode('genre_', $item); |
||||
| 49 | if (count($p) > 1) { |
||||
| 50 | $selectedGenres[] = $p[1]; |
||||
| 51 | } |
||||
| 52 | } |
||||
| 53 | $genresFilter = $this->getDoctrine()->getManager()->getRepository(Genre::class)->findBy(['id' => $selectedGenres]); |
||||
| 54 | |||||
| 55 | $selectedPeriod = $request->get('period', '1000-3000'); |
||||
| 56 | $periodFilter = explode('-', $selectedPeriod); |
||||
| 57 | |||||
| 58 | $page = $request->query->get('page', 1); |
||||
| 59 | $perPage = 12; |
||||
| 60 | $offset = ($page-1)*$perPage; |
||||
| 61 | |||||
| 62 | $moviesList->filterByGenres($genresFilter); |
||||
| 63 | $moviesList->filterByPeriod($periodFilter[0], $periodFilter[1]); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
$periodFilter[0] of type string is incompatible with the type integer expected by parameter $begin of Angelov\Donut\Movies\Mov...rface::filterByPeriod().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 64 | $moviesList->setItemsPerPage($perPage); |
||||
| 65 | $moviesList->orderBy([ |
||||
| 66 | new OrderField('movie.year', OrderDirection::DESC), |
||||
| 67 | new OrderField('movie.title', OrderDirection::ASC) |
||||
| 68 | ]); |
||||
| 69 | $moviesList->setOffset($offset); |
||||
| 70 | |||||
| 71 | $genres = $this->getDoctrine()->getManager()->getRepository(Genre::class)->findAll(); |
||||
| 72 | |||||
| 73 | return $this->render('movies/index.html.twig', [ |
||||
| 74 | 'movies_list' => $moviesList, |
||||
| 75 | 'genres' => $genres, |
||||
| 76 | 'selected_genres' => $selectedGenres, |
||||
| 77 | 'selected_period' => $selectedPeriod |
||||
| 78 | ]); |
||||
| 79 | } |
||||
| 80 | } |
||||
| 81 |