Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 38
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
CXDraftTranslationDTO
0.00% covered (danger)
0.00%
0 / 38
0.00% covered (danger)
0.00%
0 / 3
12
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
2
 createFromTranslation
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
2
 toArray
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2declare( strict_types = 1 );
3
4namespace ContentTranslation\DTO;
5
6use ContentTranslation\Translation;
7
8/**
9 * DTO class that encapsulates the payload for a draft translation on desktop editor.
10 *
11 * @author Nik Gkountas
12 * @license GPL-2.0-or-later
13 * @since 2023.10
14 */
15class CXDraftTranslationDTO {
16    private int $id;
17    private string $targetTitle;
18    private string $status;
19    private string $progress;
20    private ?int $sectionTranslationId;
21    private ?string $targetURL;
22    private ?string $sourceRevisionId;
23    private ?string $targetRevisionId;
24    private ?string $targetSectionTitle;
25    private ?array $translationUnits;
26    private ?string $targetCategories;
27
28    public function __construct(
29        int $id,
30        string $targetTitle,
31        string $status,
32        string $progress,
33        ?int $sectionTranslationId,
34        ?string $targetURL,
35        ?string $sourceRevisionId,
36        ?string $targetRevisionId,
37        ?string $targetSectionTitle,
38        ?array $translationUnits,
39        ?string $targetCategories
40    ) {
41        $this->id = $id;
42        $this->targetTitle = $targetTitle;
43        $this->status = $status;
44        $this->progress = $progress;
45        $this->sectionTranslationId = $sectionTranslationId;
46        $this->targetURL = $targetURL;
47        $this->sourceRevisionId = $sourceRevisionId;
48        $this->targetRevisionId = $targetRevisionId;
49        $this->targetSectionTitle = $targetSectionTitle;
50        $this->translationUnits = $translationUnits;
51        $this->targetCategories = $targetCategories;
52    }
53
54    public static function createFromTranslation( Translation $translation ): self {
55        $translationData = $translation->getData();
56
57        return new self(
58            $translationData['id'],
59            $translationData['targetTitle'],
60            $translationData['status'],
61            $translationData['progress'],
62            $translationData['sectionTranslationId'] ?? null,
63            $translationData['targetURL'],
64            $translationData['sourceRevisionId'],
65            $translationData['targetRevisionId'],
66            $translationData['targetSectionTitle'] ?? null,
67            $translationData['translationUnits'],
68            $translationData['targetCategories']
69        );
70    }
71
72    public function toArray(): array {
73        return [
74            "id" => $this->id,
75            "targetTitle" => $this->targetTitle,
76            "status" => $this->status,
77            "progress" => $this->progress,
78            "sectionTranslationId" => $this->sectionTranslationId,
79            "targetURL" => $this->targetURL,
80            "sourceRevisionId" => $this->sourceRevisionId,
81            "targetRevisionId" => $this->targetRevisionId,
82            "targetSectionTitle" => $this->targetSectionTitle,
83            "translationUnits" => $this->translationUnits,
84            "targetCategories" => $this->targetCategories,
85        ];
86    }
87}