Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 26 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
PublishedTranslationDTO | |
0.00% |
0 / 26 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
2 | |||
toArray | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | declare( strict_types = 1 ); |
4 | |
5 | namespace ContentTranslation\DTO; |
6 | |
7 | /** |
8 | * This class represents data transfer objects, used to return |
9 | * published translations from the Content Translation API. |
10 | * |
11 | * @copyright See AUTHORS.txt |
12 | * @license GPL-2.0-or-later |
13 | */ |
14 | class PublishedTranslationDTO extends AbstractTranslationDTO { |
15 | /** @var PublishedSectionTranslationDTO[] */ |
16 | private array $sectionTranslations; |
17 | private ?string $targetUrl; |
18 | |
19 | public function __construct( |
20 | int $translationId, |
21 | string $sourceTitle, |
22 | string $sourceLanguage, |
23 | string $targetLanguage, |
24 | string $startTimestamp, |
25 | string $lastUpdatedTimestamp, |
26 | string $pageRevision, |
27 | // corresponds to the "translation_target_title" field of "cx_translations" table, which cannot be null |
28 | string $targetTitle, |
29 | // Since we always set the target URL for the root translation when an article ("cxpublish" action) |
30 | // or a section ("cxpublishsection" action) is published, this field is expected to be a non-empty |
31 | // string under normal circumstances. However, apparently, there might be cases that for unknown |
32 | // reasons the target URL remains null, even for published translations. For this reason, let this |
33 | // field be nullable to avoid errors. |
34 | ?string $targetUrl, |
35 | array $sectionTranslations |
36 | ) { |
37 | parent::__construct( |
38 | $translationId, |
39 | $sourceTitle, |
40 | $sourceLanguage, |
41 | $targetLanguage, |
42 | $startTimestamp, |
43 | $lastUpdatedTimestamp, |
44 | $pageRevision, |
45 | $targetTitle, |
46 | ); |
47 | |
48 | $this->sectionTranslations = $sectionTranslations; |
49 | $this->targetUrl = $targetUrl; |
50 | } |
51 | |
52 | public function toArray(): array { |
53 | return [ |
54 | "translationId" => $this->translationId, |
55 | "sourceTitle" => $this->sourceTitle, |
56 | "sourceLanguage" => $this->sourceLanguage, |
57 | "targetLanguage" => $this->targetLanguage, |
58 | "startTimestamp" => $this->startTimestamp, |
59 | "lastUpdatedTimestamp" => $this->lastUpdatedTimestamp, |
60 | "pageRevision" => $this->pageRevision, |
61 | "targetTitle" => $this->targetTitle, |
62 | "targetUrl" => $this->targetUrl, |
63 | "sectionTranslations" => array_map( static function ( PublishedSectionTranslationDTO $dto ) { |
64 | return $dto->toArray(); |
65 | }, $this->sectionTranslations ) |
66 | ]; |
67 | } |
68 | } |