Skip to content

Commit

Permalink
Can add a translation group id to a talk
Browse files Browse the repository at this point in the history
When a talk belongs to a translation group then it's fairly easy to find the same talk that has been done in a different language. One talk with two different locales, two different rows, can belong to one group. This is a principle similar to what's used for blog posts.

Database tables DDL queries to add the column:
```
ALTER TABLE `talks` ADD `key_translation_group` int unsigned NULL COMMENT 'No foreign key, yet' AFTER `key_locale`;
ALTER TABLE `talks` ADD UNIQUE `key_locale_key_translation_group` (`key_locale`, `key_translation_group`);
```
  • Loading branch information
spaze committed Aug 14, 2023
1 parent 47041a6 commit 5e8fea4
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions site/app/Form/TalkFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public function create(callable $onSuccess, ?Talk $talk = null): Form
$form = $this->factory->create();
$allTalks = $this->getAllTalksExcept($talk ? (string)$talk->getAction() : null);

$form->addInteger('translationGroup', 'Skupina překladů:')
->setRequired(false);
$form->addSelect('locale', 'Jazyk:', $this->locales->getAllLocales())
->setRequired('Zadejte prosím jazyk')
->setPrompt('- vyberte -');
Expand Down Expand Up @@ -112,6 +114,7 @@ public function create(callable $onSuccess, ?Talk $talk = null): Form
$this->talks->update(
$talk->getId(),
$values->locale,
$values->translationGroup,
$values->action,
$values->title,
$values->description,
Expand Down Expand Up @@ -145,6 +148,7 @@ public function create(callable $onSuccess, ?Talk $talk = null): Form
} else {
$talkId = $this->talks->add(
$values->locale,
$values->translationGroup,
$values->action,
$values->title,
$values->description,
Expand Down Expand Up @@ -185,6 +189,7 @@ public function setTalk(Form $form, Talk $talk, SubmitButton $submit): void
$values = [
'action' => $talk->getAction(),
'locale' => $talk->getLocaleId(),
'translationGroup' => $talk->getTranslationGroupId(),
'title' => $talk->getTitleTexy(),
'description' => $talk->getDescriptionTexy(),
'date' => $talk->getDate()->format('Y-m-d H:i'),
Expand Down
7 changes: 7 additions & 0 deletions site/app/Talks/Talk.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public function __construct(
private readonly int $id,
private readonly int $localeId,
private readonly string $locale,
private readonly ?int $translationGroupId,
private readonly ?string $action,
private readonly ?string $url,
private readonly Html $title,
Expand Down Expand Up @@ -63,6 +64,12 @@ public function getLocale(): string
}


public function getTranslationGroupId(): ?int
{
return $this->translationGroupId;
}


public function getAction(): ?string
{
return $this->action;
Expand Down
1 change: 1 addition & 0 deletions site/app/Talks/TalkFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function createFromDatabaseRow(Row $row): Talk
$row->id,
$row->localeId,
$row->locale,
$row->translationGroupId,
$row->action,
$url ?? null,
$this->texyFormatter->format($row->title),
Expand Down
10 changes: 10 additions & 0 deletions site/app/Talks/Talks.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function getAll(?int $limit = null): array
t.id_talk AS id,
t.key_locale AS localeId,
l.locale,
t.key_translation_group AS translationGroupId,
t.action,
t.title,
t.description,
Expand Down Expand Up @@ -94,6 +95,7 @@ public function getUpcoming(): array
t.id_talk AS id,
t.key_locale AS localeId,
l.locale,
t.key_translation_group AS translationGroupId,
t.action,
t.title,
t.description,
Expand Down Expand Up @@ -143,6 +145,7 @@ public function get(string $name): Talk
t.id_talk AS id,
t.key_locale AS localeId,
l.locale,
t.key_translation_group AS translationGroupId,
t.action,
t.title,
t.description,
Expand Down Expand Up @@ -192,6 +195,7 @@ public function getById(int $id): Talk
t.id_talk AS id,
t.key_locale AS localeId,
l.locale,
t.key_translation_group AS translationGroupId,
t.action,
t.title,
t.description,
Expand Down Expand Up @@ -262,6 +266,7 @@ public function getFavorites(): array
public function update(
int $id,
int $localeId,
?int $translationGroupId,
?string $action,
string $title,
?string $description,
Expand All @@ -286,6 +291,7 @@ public function update(
): void {
$params = $this->getAddUpdateParams(
$localeId,
$translationGroupId,
$action,
$title,
$description,
Expand Down Expand Up @@ -319,6 +325,7 @@ public function update(
*/
public function add(
int $localeId,
?int $translationGroupId,
?string $action,
string $title,
?string $description,
Expand All @@ -343,6 +350,7 @@ public function add(
): int {
$params = $this->getAddUpdateParams(
$localeId,
$translationGroupId,
$action,
$title,
$description,
Expand Down Expand Up @@ -389,6 +397,7 @@ public function pageTitle(string $translationKey, Talk $talk): Html
*/
private function getAddUpdateParams(
int $localeId,
?int $translationGroupId,
?string $action,
string $title,
?string $description,
Expand Down Expand Up @@ -418,6 +427,7 @@ private function getAddUpdateParams(
}
return [
'key_locale' => $localeId,
'key_translation_group' => empty($translationGroupId) ? null : $translationGroupId,
'action' => (empty($action) ? null : $action),
'title' => $title,
'description' => (empty($description) ? null : $description),
Expand Down
3 changes: 3 additions & 0 deletions site/app/Talks/talkInputs.latte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
{varType int $videoThumbnailHeight}
{form talk class => "aligned wide"}
<table>
<tr>
<th>{label translationGroup /}</th><td class="short">{input translationGroup}</td>
</tr>
<tr>
<th>{label locale /}</th><td class="short">{input locale}</td>
</tr>
Expand Down

0 comments on commit 5e8fea4

Please sign in to comment.