Skip to content

Commit

Permalink
Merge pull request #545 from sahinakkaya/main
Browse files Browse the repository at this point in the history
Show movies from watch list in person detail page
  • Loading branch information
leepeuker authored Nov 12, 2023
2 parents d2b165c + 2e8c2d9 commit 35de7b9
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Domain/Movie/MovieApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,22 @@ 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 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);
Expand Down
36 changes: 36 additions & 0 deletions src/Domain/Movie/MovieRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,42 @@ public function fetchWithDirector(int $personId, int $userId) : array
);
}


public function fetchFromWatchlistWithActor(int $personId, int $userId) : array
{
return $this->dbConnection->fetchAllAssociative(
<<<SQL
SELECT DISTINCT m.*, mur.rating as userRating
FROM movie m
JOIN movie_cast mc ON m.id = mc.movie_id
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.movie_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(
<<<SQL
SELECT DISTINCT m.*, mur.rating as userRating
FROM movie m
JOIN movie_crew mc ON m.id = mc.movie_id AND job = "Director"
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.movie_id)
ORDER BY LOWER(m.title)
SQL,
[$userId, $userId, $personId],
);
}

public function findById(int $movieId) : ?MovieEntity
{
$data = $this->dbConnection->fetchAssociative('SELECT * FROM `movie` WHERE id = ?', [$movieId]);
Expand Down
2 changes: 2 additions & 0 deletions src/HttpController/Web/PersonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ public function renderPage(Request $request) : Response
'isHiddenInTopLists' => $isHiddenInTopLists,
],
'moviesAsActor' => $this->movieApi->fetchWithActor($personId, $userId),
'moviesFromWatchlistAsActor' => $this->movieApi->fetchFromWatchlistWithActor($personId, $userId),
'moviesAsDirector' => $this->movieApi->fetchWithDirector($personId, $userId),
'moviesFromWatchlistAsDirector' => $this->movieApi->fetchFromWatchlistWithDirector($personId, $userId),
]),
);
}
Expand Down
43 changes: 43 additions & 0 deletions templates/page/person.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,27 @@
{% endfor %}
</div>
{% endif %}
{% if moviesFromWatchlistAsActor is not empty %}
<h6>From your watch list</h6>
<div class="row row-cols-3 row-cols-md-3 row-cols-lg-6" style="text-align: center;margin-top: 1rem">
{% for movieAsActor in moviesFromWatchlistAsActor %}
<div class="col position-relative" style="padding-bottom: 1rem;">
<div class="card h-100 position-relative" style="cursor: pointer"
onclick="window.location='/users/{{ routeUsername }}/movies/{{ movieAsActor.id }}'">
<div class="position-relative">
<img src="{{ movieAsActor.poster_path }}" class="card-img-top card-img-bottom" alt="{{ movieAsActor.title }} Poster">
</div>

{% if movieAsActor.userRating is not null %}
<span class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-warning text-dark" style="font-size: 0.8rem">
{{ movieAsActor.userRating }}
</span>
{% endif %}
</div>
</div>
{% endfor %}
</div>
{% endif %}
</div>
<div class="tab-pane fade show {% if person.knownForDepartment == 'Directing' or (moviesAsActor is empty and moviesAsDirector is not empty) %}active{% endif %}"
id="director" role="tabpanel" aria-labelledby="profile-tab"
Expand All @@ -159,6 +180,28 @@
</div>
{% endfor %}
</div>

{% if moviesFromWatchlistAsDirector is not empty %}
<h6>From your watch list</h6>
<div class="row row-cols-3 row-cols-md-3 row-cols-lg-6" style="text-align: center;margin-top: 1rem">
{% for movieAsDirector in moviesFromWatchlistAsDirector %}
<div class="col position-relative" style="padding-bottom: 1rem">
<div class="card h-100 position-relative" style="cursor: pointer"
onclick="window.location='/users/{{ routeUsername }}/movies/{{ movieAsDirector.id }}'">
<div class="position-relative">
<img src="{{ movieAsDirector.poster_path }}" class="card-img-top card-img-bottom" alt="{{ movieAsDirector.title }} Poster">

</div>
{% if movieAsDirector.userRating is not null %}
<span class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-warning text-dark" style="font-size: 0.8rem">
{{ movieAsDirector.userRating }}
</span>
{% endif %}
</div>
</div>
{% endfor %}
</div>
{% endif %}
</div>
</div>
<br>
Expand Down

0 comments on commit 35de7b9

Please sign in to comment.