Skip to content

Commit

Permalink
Update person and movoe page to always disbale tmdb and imdb links if…
Browse files Browse the repository at this point in the history
… possible
  • Loading branch information
leepeuker committed Oct 1, 2023
1 parent 94725a9 commit 7057ac6
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 19 deletions.
5 changes: 5 additions & 0 deletions src/Api/Imdb/ImdbUrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ public function buildMovieUrl(string $imdbId) : string
{
return "https://www.imdb.com/title/$imdbId";
}

public function generatePersonUrl(string $imdbId) : string
{
return "https://www.imdb.com/name/$imdbId";
}
}
5 changes: 5 additions & 0 deletions src/Api/Tmdb/TmdbUrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ public function generateMovieUrl(int $tmdbId) : Url
{
return Url::createFromString("https://www.themoviedb.org/movie/$tmdbId/");
}

public function generatePersonUrl(int $tmdbId) : Url
{
return Url::createFromString("https://www.themoviedb.org/person/$tmdbId/");
}
}
13 changes: 13 additions & 0 deletions src/HttpController/Web/PersonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Movary\HttpController\Web;

use Movary\Api\Imdb;
use Movary\Api\Tmdb;
use Movary\Domain\Movie\MovieApi;
use Movary\Domain\Person;
use Movary\Domain\User\Service\UserPageAuthorizationChecker;
Expand All @@ -20,6 +22,8 @@ public function __construct(
private readonly Environment $twig,
private readonly UserPageAuthorizationChecker $userPageAuthorizationChecker,
private readonly UrlGenerator $urlGenerator,
private readonly Imdb\ImdbUrlGenerator $imdbUrlGenerator,
private readonly Tmdb\TmdbUrlGenerator $tmdbUrlGenerator,
) {
}

Expand Down Expand Up @@ -50,6 +54,13 @@ public function renderPage(Request $request) : Response
}
}

$imdbId = $person->getImdbId();

$imdbUrl = null;
if ($imdbId !== null) {
$imdbUrl = $this->imdbUrlGenerator->generatePersonUrl($imdbId);
}

