class-wpml-tm-job-entity.php
6.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
<?php
use WPML\FP\Lst;
class WPML_TM_Job_Entity {
const POST_TYPE = 'post';
const STRING_TYPE = 'string';
const STRING_BATCH = 'st-batch_strings';
const PACKAGE_TYPE = 'package';
/** @var int */
private $id;
/** @var string */
private $type;
/** @var int */
private $tp_id;
/** @var WPML_TM_Jobs_Batch */
private $batch;
/** @var int */
private $status;
/** @var int */
private $original_element_id;
/** @var string */
private $source_language;
/** @var string */
private $target_language;
/** @var string */
private $translation_service;
/** @var DateTime */
private $sent_date;
/** @var DateTime|null */
private $deadline;
/** @var int */
private $translator_id;
/** @var int */
private $revision;
/** @var WPML_TM_Job_TS_Status */
private $ts_status;
/** @var bool */
private $needs_update;
/** @var bool */
private $has_completed_translation = false;
/** @var string */
private $title;
/**
* @param int $id
* @param string $type
* @param int $tp_id
* @param WPML_TM_Jobs_Batch $batch
* @param int $status
*/
public function __construct( $id, $type, $tp_id, WPML_TM_Jobs_Batch $batch, $status ) {
$this->id = (int) $id;
if ( ! self::is_type_valid( $type ) ) {
throw new InvalidArgumentException( 'Invalid type value: ' . $type );
}
$this->type = $type;
$this->tp_id = (int) $tp_id;
$this->batch = $batch;
$this->set_status( $status );
}
/**
* @deprecated Use `get_rid` instead.
*
* This method is deprecated because it caused confusion
* between the `job_id` and the `rid`.
*
* It's actually returning the `rid`.
*
* @return int
*/
public function get_id() {
return $this->get_rid();
}
/**
* @return int
*/
public function get_rid() {
return $this->id;
}
/**
* @return string
*/
public function get_type() {
return $this->type;
}
/**
* @return int
*/
public function get_tp_id() {
return $this->tp_id;
}
/**
* @return WPML_TM_Jobs_Batch
*/
public function get_batch() {
return $this->batch;
}
/**
* @return int
*/
public function get_status() {
return $this->status;
}
/**
* @param int $status
*/
public function set_status( $status ) {
$status = (int) $status;
if ( ! in_array(
$status,
array(
ICL_TM_NOT_TRANSLATED,
ICL_TM_WAITING_FOR_TRANSLATOR,
ICL_TM_IN_PROGRESS,
ICL_TM_TRANSLATION_READY_TO_DOWNLOAD,
ICL_TM_DUPLICATE,
ICL_TM_COMPLETE,
ICL_TM_NEEDS_UPDATE,
ICL_TM_NEEDS_REVIEW,
ICL_TM_ATE_CANCELLED,
ICL_TM_ATE_NEEDS_RETRY,
),
true
) ) {
$status = ICL_TM_NOT_TRANSLATED;
}
$this->status = $status;
}
/**
* @return int
*/
public function get_original_element_id() {
return $this->original_element_id;
}
/**
* @param int $original_element_id
*/
public function set_original_element_id( $original_element_id ) {
$this->original_element_id = $original_element_id;
}
/**
* @return string
*/
public function get_source_language() {
return $this->source_language;
}
/**
* @param string $source_language
*/
public function set_source_language( $source_language ) {
$this->source_language = $source_language;
}
/**
* @return string
*/
public function get_target_language() {
return $this->target_language;
}
/**
* @param string $target_language
*/
public function set_target_language( $target_language ) {
$this->target_language = $target_language;
}
/**
* @return string
*/
public function get_translation_service() {
return $this->translation_service;
}
/**
* @param string $translation_service
*/
public function set_translation_service( $translation_service ) {
$this->translation_service = $translation_service;
}
/**
* @return DateTime
*/
public function get_sent_date() {
return $this->sent_date;
}
/**
* @param DateTime $sent_date
*/
public function set_sent_date( DateTime $sent_date ) {
$this->sent_date = $sent_date;
}
/**
* @param int $tp_id
*/
public function set_tp_id( $tp_id ) {
$this->tp_id = $tp_id;
}
/**
* @return DateTime|null
*/
public function get_deadline() {
return $this->deadline;
}
/**
* @param DateTime|null $deadline
*/
public function set_deadline( DateTime $deadline = null ) {
$this->deadline = $deadline;
}
/**
* @return int
*/
public function get_translator_id() {
return $this->translator_id;
}
/**
* @param int $translator_id
*
* @return self
*/
public function set_translator_id( $translator_id ) {
$this->translator_id = $translator_id;
return $this;
}
/**
* @return int
*/
public function get_revision() {
return $this->revision;
}
/**
* @param int $revision
*/
public function set_revision( $revision ) {
$this->revision = max( (int) $revision, 1 );
}
/**
* @return WPML_TM_Job_TS_Status
*/
public function get_ts_status() {
return $this->ts_status;
}
/**
* @param WPML_TM_Job_TS_Status|string $ts_status
*/
public function set_ts_status( $ts_status ) {
if ( is_string( $ts_status ) ) {
$status = json_decode( $ts_status );
if ( $status ) {
$ts_status = new WPML_TM_Job_TS_Status( $status->ts_status->status, $status->ts_status->links );
}
}
$this->ts_status = $ts_status;
}
/**
* @param WPML_TM_Job_Entity $job
*
* @return bool
*/
public function is_equal( WPML_TM_Job_Entity $job ) {
return $this->get_id() === $job->get_id() && $this->get_type() === $job->get_type();
}
/**
* @return bool
*/
public function does_need_update() {
return $this->needs_update;
}
/**
* @param bool $needs_update
*/
public function set_needs_update( $needs_update ) {
$this->needs_update = (bool) $needs_update;
}
/**
* @return bool
*/
public function has_completed_translation() {
return $this->has_completed_translation;
}
/**
* @param bool $has_completed_translation
*/
public function set_has_completed_translation( $has_completed_translation ) {
$this->has_completed_translation = (bool) $has_completed_translation;
}
/**
* @return string
*/
public function get_title() {
return $this->title;
}
/**
* @param string $title
*/
public function set_title( $title ) {
$this->title = $title;
}
/**
* @param string $type
*
* @return bool
*/
public static function is_type_valid( $type ) {
return Lst::includes( $type, [ self::POST_TYPE, self::STRING_TYPE, self::PACKAGE_TYPE, self::STRING_BATCH ] );
}
}