diff --git a/src/Controller/IndexController.php b/src/Controller/IndexController.php index 6906f59..1f0e129 100644 --- a/src/Controller/IndexController.php +++ b/src/Controller/IndexController.php @@ -22,6 +22,7 @@ final class IndexController extends AbstractController 'active_downloads' => $this->downloadRepository->getActivePaginated(), 'recent_downloads' => $this->downloadRepository->latest(5), 'popular_movies' => $this->tmdb->popularMovies(1, 6), + 'popular_tvshows' => $this->tmdb->popularTvShows(1, 6), ]); } } diff --git a/src/Tmdb/Tmdb.php b/src/Tmdb/Tmdb.php index cdda7ef..2fc8cdc 100644 --- a/src/Tmdb/Tmdb.php +++ b/src/Tmdb/Tmdb.php @@ -111,6 +111,23 @@ class Tmdb return $movies; } + public function popularTvShows(int $page = 1, ?int $limit = null) + { + $movies = $this->tvRepository->getPopular(['page' => $page]); + + $movies = $movies->map(function ($movie) use ($movies) { + return $this->parseResult($movies[$movie], "movie"); + }); + + $movies = array_values($movies->toArray()); + + if (null !== $limit) { + $movies = array_slice($movies, 0, $limit); + } + + return $movies; + } + public function search(string $term, int $page = 1) { $searchRepository = new SearchRepository($this->client); diff --git a/templates/components/Poster.html.twig b/templates/components/Poster.html.twig index d70a40e..806cd21 100644 --- a/templates/components/Poster.html.twig +++ b/templates/components/Poster.html.twig @@ -1,12 +1,12 @@

{{ title }}

diff --git a/templates/index/index.html.twig b/templates/index/index.html.twig index bf0c2af..91bde79 100644 --- a/templates/index/index.html.twig +++ b/templates/index/index.html.twig @@ -54,7 +54,7 @@ -
+
{% for movie in popular_movies %} + year="{{ movie.year }}" + mediaType="movies" + /> + {% endfor %} + + + {% for movie in popular_tvshows %} + {% endfor %}