return Response::create(
StatusCode::createOk(),
$this->twig->render('page/person.html.twig', [
Expand All @@ -64,6 +75,8 @@ public function renderPage(Request $request) : Response
'birthDate' => $person->getBirthDate(),
'deathDate' => $person->getDeathDate(),
'placeOfBirth' => $person->getPlaceOfBirth(),
'tmdbUrl' => $this->tmdbUrlGenerator->generatePersonUrl($person->getTmdbId()),
'imdbUrl' => $imdbUrl,
],
'moviesAsActor' => $this->movieApi->fetchWithActor($personId, $userId),
'moviesAsDirector' => $this->movieApi->fetchWithDirector($personId, $userId),
Expand Down
30 changes: 15 additions & 15 deletions templates/page/movie.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,26 @@

<div class="carousel" style="display: flex;margin-top: 0.9rem;margin-bottom: 0.9rem">
{% if movie.imdbId is not null %}
<div style="display: flex; align-items: center;cursor:pointer;" onclick="window.open('{{ movie.imdbUrl }}', '_blank')">
<img src="/images/imdb-logo.svg" style="width: 3rem">
<p style="margin-bottom: 0;margin-left: 0.3rem;text-align: center">
{% if movie.imdbRatingAverage is not null %}
<a style="display: flex; align-items: center;cursor:pointer;margin-right: {% if movie.imdbRatingAverage is null %}0.6rem{% else %}0.3rem{% endif %}"
href="{{ movie.imdbUrl }}" target="_blank">
<img src="/images/imdb-logo.svg" style="width: 3rem" alt="imdb logo">
</a>
{% if movie.imdbRatingAverage is not null %}
<p style="margin-bottom: 0;margin-right: 0.5rem;text-align: center">
{# Must be in one line otherwise there is a whitespace between the slash and the vote count which looks ugly #}
<span class="fw-bold">{% if movie.imdbRatingAverage is null %}-{% else %}{{ movie.imdbRatingAverage|number_format(1, '.', ',') }}{% endif %}</span><span
class="fw-lighter">/{{ movie.imdbRatingVoteCount|default('-') }}</span>
{% endif %}
</p>
</div>
{% endif %}
{% endif %}
<div style="display: flex; align-items: center;{% if movie.imdbRatingAverage is not null %}margin-left: 0.6rem;{% elseif movie.imdbId is not null %}margin-left: 0.4rem;{% endif %}cursor:pointer;"
onclick="window.open('{{ movie.tmdbUrl }}', '_blank')">
<img src="/images/tmdb-logo.svg" style="width: 2rem">
<p style=" margin-bottom: 0;margin-left: 0.3rem;text-align: center">
{# Must be in one line otherwise there is a whitespace between the slash and the vote count which looks ugly #}
<span class="fw-bold">{% if movie.tmdbRatingAverage is null %}-{% else %}{{ movie.tmdbRatingAverage|number_format(1, '.', ',') }}{% endif %}</span><span
class="fw-lighter">/{{ movie.tmdbRatingVoteCount|default('-') }}</span>
</p>
</div>
<a style="display: flex; align-items: center;cursor:pointer;margin-right: {% if movie.tmdbRatingAverage is null %}0.6rem{% else %}0.3rem{% endif %};text-align: center" href="{{ movie.tmdbUrl }}" target="_blank">
<img src="/images/tmdb-logo.svg" style="width: 2rem" alt="tmdb logo">
</a>
<p style="margin-bottom: 0;margin-right: .5rem">
{# Must be in one line otherwise there is a whitespace between the slash and the vote count which looks ugly #}
<span class="fw-bold">{% if movie.tmdbRatingAverage is null %}-{% else %}{{ movie.tmdbRatingAverage|number_format(1, '.', ',') }}{% endif %}</span><span
class="fw-lighter">/{{ movie.tmdbRatingVoteCount|default('-') }}</span>
</p>
</div>

{# --- Buttons --- #}
Expand Down
22 changes: 18 additions & 4 deletions templates/page/person.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
<p class="fw-light" style="margin-bottom: 0.4rem">{{ person.knownForDepartment }}</p>

<h6 style="margin-bottom: 0.1rem">Gender</h6>
<p class="fw-light" style="margin-bottom: 0.4rem">{{ person.gender == '0' ? '-' }}{{ person.gender == '1' ? 'Female' }}{{ person.gender == '2' ? 'Male' }}{{ person.gender == '3' ? 'Non-Binary' }}</p>
<p class="fw-light"
style="margin-bottom: 0.4rem">{{ person.gender == '0' ? '-' }}{{ person.gender == '1' ? 'Female' }}{{ person.gender == '2' ? 'Male' }}{{ person.gender == '3' ? 'Non-Binary' }}</p>

{% if person.birthDate is not null %}
<h6 style="margin-bottom: 0.1rem">Birth date</h6>
Expand All @@ -53,6 +54,17 @@
</div>
</div>

<div class="carousel" style="display: flex;margin-top: 0.9rem;margin-bottom: 0.9rem">
{% if person.imdbUrl is not null %}
<a style="display: flex; align-items: center;cursor:pointer;margin-right: 0.6rem" href="{{ person.imdbUrl }}" target="_blank">
<img src="/images/imdb-logo.svg" style="width: 3rem" alt="imdb logo">
</a>
{% endif %}
<a style="display: flex; align-items: center;cursor:pointer;" href="{{ person.tmdbUrl }}" target="_blank">
<img src="/images/tmdb-logo.svg" style="width: 2rem" alt="tmdb logo">
</a>
</div>

<h6 style="margin-bottom: 0.1rem; margin-top: 1rem; font-weight: bold;">Biography</h6>
{% if person.biography is not null %}
<p id="biographyParagraph" style="margin-bottom: 1rem">{{ person.biography|nl2br }}</p>
Expand All @@ -65,7 +77,7 @@
<p>No biography available.</p>
{% endif %}

<ul class="nav nav-tabs" id="myTab" role="tablist" >
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link {% if moviesAsActor is empty %}disabled{% elseif person.knownForDepartment == 'Acting' or moviesAsDirector is empty %}active{% endif %}"
id="home-tab"
Expand All @@ -91,7 +103,8 @@
<div class="row row-cols-3 row-cols-md-3 row-cols-lg-6" style="text-align: center;margin-top: 1rem">
{% for movieAsActor in moviesAsActor %}
<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="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>
Expand All @@ -113,7 +126,8 @@
<div class="row row-cols-3 row-cols-md-3 row-cols-lg-6" style="text-align: center;margin-top: 1rem">
{% for movieAsDirector in moviesAsDirector %}
<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="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">

Expand Down

0 comments on commit 7057ac6

Please sign in to comment.