diff --git a/db/migrations/mysql/20231001110211_AddImdbIdToPersonTable.php b/db/migrations/mysql/20231001110211_AddImdbIdToPersonTable.php new file mode 100644 index 00000000..68825bdb --- /dev/null +++ b/db/migrations/mysql/20231001110211_AddImdbIdToPersonTable.php @@ -0,0 +1,24 @@ +execute( + <<execute( + <<execute( + <<execute( + 'INSERT INTO `tmp_person` ( + `id`, + `name`, + `gender`, + `known_for_department`, + `poster_path`, + `biography`, + `birth_date`, + `place_of_birth`, + `death_date`, + `tmdb_id`, + `tmdb_poster_path`, + `created_at`, + `updated_at`, + `updated_at_tmdb` + ) SELECT + `id`, + `name`, + `gender`, + `known_for_department`, + `poster_path`, + `biography`, + `birth_date`, + `place_of_birth`, + `death_date`, + `tmdb_id`, + `tmdb_poster_path`, + `created_at`, + `updated_at`, + `updated_at_tmdb` + FROM `person`', + ); + $this->execute('DROP TABLE `person`'); + $this->execute('ALTER TABLE `tmp_person` RENAME TO `person`'); + } + + public function up() + { + $this->execute( + <<execute( + 'INSERT INTO `tmp_person` ( + `id`, + `name`, + `gender`, + `known_for_department`, + `poster_path`, + `biography`, + `birth_date`, + `place_of_birth`, + `death_date`, + `tmdb_id`, + `tmdb_poster_path`, + `created_at`, + `updated_at`, + `updated_at_tmdb` + ) SELECT + `id`, + `name`, + `gender`, + `known_for_department`, + `poster_path`, + `biography`, + `birth_date`, + `place_of_birth`, + `death_date`, + `tmdb_id`, + `tmdb_poster_path`, + `created_at`, + `updated_at`, + `updated_at_tmdb` + FROM `person`', + ); + $this->execute('DROP TABLE `person`'); + $this->execute('ALTER TABLE `tmp_person` RENAME TO `person`'); + } +} diff --git a/src/Api/Imdb/ImdbUrlGenerator.php b/src/Api/Imdb/ImdbUrlGenerator.php index 7bc00699..20d6517d 100644 --- a/src/Api/Imdb/ImdbUrlGenerator.php +++ b/src/Api/Imdb/ImdbUrlGenerator.php @@ -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"; + } } diff --git a/src/Api/Tmdb/Dto/TmdbPerson.php b/src/Api/Tmdb/Dto/TmdbPerson.php index 210a8464..9e0b5232 100644 --- a/src/Api/Tmdb/Dto/TmdbPerson.php +++ b/src/Api/Tmdb/Dto/TmdbPerson.php @@ -9,6 +9,7 @@ class TmdbPerson { private function __construct( private readonly int $tmdbId, + private readonly ?string $imdbId, private readonly string $name, private readonly ?string $biography, private readonly ?Date $birthDate, @@ -25,6 +26,7 @@ public static function createFromArray(array $data) : self { return new self( $data['id'], + $data['imdb_id'], $data['name'], empty($data['biography']) === true ? null : $data['biography'], empty($data['birthday']) === true ? null : Date::createFromString($data['birthday']), @@ -57,6 +59,11 @@ public function getGender() : Gender return $this->gender; } + public function getImdbId() : ?string + { + return $this->imdbId; + } + public function getKnownForDepartment() : ?string { return $this->knownForDepartment; diff --git a/src/Api/Tmdb/TmdbUrlGenerator.php b/src/Api/Tmdb/TmdbUrlGenerator.php index c62a8510..7771ed7b 100644 --- a/src/Api/Tmdb/TmdbUrlGenerator.php +++ b/src/Api/Tmdb/TmdbUrlGenerator.php @@ -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/"); + } } diff --git a/src/Domain/Person/PersonApi.php b/src/Domain/Person/PersonApi.php index e132ecbd..54986252 100644 --- a/src/Domain/Person/PersonApi.php +++ b/src/Domain/Person/PersonApi.php @@ -24,6 +24,7 @@ public function create( ?Date $deathDate = null, ?string $placeOfBirth = null, ?DateTime $updatedAtTmdb = null, + ?string $imdbId = null, ) : PersonEntity { return $this->repository->create( $tmdbId, @@ -36,6 +37,7 @@ public function create( $deathDate, $placeOfBirth, $updatedAtTmdb, + $imdbId, ); } @@ -113,6 +115,7 @@ public function update( ?Date $deathDate = null, ?string $placeOfBirth = null, ?DateTime $updatedAtTmdb = null, + ?string $imdbId = null, ) : PersonEntity { return $this->repository->update( $id, @@ -126,6 +129,7 @@ public function update( $deathDate, $placeOfBirth, $updatedAtTmdb, + $imdbId, ); } } diff --git a/src/Domain/Person/PersonEntity.php b/src/Domain/Person/PersonEntity.php index 577ac0bd..0becbd6c 100644 --- a/src/Domain/Person/PersonEntity.php +++ b/src/Domain/Person/PersonEntity.php @@ -14,6 +14,7 @@ private function __construct( private readonly Gender $gender, private readonly ?string $knownForDepartment, private readonly int $tmdbId, + private readonly ?string $imdbId, private readonly ?string $posterPath, private readonly ?string $tmdbPosterPath, private readonly ?string $biography, @@ -32,6 +33,7 @@ public static function createFromArray(array $data) : self Gender::createFromInt((int)$data['gender']), $data['known_for_department'], $data['tmdb_id'], + $data['imdb_id'], $data['poster_path'], $data['tmdb_poster_path'], empty($data['biography']) === true ? null : $data['biography'], @@ -67,6 +69,11 @@ public function getId() : int return $this->id; } + public function getImdbId() : ?string + { + return $this->imdbId; + } + public function getKnownForDepartment() : ?string { return $this->knownForDepartment; diff --git a/src/Domain/Person/PersonRepository.php b/src/Domain/Person/PersonRepository.php index 97674a0f..295141a6 100644 --- a/src/Domain/Person/PersonRepository.php +++ b/src/Domain/Person/PersonRepository.php @@ -25,6 +25,7 @@ public function create( ?Date $deathDate = null, ?string $placeOfBirth = null, ?DateTime $updatedAtTmdb = null, + ?string $imdbId = null, ) : PersonEntity { $this->dbConnection->insert( 'person', @@ -33,6 +34,7 @@ public function create( 'gender' => $gender->asInt(), 'known_for_department' => $knownForDepartment, 'tmdb_id' => $tmdbId, + 'imdb_id' => $imdbId, 'tmdb_poster_path' => $tmdbPosterPath, 'biography' => $biography === null ? null : $biography, 'birth_date' => $birthDate === null ? null : (string)$birthDate, @@ -117,12 +119,14 @@ public function update( ?Date $deathDate = null, ?string $placeOfBirth = null, ?DateTime $updatedAtTmdb = null, + ?string $imdbId = null, ) : PersonEntity { $payload = [ 'name' => $name, 'gender' => $gender->asInt(), 'known_for_department' => $knownForDepartment, 'tmdb_id' => $tmdbId, + 'imdb_id' => $imdbId, 'tmdb_poster_path' => $tmdbPosterPath, 'biography' => $biography === null ? null : $biography, 'birth_date' => $birthDate === null ? null : (string)$birthDate, diff --git a/src/HttpController/Web/PersonController.php b/src/HttpController/Web/PersonController.php index 5d633fec..f9a7cc9e 100644 --- a/src/HttpController/Web/PersonController.php +++ b/src/HttpController/Web/PersonController.php @@ -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; @@ -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, ) { } @@ -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', [ @@ -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), diff --git a/src/Service/Tmdb/SyncPerson.php b/src/Service/Tmdb/SyncPerson.php index ef5c8ef8..025fc851 100644 --- a/src/Service/Tmdb/SyncPerson.php +++ b/src/Service/Tmdb/SyncPerson.php @@ -49,6 +49,7 @@ public function syncPerson(int $tmdbId) : void $tmdbPerson->getDeathDate(), $tmdbPerson->getPlaceOfBirth(), updatedAtTmdb: DateTime::create(), + imdbId: $tmdbPerson->getImdbId() ); $this->logger->debug('TMDB: Created person meta data', ['personId' => $person->getId(), 'tmdbId' => $person->getTmdbId()]); @@ -72,6 +73,7 @@ public function syncPerson(int $tmdbId) : void $tmdbPerson->getDeathDate(), $tmdbPerson->getPlaceOfBirth(), DateTime::create(), + $tmdbPerson->getImdbId() ); $this->logger->debug('TMDB: Updated person meta data', ['personId' => $person->getId(), 'tmdbId' => $person->getTmdbId()]); diff --git a/templates/page/movie.html.twig b/templates/page/movie.html.twig index 71c42daf..f9474bfb 100644 --- a/templates/page/movie.html.twig +++ b/templates/page/movie.html.twig @@ -43,7 +43,7 @@
- +
@@ -83,25 +83,30 @@
{# --- Buttons --- #} diff --git a/templates/page/person.html.twig b/templates/page/person.html.twig index b308f1cf..3ca1eb6b 100644 --- a/templates/page/person.html.twig +++ b/templates/page/person.html.twig @@ -26,33 +26,45 @@
- +
Known for
-

{{ person.knownForDepartment }}

+

{{ person.knownForDepartment }}

Gender
-

{{ person.gender == '0' ? '-' }}{{ person.gender == '1' ? 'Female' }}{{ person.gender == '2' ? 'Male' }}{{ person.gender == '3' ? 'Non-Binary' }}

+

{{ person.gender == '0' ? '-' }}{{ person.gender == '1' ? 'Female' }}{{ person.gender == '2' ? 'Male' }}{{ person.gender == '3' ? 'Non-Binary' }}

{% if person.birthDate is not null %}
Birth date
-

{{ person.birthDate }} {% if person.deathDate is null %}({{ person.age }}){% endif %}

+

{{ person.birthDate }} {% if person.deathDate is null %}({{ person.age }}){% endif %}

{% endif %} {% if person.deathDate is not null %}
Day of Death
-

{{ person.deathDate }} ({{ person.age }})

+

{{ person.deathDate }} ({{ person.age }})

{% endif %} {% if person.placeOfBirth is not null %}
Place of Birth
-

{{ person.placeOfBirth }}

+

{{ person.placeOfBirth }}

{% endif %}
+ +
Biography
{% if person.biography is not null %}

{{ person.biography|nl2br }}

@@ -65,7 +77,7 @@

No biography available.

{% endif %} -