Skip to content

Commit

Permalink
Merge pull request #430 from leepeuker/add-biography-to-person
Browse files Browse the repository at this point in the history
Add biography to person
  • Loading branch information
leepeuker authored Jul 10, 2023
2 parents 8b1cf6c + 08d57ed commit 7c5b88d
Show file tree
Hide file tree
Showing 10 changed files with 225 additions and 5 deletions.
24 changes: 24 additions & 0 deletions db/migrations/mysql/20230704133329_AddBiographyToPersonTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class AddBiographyToPersonTable extends AbstractMigration
{
public function down() : void
{
$this->execute(
<<<SQL
ALTER TABLE person DROP COLUMN biography;
SQL,
);
}

public function up() : void
{
$this->execute(
<<<SQL
ALTER TABLE person ADD COLUMN biography TEXT NULL AFTER birth_date;
SQL,
);
}
}
123 changes: 123 additions & 0 deletions db/migrations/sqlite/20230704133329_AddBiographyToPersonTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?php declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class AddBiographyToPersonTable extends AbstractMigration
{
public function down()
{
$this->execute(
<<<SQL
CREATE TABLE `tmp_person` (
`id` INTEGER,
`name` TEXT NOT NULL,
`gender` TEXT NOT NULL,
`known_for_department` TEXT DEFAULT NULL,
`poster_path` TEXT DEFAULT NULL,
`birth_date` TEXT DEFAULT NULL,
`place_of_birth` TEXT DEFAULT NULL,
`death_date` TEXT DEFAULT NULL,
`tmdb_id` INTEGER NOT NULL,
`tmdb_poster_path` TEXT DEFAULT NULL,
`created_at` TEXT NOT NULL,
`updated_at` TEXT DEFAULT NULL,
`updated_at_tmdb` TEXT DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE (`tmdb_id`)
)
SQL,
);
$this->execute(
'INSERT INTO `tmp_person` (
`id`,
`name`,
`gender`,
`known_for_department`,
`poster_path`,
`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`,
`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(
<<<SQL
CREATE TABLE `tmp_person` (
`id` INTEGER,
`name` TEXT NOT NULL,
`gender` TEXT NOT NULL,
`known_for_department` TEXT DEFAULT NULL,
`poster_path` TEXT DEFAULT NULL,
`biography` TEXT DEFAULT NULL,
`birth_date` TEXT DEFAULT NULL,
`place_of_birth` TEXT DEFAULT NULL,
`death_date` TEXT DEFAULT NULL,
`tmdb_id` INTEGER NOT NULL,
`tmdb_poster_path` TEXT DEFAULT NULL,
`created_at` TEXT NOT NULL,
`updated_at` TEXT DEFAULT NULL,
`updated_at_tmdb` TEXT DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE (`tmdb_id`)
)
SQL,
);
$this->execute(
'INSERT INTO `tmp_person` (
`id`,
`name`,
`gender`,
`known_for_department`,
`poster_path`,
`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`,
`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`');
}
}
24 changes: 24 additions & 0 deletions public/js/person.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function toggleBiography()
{
let expandContainer = document.getElementById('expandContainer');
if(document.getElementsByClassName('truncated').length > 0) {
document.getElementById('biographyParagraph').classList.remove('truncated');
expandContainer.getElementsByTagName('i')[0].classList.remove('bi-chevron-down');
expandContainer.getElementsByTagName('i')[0].classList.add('bi-chevron-up');
expandContainer.children[1].innerHTML = 'Show less&#8230;';
} else {
document.getElementById('biographyParagraph').classList.add('truncated');
expandContainer.getElementsByTagName('i')[0].classList.add('bi-chevron-down');
expandContainer.getElementsByTagName('i')[0].classList.remove('bi-chevron-up');
expandContainer.children[1].innerHTML = 'Show more&#8230;';
}
}

document.addEventListener("DOMContentLoaded", () => {
let biographyHeight = document.getElementById('biographyParagraph').offsetHeight;
let windowHeight = window.outerHeight;
if(((biographyHeight / windowHeight) * 100) > 20) {
document.getElementById('biographyParagraph').classList.add('truncated');
document.getElementById('expandContainer').classList.remove('d-none');
}
});
7 changes: 7 additions & 0 deletions src/Api/Tmdb/Dto/TmdbPerson.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class TmdbPerson
private function __construct(
private readonly int $tmdbId,
private readonly string $name,
private readonly ?string $biography,
private readonly ?Date $birthDate,
private readonly ?Date $deathDate,
private readonly Gender $gender,
Expand All @@ -25,6 +26,7 @@ public static function createFromArray(array $data) : self
return new self(
$data['id'],
$data['name'],
empty($data['biography']) === true ? null : $data['biography'],
empty($data['birthday']) === true ? null : Date::createFromString($data['birthday']),
empty($data['deathday']) === true ? null : Date::createFromString($data['deathday']),
Gender::createFromInt($data['gender']),
Expand All @@ -35,6 +37,11 @@ public static function createFromArray(array $data) : self
);
}

public function getBiography() : ?string
{
return $this->biography;
}

public function getBirthDate() : ?Date
{
return $this->birthDate;
Expand Down
4 changes: 4 additions & 0 deletions src/Domain/Person/PersonApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function create(
Gender $gender,
?string $knownForDepartment,
?string $tmdbPosterPath,
?string $biography = null,
?Date $birthDate = null,
?Date $deathDate = null,
?string $placeOfBirth = null,
Expand All @@ -30,6 +31,7 @@ public function create(
$gender,
$knownForDepartment,
$tmdbPosterPath,
$biography,
$birthDate,
$deathDate,
$placeOfBirth,
Expand Down Expand Up @@ -106,6 +108,7 @@ public function update(
Gender $gender,
?string $knownForDepartment,
?string $tmdbPosterPath,
?string $biography = null,
?Date $birthDate = null,
?Date $deathDate = null,
?string $placeOfBirth = null,
Expand All @@ -118,6 +121,7 @@ public function update(
$gender,
$knownForDepartment,
$tmdbPosterPath,
$biography,
$birthDate,
$deathDate,
$placeOfBirth,
Expand Down
7 changes: 7 additions & 0 deletions src/Domain/Person/PersonEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ private function __construct(
private readonly int $tmdbId,
private readonly ?string $posterPath,
private readonly ?string $tmdbPosterPath,
private readonly ?string $biography,
private readonly ?Date $birthDate,
private readonly ?Date $deathDate,
private readonly ?string $placeOfBirth,
Expand All @@ -33,13 +34,19 @@ public static function createFromArray(array $data) : self
$data['tmdb_id'],
$data['poster_path'],
$data['tmdb_poster_path'],
empty($data['biography']) === true ? null : $data['biography'],
empty($data['birth_date']) === true ? null : Date::createFromString($data['birth_date']),
empty($data['death_date']) === true ? null : Date::createFromString($data['death_date']),
$data['place_of_birth'],
empty($data['updated_at_tmdb']) === true ? null : DateTime::createFromString($data['updated_at_tmdb']),
);
}

public function getBiography() : ?string
{
return $this->biography;
}

public function getBirthDate() : ?Date
{
return $this->birthDate;
Expand Down
4 changes: 4 additions & 0 deletions src/Domain/Person/PersonRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function create(
Gender $gender,
?string $knownForDepartment,
?string $tmdbPosterPath,
?string $biography = null,
?Date $birthDate = null,
?Date $deathDate = null,
?string $placeOfBirth = null,
Expand All @@ -33,6 +34,7 @@ public function create(
'known_for_department' => $knownForDepartment,
'tmdb_id' => $tmdbId,
'tmdb_poster_path' => $tmdbPosterPath,
'biography' => $biography === null ? null : $biography,
'birth_date' => $birthDate === null ? null : (string)$birthDate,
'death_date' => $deathDate === null ? null : (string)$deathDate,
'place_of_birth' => $placeOfBirth,
Expand Down Expand Up @@ -110,6 +112,7 @@ public function update(
Gender $gender,
?string $knownForDepartment,
?string $tmdbPosterPath,
?string $biography = null,
?Date $birthDate = null,
?Date $deathDate = null,
?string $placeOfBirth = null,
Expand All @@ -121,6 +124,7 @@ public function update(
'known_for_department' => $knownForDepartment,
'tmdb_id' => $tmdbId,
'tmdb_poster_path' => $tmdbPosterPath,
'biography' => $biography === null ? null : $biography,
'birth_date' => $birthDate === null ? null : (string)$birthDate,
'death_date' => $deathDate === null ? null : (string)$deathDate,
'place_of_birth' => $placeOfBirth,
Expand Down
1 change: 1 addition & 0 deletions src/HttpController/PersonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public function renderPage(Request $request) : Response
'knownForDepartment' => $person->getKnownForDepartment(),
'gender' => $person->getGender(),
'age' => $age,
'biography' => $person->getBiography(),
'birthDate' => $person->getBirthDate(),
'deathDate' => $person->getDeathDate(),
'placeOfBirth' => $person->getPlaceOfBirth(),
Expand Down
2 changes: 2 additions & 0 deletions src/Service/Tmdb/SyncPerson.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function syncPerson(int $tmdbId) : void
$tmdbPerson->getGender(),
$tmdbPerson->getKnownForDepartment(),
$tmdbPerson->getProfilePath(),
$tmdbPerson->getBiography(),
$tmdbPerson->getBirthDate(),
$tmdbPerson->getDeathDate(),
$tmdbPerson->getPlaceOfBirth(),
Expand All @@ -66,6 +67,7 @@ public function syncPerson(int $tmdbId) : void
$tmdbPerson->getGender(),
$tmdbPerson->getKnownForDepartment(),
$tmdbPerson->getProfilePath(),
$tmdbPerson->getBiography(),
$tmdbPerson->getBirthDate(),
$tmdbPerson->getDeathDate(),
$tmdbPerson->getPlaceOfBirth(),
Expand Down
34 changes: 29 additions & 5 deletions templates/page/person.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@

{% block scripts %}
<script src="/js/user-select.js"></script>
<script src="/js/person.js"></script>
{% endblock %}

{% block body %}
<style>
.truncated {
-webkit-mask-image: linear-gradient(to bottom, black 75%, transparent 100%);
mask-image: linear-gradient(to bottom, black 75%, transparent 100%);
max-height: 4rem;
overflow-y: hidden;
}
</style>
<main role="main" class="container">
{{ include('component/navbar.html.twig') }}
{{ include('component/user-select.html.twig') }}
Expand All @@ -29,19 +38,34 @@

{% if person.birthDate is not null %}
<h6 style="margin-bottom: 0.1rem">Birth date</h6>
<p style="margin-bottom: 0.4rem">{{ person.birthDate }} ({{ person.age }}{% if person.deathDate is not null %}&#10013;{% endif %})</p>
<p style="margin-bottom: 0.4rem">{{ person.birthDate }} {% if person.deathDate is null %}({{ person.age }}){% endif %}</p>
{% endif %}

{% if person.deathDate is not null %}
<h6 style="margin-bottom: 0.1rem">Death date</h6>
<p style="margin-bottom: 0.4rem">{{ person.deathDate }}</p>
<h6 style="margin-bottom: 0.1rem">Day of Death</h6>
<p style="margin-bottom: 0.4rem">{{ person.deathDate }} ({{ person.age }})</p>
{% endif %}

{% if person.placeOfBirth is not null %}
<h6 style="margin-bottom: 0.1rem">Place of Birth</h6>
<p style="margin-bottom: 0.4rem">{{ person.placeOfBirth }}</p>
{% endif %}
</div>
</div>

<br>
<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>
<div class="text-primary d-none" style="cursor: pointer; top: 0;" id="expandContainer">
<span style="padding: 0;float: right;" onclick="toggleBiography()"><i class="bi bi-chevron-down"></i></span>
<span style="float: right; margin-right: 0.5em;" onclick="toggleBiography()">Read more&#8230;</span>
<br>
</div>
{% else %}
<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 Down

0 comments on commit 7c5b88d

Please sign in to comment.