From 887e3ee073e52872a3ad71b013ba70d8abdb0b1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Eahin=20Akkaya?= Date: Sat, 11 Nov 2023 13:43:59 +0300 Subject: [PATCH 1/6] Show movies from watch list in person detail page --- src/Domain/Movie/MovieApi.php | 8 ++++++++ src/Domain/Movie/MovieRepository.php | 17 +++++++++++++++++ src/HttpController/Web/PersonController.php | 1 + templates/page/person.html.twig | 21 +++++++++++++++++++++ 4 files changed, 47 insertions(+) diff --git a/src/Domain/Movie/MovieApi.php b/src/Domain/Movie/MovieApi.php index d4f5038ba..33f7f65ee 100644 --- a/src/Domain/Movie/MovieApi.php +++ b/src/Domain/Movie/MovieApi.php @@ -301,6 +301,14 @@ public function fetchWithDirector(int $personId, int $userId) : array return $this->urlGenerator->replacePosterPathWithImageSrcUrl($movies); } + + public function fetchFromWatchlistWithActor(int $personId, int $userId) : array + { + $movies = $this->repository->fetchFromWatchlistWithActor($personId, $userId); + + return $this->urlGenerator->replacePosterPathWithImageSrcUrl($movies); + } + public function findById(int $movieId) : ?MovieEntity { return $this->repository->findById($movieId); diff --git a/src/Domain/Movie/MovieRepository.php b/src/Domain/Movie/MovieRepository.php index 8bca1510d..c4b98797f 100644 --- a/src/Domain/Movie/MovieRepository.php +++ b/src/Domain/Movie/MovieRepository.php @@ -898,6 +898,23 @@ public function fetchWithDirector(int $personId, int $userId) : array ); } + + public function fetchFromWatchlistWithActor(int $personId, int $userId) : array + { + return $this->dbConnection->fetchAllAssociative( + <<dbConnection->fetchAssociative('SELECT * FROM `movie` WHERE id = ?', [$movieId]); diff --git a/src/HttpController/Web/PersonController.php b/src/HttpController/Web/PersonController.php index be034d15a..50af755d5 100644 --- a/src/HttpController/Web/PersonController.php +++ b/src/HttpController/Web/PersonController.php @@ -123,6 +123,7 @@ public function renderPage(Request $request) : Response 'isHiddenInTopLists' => $isHiddenInTopLists, ], 'moviesAsActor' => $this->movieApi->fetchWithActor($personId, $userId), + 'moviesAsActorFromWatchlist' => $this->movieApi->fetchFromWatchlistWithActor($personId, $userId), 'moviesAsDirector' => $this->movieApi->fetchWithDirector($personId, $userId), ]), ); diff --git a/templates/page/person.html.twig b/templates/page/person.html.twig index 27ab7fb2f..8982e0956 100644 --- a/templates/page/person.html.twig +++ b/templates/page/person.html.twig @@ -137,6 +137,27 @@ {% endfor %} {% endif %} + {% if moviesAsActorFromWatchlist is not empty %} +

From your watchlist

+
+ {% for movieAsActor in moviesAsActorFromWatchlist %} +
+
+
+ {{ movieAsActor.title }} Poster +
+ + {% if movieAsActor.userRating is not null %} + + {{ movieAsActor.userRating }} + + {% endif %} +
+
+ {% endfor %} +
+ {% endif %}
Date: Sat, 11 Nov 2023 15:56:48 +0300 Subject: [PATCH 2/6] Fix naming --- src/HttpController/Web/PersonController.php | 2 +- templates/page/person.html.twig | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/HttpController/Web/PersonController.php b/src/HttpController/Web/PersonController.php index 50af755d5..a3d41f572 100644 --- a/src/HttpController/Web/PersonController.php +++ b/src/HttpController/Web/PersonController.php @@ -123,7 +123,7 @@ public function renderPage(Request $request) : Response 'isHiddenInTopLists' => $isHiddenInTopLists, ], 'moviesAsActor' => $this->movieApi->fetchWithActor($personId, $userId), - 'moviesAsActorFromWatchlist' => $this->movieApi->fetchFromWatchlistWithActor($personId, $userId), + 'moviesFromWatchlistAsActor' => $this->movieApi->fetchFromWatchlistWithActor($personId, $userId), 'moviesAsDirector' => $this->movieApi->fetchWithDirector($personId, $userId), ]), ); diff --git a/templates/page/person.html.twig b/templates/page/person.html.twig index 8982e0956..5284d9c32 100644 --- a/templates/page/person.html.twig +++ b/templates/page/person.html.twig @@ -137,10 +137,10 @@ {% endfor %}
{% endif %} - {% if moviesAsActorFromWatchlist is not empty %} -

From your watchlist

+ {% if moviesFromWatchlistAsActor is not empty %} +

