-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display a direct link to the talk in the other locale, if available
And a generic "list all talks" link if not.
- Loading branch information
Showing
4 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace MichalSpacekCz\Talks; | ||
|
||
use Nette\Database\Explorer; | ||
|
||
class TalkLocaleUrls | ||
{ | ||
|
||
public function __construct( | ||
private readonly Explorer $database, | ||
) { | ||
} | ||
|
||
|
||
/** | ||
* @return array<string, string> locale => action | ||
*/ | ||
public function get(Talk $talk): array | ||
{ | ||
if (!$talk->getTranslationGroupId()) { | ||
return []; | ||
} | ||
return $this->database->fetchPairs( | ||
'SELECT l.locale, t.action FROM talks t JOIN locales l ON t.key_locale = l.id_locale WHERE t.key_translation_group = ?', | ||
$talk->getTranslationGroupId(), | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace MichalSpacekCz\Talks; | ||
|
||
use DateTime; | ||
use MichalSpacekCz\Media\Video; | ||
use MichalSpacekCz\Test\Database\Database; | ||
use Nette\Utils\Html; | ||
use Tester\Assert; | ||
use Tester\TestCase; | ||
|
||
$runner = require __DIR__ . '/../bootstrap.php'; | ||
|
||
/** @testCase */ | ||
class TalkLocaleUrlsTest extends TestCase | ||
{ | ||
|
||
public function __construct( | ||
private readonly TalkLocaleUrls $talkLocaleUrls, | ||
private readonly Database $database, | ||
) { | ||
} | ||
|
||
|
||
public function testGet(): void | ||
{ | ||
$expected = ['cs_CZ' => 'foobar']; | ||
$this->database->setFetchPairsResult($expected); | ||
Assert::same([], $this->talkLocaleUrls->get($this->buildTalk(null))); | ||
Assert::same($expected, $this->talkLocaleUrls->get($this->buildTalk(1337))); | ||
} | ||
|
||
|
||
private function buildTalk(?int $translationGroup): Talk | ||
{ | ||
$video = new Video( | ||
null, | ||
null, | ||
null, | ||
null, | ||
null, | ||
null, | ||
320, | ||
200, | ||
null, | ||
); | ||
return new Talk( | ||
10, | ||
1, | ||
'cs_CZ', | ||
$translationGroup, | ||
null, | ||
null, | ||
Html::fromText('title'), | ||
'title', | ||
null, | ||
null, | ||
new DateTime(), | ||
null, | ||
null, | ||
false, | ||
null, | ||
null, | ||
$video, | ||
null, | ||
Html::fromText('event'), | ||
'event', | ||
null, | ||
null, | ||
null, | ||
null, | ||
null, | ||
null, | ||
null, | ||
null, | ||
null, | ||
null, | ||
false, | ||
); | ||
} | ||
|
||
} | ||
|
||
$runner->run(TalkLocaleUrlsTest::class); |