Skip to content

Commit

Permalink
Merge pull request #76 from leepeuker/hotfix-persoon-page-movies
Browse files Browse the repository at this point in the history
Fix buggy watched movies on actor page
  • Loading branch information
leepeuker authored Jul 27, 2022
2 parents 97f70e7 + 6ca38da commit 4d68bdd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/Application/Movie/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ public function fetchHistoryOrderedByWatchedAtDesc(int $userId) : array
return $this->historySelectService->fetchHistoryOrderedByWatchedAtDesc($userId);
}

public function fetchWithActor(int $personId, int $userId) : EntityList
public function fetchWithActor(int $personId, int $userId) : array
{
return $this->movieSelectService->fetchWithActor($personId, $userId);
}

public function fetchWithDirector(int $personId, int $userId) : EntityList
public function fetchWithDirector(int $personId, int $userId) : array
{
return $this->movieSelectService->fetchWithDirector($personId, $userId);
}
Expand Down
14 changes: 8 additions & 6 deletions src/Application/Movie/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,31 +424,33 @@ public function fetchWithActor(int $personId, int $userId) : array
{
return $this->dbConnection->fetchAllAssociative(
<<<SQL
SELECT m.*
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 movie_user_watch_dates muwd ON m.id = muwd.movie_id
LEFT JOIN movie_user_rating mur ON muwd.movie_id = mur.movie_id and mur.user_id = ?
WHERE p.id = ? AND m.id IN (SELECT DISTINCT movie_id FROM movie_user_watch_dates mh) AND muwd.user_id = ?
ORDER BY m.title
SQL,
[$personId, $userId]
[$userId, $personId, $userId]
);
}

public function fetchWithDirector(int $personId, int $userId) : array
{
return $this->dbConnection->fetchAllAssociative(
<<<SQL
SELECT m.*
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 movie_user_watch_dates muwd ON m.id = muwd.movie_id
WHERE p.id = ? AND m.id IN (SELECT DISTINCT movie_id FROM movie_user_watch_dates mh) AND muwd.user_id = ?
JOIN movie_user_watch_dates muwd ON m.id = muwd.movie_id and muwd.user_id = ?
LEFT JOIN movie_user_rating mur ON muwd.movie_id = mur.movie_id and mur.user_id = ?
WHERE p.id = ? AND m.id IN (SELECT DISTINCT movie_id FROM movie_user_watch_dates mh)
ORDER BY m.title
SQL,
[$personId, $userId]
[$userId, $userId, $personId]
);
}

Expand Down
8 changes: 4 additions & 4 deletions src/Application/Movie/Service/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ public function fetchAllOrderedByLastUpdatedAtTmdbAsc() : EntityList
return $this->repository->fetchAllOrderedByLastUpdatedAtTmdbAsc();
}

public function fetchWithActor(int $personId, int $userId) : EntityList
public function fetchWithActor(int $personId, int $userId) : array
{
return EntityList::createFromArray($this->repository->fetchWithActor($personId, $userId));
return $this->repository->fetchWithActor($personId, $userId);
}

public function fetchWithDirector(int $personId, int $userId) : EntityList
public function fetchWithDirector(int $personId, int $userId) : array
{
return EntityList::createFromArray($this->repository->fetchWithDirector($personId, $userId));
return $this->repository->fetchWithDirector($personId, $userId);
}

public function findById(int $movieId) : ?Entity
Expand Down
13 changes: 6 additions & 7 deletions templates/page/person.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@
<div class="col position-relative" style="padding-bottom: 1rem;">
<div class="card h-100 position-relative" style="cursor: pointer" onclick="window.location='/{{ routeUsername }}/movie/{{ movieAsActor.id }}'">
<div class="position-relative">
<img src="{{ tmdb.generatePosterImageUrl(movieAsActor.tmdbPosterPath) }}" class="card-img-top" alt="..."
<img src="{{ tmdb.generatePosterImageUrl(movieAsActor.tmdb_poster_path) }}" class="card-img-top" alt="..."
style="border-top-left-radius:0;border-top-right-radius:0;">
</div>

{% if movieAsActor.personalRating is not null %}
{% 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.personalRating }}
{{ movieAsActor.userRating }}
</span>
{% endif %}
</div>
Expand All @@ -79,14 +79,13 @@
<div class="col position-relative">
<div class="card h-100 position-relative" style="cursor: pointer" onclick="window.location='/{{ routeUsername }}/movie/{{ movieAsDirector.id }}'">
<div class="position-relative">
<img src="{{ tmdb.generatePosterImageUrl(movieAsDirector.tmdbPosterPath) }}" class="card-img-top" alt="..."
<img src="{{ tmdb.generatePosterImageUrl(movieAsDirector.tmdb_poster_path) }}" class="card-img-top" alt="..."
style="border-top-left-radius:0;border-top-right-radius:0;">

</div>

{% if movieAsDirector.personalRating is not null %}
{% 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.personalRating }}
{{ movieAsDirector.userRating }}
</span>
{% endif %}
</div>
Expand Down

0 comments on commit 4d68bdd

Please sign in to comment.