wpml-tf-feedback.php
6.55 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
<?php
/**
* Class WPML_TF_Feedback
*
* @author OnTheGoSystems
*/
class WPML_TF_Feedback implements IWPML_TF_Data_Object {
/** @var int */
private $id;
/** @var string */
private $date_created;
/** @var WPML_TF_Feedback_Status */
private $status;
/** @var int */
private $rating;
/** @var string */
private $content;
/** @var int */
private $document_id;
/** @var string */
private $document_type;
/** @var string */
private $language_from;
/** @var string */
private $language_to;
/** @var int|null */
private $job_id;
/** @var WPML_TF_Feedback_Reviewer */
private $reviewer;
/** @var WPML_TF_Collection $messages */
private $messages;
/** @var WPML_TF_Backend_Document_Information $document_information */
private $document_information;
/** @var WPML_TF_TP_Responses $tp_rating_responses */
private $tp_responses;
/**
* WPML_Translation_Feedback constructor.
*
* @param array $data
* @param WPML_TF_Backend_Document_Information $document_information
*/
public function __construct(
$data = array(),
WPML_TF_Backend_Document_Information $document_information = null
) {
$this->id = array_key_exists( 'id', $data ) ? (int) $data['id'] : null;
$this->date_created = array_key_exists( 'date_created', $data )
? sanitize_text_field( $data['date_created'] ) : null;
$this->rating = array_key_exists( 'rating', $data ) ? (int) $data['rating'] : null;
$this->content = array_key_exists( 'content', $data )
? sanitize_text_field( $data['content'] ) : '';
$this->document_id = array_key_exists( 'document_id', $data ) ? (int) $data['document_id'] : null;
$this->document_type = array_key_exists( 'document_type', $data )
? sanitize_text_field( $data['document_type'] ) : null;
$this->language_from = array_key_exists( 'language_from', $data )
? sanitize_text_field( $data['language_from'] ) : null;
$this->language_to = array_key_exists( 'language_to', $data )
? sanitize_text_field( $data['language_to'] ) : null;
$this->job_id = array_key_exists( 'job_id', $data ) ? (int) $data['job_id'] : null;
$this->messages = array_key_exists( 'messages', $data ) && $data['messages'] instanceof WPML_TF_Collection
? $data['messages'] : new WPML_TF_Message_Collection();
if ( array_key_exists( 'reviewer_id', $data ) ) {
$this->set_reviewer( $data['reviewer_id'] );
}
$this->status = array_key_exists( 'status', $data )
? new WPML_TF_Feedback_Status( $data['status'] ) : new WPML_TF_Feedback_Status( 'pending' );
$this->set_tp_responses( new WPML_TF_TP_Responses( $data ) );
if ( $document_information ) {
$this->set_document_information( $document_information );
}
}
/**
* @return int|mixed|null
*/
public function get_id() {
return $this->id;
}
/**
* @return int|null
*/
public function get_feedback_id() {
return $this->id;
}
/**
* @param \WPML_TF_Message $message
*/
public function add_message( WPML_TF_Message $message ) {
$this->messages->add( $message );
}
/**
* @return mixed|null|string
*/
public function get_date_created() {
return $this->date_created;
}
/**
* @return string
*/
public function get_status() {
return $this->status->get_value();
}
/**
* @param string $status
*/
public function set_status( $status ) {
$this->status->set_value( $status );
}
/**
* @return int
*/
public function get_rating() {
return $this->rating;
}
/**
* @param int $rating
*/
public function set_rating( $rating ) {
$this->rating = (int) $rating;
}
/**
* @return mixed|null|string
*/
public function get_content() {
return $this->content;
}
/**
* @param string $content
*/
public function set_content( $content ) {
$this->content = sanitize_text_field( $content );
}
/**
* @return int|null
*/
public function get_document_id() {
return $this->document_id;
}
/**
* @return null|string
*/
public function get_document_type() {
return $this->document_type;
}
/**
* @return null|string
*/
public function get_language_from() {
return $this->language_from;
}
/**
* @return null|string
*/
public function get_language_to() {
return $this->language_to;
}
/**
* @return int|null
*/
public function get_job_id() {
return $this->job_id;
}
/**
* @return WPML_TF_Feedback_Reviewer
*/
public function get_reviewer() {
if ( ! isset( $this->reviewer ) ) {
$this->set_reviewer( 0 );
}
return $this->reviewer;
}
/**
* @param int $reviewer_id
*/
public function set_reviewer( $reviewer_id ) {
$this->reviewer = new WPML_TF_Feedback_Reviewer( $reviewer_id );
}
/**
* @return WPML_TF_Collection
*/
public function get_messages() {
return $this->messages;
}
/** @param WPML_TF_TP_Responses $tp_responses */
public function set_tp_responses( WPML_TF_TP_Responses $tp_responses ) {
$this->tp_responses = $tp_responses;
}
/** @return WPML_TF_TP_Responses */
public function get_tp_responses() {
return $this->tp_responses;
}
/**
* @return string|null
*/
public function get_text_status() {
return $this->status->get_display_text();
}
/** @return array */
public function get_next_status() {
return $this->status->get_next_status();
}
/** @return bool */
public function is_pending() {
return $this->status->is_pending();
}
/**
* @return string
*/
public function get_document_flag_url() {
return $this->document_information->get_flag_url( $this->get_language_to() );
}
/**
* @return string
*/
public function get_source_document_flag_url() {
return $this->document_information->get_flag_url( $this->get_language_from() );
}
/**
* @return bool
*/
public function is_local_translation() {
return $this->document_information->is_local_translation( $this->get_job_id() );
}
/**
* @return string
*/
public function get_translator_name() {
return $this->document_information->get_translator_name( $this->get_job_id() );
}
/**
* @return array
*/
public function get_available_translators() {
return $this->document_information->get_available_translators( $this->language_from, $this->language_to );
}
/**
* @param WPML_TF_Backend_Document_Information $document_information
*/
public function set_document_information( WPML_TF_Backend_Document_Information $document_information ) {
$this->document_information = $document_information;
$this->document_information->init( $this->get_document_id(), $this->get_document_type() );
}
/** @return WPML_TF_Backend_Document_Information */
public function get_document_information() {
return $this->document_information;
}
}