Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 30 |
|
0.00% |
0 / 10 |
CRAP | |
0.00% |
0 / 1 |
| Translation | |
0.00% |
0 / 30 |
|
0.00% |
0 / 10 |
132 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| isNew | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setIsNew | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getTranslationId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getSourceTitle | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getSourceLanguage | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getTargetLanguage | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getStatus | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getData | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| newFromRow | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace ContentTranslation; |
| 4 | |
| 5 | class Translation { |
| 6 | private bool $isNew = false; |
| 7 | |
| 8 | public function __construct( public array $translation ) { |
| 9 | } |
| 10 | |
| 11 | /** |
| 12 | * @return bool Whether the last CRUD operation on this translation was "create" |
| 13 | */ |
| 14 | public function isNew(): bool { |
| 15 | return $this->isNew; |
| 16 | } |
| 17 | |
| 18 | public function setIsNew( bool $isNew ): void { |
| 19 | $this->isNew = $isNew; |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * @return int |
| 24 | */ |
| 25 | public function getTranslationId() { |
| 26 | return $this->translation['id']; |
| 27 | } |
| 28 | |
| 29 | public function getSourceTitle(): string { |
| 30 | return $this->translation['sourceTitle']; |
| 31 | } |
| 32 | |
| 33 | public function getSourceLanguage(): string { |
| 34 | return $this->translation['sourceLanguage']; |
| 35 | } |
| 36 | |
| 37 | public function getTargetLanguage(): string { |
| 38 | return $this->translation['targetLanguage']; |
| 39 | } |
| 40 | |
| 41 | public function getStatus(): string { |
| 42 | return $this->translation['status']; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Return the underlying data fields. |
| 47 | * |
| 48 | * @return array |
| 49 | */ |
| 50 | public function getData() { |
| 51 | return $this->translation; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * @param \stdClass $row |
| 56 | * @return self |
| 57 | */ |
| 58 | public static function newFromRow( $row ) { |
| 59 | $fields = [ |
| 60 | 'id' => (int)$row->translation_id, |
| 61 | 'sourceTitle' => $row->translation_source_title, |
| 62 | 'targetTitle' => $row->translation_target_title, |
| 63 | 'sourceLanguage' => $row->translation_source_language, |
| 64 | 'targetLanguage' => $row->translation_target_language, |
| 65 | 'sourceRevisionId' => $row->translation_source_revision_id, |
| 66 | 'targetRevisionId' => $row->translation_target_revision_id, |
| 67 | 'sourceURL' => $row->translation_source_url, |
| 68 | 'targetURL' => $row->translation_target_url, |
| 69 | 'status' => $row->translation_status, |
| 70 | 'startTimestamp' => $row->translation_start_timestamp, |
| 71 | 'lastUpdateTimestamp' => $row->translation_last_updated_timestamp, |
| 72 | 'progress' => $row->translation_progress, |
| 73 | 'startedTranslator' => $row->translation_started_by, |
| 74 | 'lastUpdatedTranslator' => $row->translation_last_update_by, |
| 75 | 'cxVersion' => 1, |
| 76 | ]; |
| 77 | |
| 78 | // BC code to gracefully handle lack of schema change |
| 79 | if ( isset( $row->translation_cx_version ) ) { |
| 80 | $fields['cxVersion'] = (int)$row->translation_cx_version; |
| 81 | } |
| 82 | |
| 83 | return new self( $fields ); |
| 84 | } |
| 85 | } |