From your watch list

- {% for movieAsActor in moviesAsActorFromWatchlist %} + {% for movieAsActor in moviesFromWatchlistAsActor %}
From 5a10e2317f9e1a07ae86d3d5db73c6336b81633c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Eahin=20Akkaya?= Date: Sat, 11 Nov 2023 15:57:49 +0300 Subject: [PATCH 3/6] Show movies from watch list in director tab --- src/Domain/Movie/MovieApi.php | 8 +++++++ src/Domain/Movie/MovieRepository.php | 23 +++++++++++++++++++-- src/HttpController/Web/PersonController.php | 1 + templates/page/person.html.twig | 22 ++++++++++++++++++++ 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/Domain/Movie/MovieApi.php b/src/Domain/Movie/MovieApi.php index 33f7f65ee..74dd2ce5c 100644 --- a/src/Domain/Movie/MovieApi.php +++ b/src/Domain/Movie/MovieApi.php @@ -309,6 +309,14 @@ public function fetchFromWatchlistWithActor(int $personId, int $userId) : array return $this->urlGenerator->replacePosterPathWithImageSrcUrl($movies); } + + public function fetchFromWatchlistWithDirector(int $personId, int $userId) : array + { + $movies = $this->repository->fetchFromWatchlistWithDirector($personId, $userId); + + return $this->urlGenerator->replacePosterPathWithImageSrcUrl($movies); + } + public function findById(int $movieId) : ?MovieEntity { return $this->repository->findById($movieId); diff --git a/src/Domain/Movie/MovieRepository.php b/src/Domain/Movie/MovieRepository.php index c4b98797f..ac87d5e2f 100644 --- a/src/Domain/Movie/MovieRepository.php +++ b/src/Domain/Movie/MovieRepository.php @@ -903,15 +903,34 @@ public function fetchFromWatchlistWithActor(int $personId, int $userId) : array { return $this->dbConnection->fetchAllAssociative( <<dbConnection->fetchAllAssociative( + << $this->movieApi->fetchWithActor($personId, $userId), 'moviesFromWatchlistAsActor' => $this->movieApi->fetchFromWatchlistWithActor($personId, $userId), 'moviesAsDirector' => $this->movieApi->fetchWithDirector($personId, $userId), + 'moviesFromWatchlistAsDirector' => $this->movieApi->fetchFromWatchlistWithDirector($personId, $userId), ]), ); } diff --git a/templates/page/person.html.twig b/templates/page/person.html.twig index 5284d9c32..6757c2f47 100644 --- a/templates/page/person.html.twig +++ b/templates/page/person.html.twig @@ -180,6 +180,28 @@
{% endfor %}
+ + {% if moviesFromWatchlistAsDirector is not empty %} +

From your watch list

+
+ {% for movieAsDirector in moviesFromWatchlistAsDirector %} +
+
+
+ {{ movieAsDirector.title }} Poster + +
+ {% if movieAsDirector.userRating is not null %} + + {{ movieAsDirector.userRating }} + + {% endif %} +
+
+ {% endfor %} +
+ {% endif %}

From f353e0085ecb655542bcf009eb76cd95b58f753a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Eahin=20Akkaya?= Date: Sun, 12 Nov 2023 14:24:45 +0300 Subject: [PATCH 4/6] Apply suggestions from code review Co-authored-by: Lee Peuker --- src/Domain/Movie/MovieRepository.php | 5 ++--- templates/page/person.html.twig | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Domain/Movie/MovieRepository.php b/src/Domain/Movie/MovieRepository.php index ac87d5e2f..9e8ec7afb 100644 --- a/src/Domain/Movie/MovieRepository.php +++ b/src/Domain/Movie/MovieRepository.php @@ -909,14 +909,13 @@ public function fetchFromWatchlistWithActor(int $personId, int $userId) : array JOIN person p ON mc.person_id = p.id JOIN watchlist wl ON m.id = wl.movie_id LEFT JOIN movie_user_rating mur ON wl.movie_id = mur.movie_id and mur.user_id = ? - WHERE p.id = ? AND m.id IN (SELECT DISTINCT movie_id FROM watchlist) AND wl.user_id = ? + WHERE p.id = ? AND m.id IN (wl.movies_id) AND wl.user_id = ? ORDER BY LOWER(m.title) SQL, [$userId, $personId, $userId], ); } - public function fetchFromWatchlistWithDirector(int $personId, int $userId) : array { return $this->dbConnection->fetchAllAssociative( @@ -927,7 +926,7 @@ public function fetchFromWatchlistWithDirector(int $personId, int $userId) : arr JOIN person p ON mc.person_id = p.id JOIN watchlist wl ON m.id = wl.movie_id and wl.user_id = ? LEFT JOIN movie_user_rating mur ON wl.movie_id = mur.movie_id and mur.user_id = ? - WHERE p.id = ? AND m.id IN (SELECT DISTINCT movie_id FROM watchlist) + WHERE p.id = ? AND m.id IN (wl.movies_id) ORDER BY LOWER(m.title) SQL, [$userId, $userId, $personId], diff --git a/templates/page/person.html.twig b/templates/page/person.html.twig index 6757c2f47..94d472c48 100644 --- a/templates/page/person.html.twig +++ b/templates/page/person.html.twig @@ -138,7 +138,7 @@ {% endif %} {% if moviesFromWatchlistAsActor is not empty %} -

From your watch list

+
From your watch list
{% for movieAsActor in moviesFromWatchlistAsActor %}
@@ -182,7 +182,7 @@
{% if moviesFromWatchlistAsDirector is not empty %} -

From your watch list

+
From your watch list
{% for movieAsDirector in moviesFromWatchlistAsDirector %}
From 95757b83640a7711587670c34b7e67186a4f629c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Eahin=20Akkaya?= Date: Sun, 12 Nov 2023 14:38:32 +0300 Subject: [PATCH 5/6] Revert f353e00 partially Apparently, sub-query is required in sql statement. See https://github.com/leepeuker/movary/pull/545#discussion_r1390389897 --- src/Domain/Movie/MovieRepository.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Domain/Movie/MovieRepository.php b/src/Domain/Movie/MovieRepository.php index 9e8ec7afb..ac87d5e2f 100644 --- a/src/Domain/Movie/MovieRepository.php +++ b/src/Domain/Movie/MovieRepository.php @@ -909,13 +909,14 @@ public function fetchFromWatchlistWithActor(int $personId, int $userId) : array JOIN person p ON mc.person_id = p.id JOIN watchlist wl ON m.id = wl.movie_id LEFT JOIN movie_user_rating mur ON wl.movie_id = mur.movie_id and mur.user_id = ? - WHERE p.id = ? AND m.id IN (wl.movies_id) AND wl.user_id = ? + WHERE p.id = ? AND m.id IN (SELECT DISTINCT movie_id FROM watchlist) AND wl.user_id = ? ORDER BY LOWER(m.title) SQL, [$userId, $personId, $userId], ); } + public function fetchFromWatchlistWithDirector(int $personId, int $userId) : array { return $this->dbConnection->fetchAllAssociative( @@ -926,7 +927,7 @@ public function fetchFromWatchlistWithDirector(int $personId, int $userId) : arr JOIN person p ON mc.person_id = p.id JOIN watchlist wl ON m.id = wl.movie_id and wl.user_id = ? LEFT JOIN movie_user_rating mur ON wl.movie_id = mur.movie_id and mur.user_id = ? - WHERE p.id = ? AND m.id IN (wl.movies_id) + WHERE p.id = ? AND m.id IN (SELECT DISTINCT movie_id FROM watchlist) ORDER BY LOWER(m.title) SQL, [$userId, $userId, $personId], From 2e8c2d99473ef86aec6adc9cf3f55bb4b85dcd41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Eahin=20Akkaya?= Date: Sun, 12 Nov 2023 15:00:24 +0300 Subject: [PATCH 6/6] Apply suggestions from code review Co-authored-by: Lee Peuker --- src/Domain/Movie/MovieRepository.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Domain/Movie/MovieRepository.php b/src/Domain/Movie/MovieRepository.php index ac87d5e2f..880a98633 100644 --- a/src/Domain/Movie/MovieRepository.php +++ b/src/Domain/Movie/MovieRepository.php @@ -909,7 +909,7 @@ public function fetchFromWatchlistWithActor(int $personId, int $userId) : array JOIN person p ON mc.person_id = p.id JOIN watchlist wl ON m.id = wl.movie_id LEFT JOIN movie_user_rating mur ON wl.movie_id = mur.movie_id and mur.user_id = ? - WHERE p.id = ? AND m.id IN (SELECT DISTINCT movie_id FROM watchlist) AND wl.user_id = ? + WHERE p.id = ? AND m.id IN (wl.movie_id) AND wl.user_id = ? ORDER BY LOWER(m.title) SQL, [$userId, $personId, $userId], @@ -927,7 +927,7 @@ public function fetchFromWatchlistWithDirector(int $personId, int $userId) : arr JOIN person p ON mc.person_id = p.id JOIN watchlist wl ON m.id = wl.movie_id and wl.user_id = ? LEFT JOIN movie_user_rating mur ON wl.movie_id = mur.movie_id and mur.user_id = ? - WHERE p.id = ? AND m.id IN (SELECT DISTINCT movie_id FROM watchlist) + WHERE p.id = ? AND m.id IN (wl.movie_id) ORDER BY LOWER(m.title) SQL, [$userId, $userId, $personId],