class-wpml-editor-ui-job.php
2.46 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
<?php
class WPML_Editor_UI_Job {
private $fields = array();
protected $job_id;
private $job_type;
private $job_type_title;
private $title;
private $view_link;
private $source_lang;
private $target_lang;
private $translation_complete;
private $duplicate;
private $note = '';
function __construct(
$job_id,
$job_type,
$job_type_title,
$title,
$view_link,
$source_lang,
$target_lang,
$translation_complete,
$duplicate
) {
$this->job_id = $job_id;
$this->job_type = $job_type;
$this->job_type_title = $job_type_title;
$this->title = $title;
$this->view_link = $view_link;
$this->source_lang = $source_lang;
$this->target_lang = $target_lang;
$this->translation_complete = $translation_complete;
$this->duplicate = $duplicate;
}
public function add_field( $field ) {
$this->fields[] = $field;
}
public function add_note( $note ) {
$this->note = $note;
}
public function get_all_fields() {
$fields = array();
/** @var WPML_Editor_UI_Field $field */
foreach ( $this->fields as $field ) {
$child_fields = $field->get_fields();
/** @var WPML_Editor_UI_Field $child_field */
foreach ( $child_fields as $child_field ) {
$fields[] = $child_field;
}
}
return $fields;
}
public function get_layout_of_fields() {
$layout = array();
/** @var WPML_Editor_UI_Field $field */
foreach ( $this->fields as $field ) {
$layout[] = $field->get_layout();
}
return $layout;
}
public function get_target_language() {
return $this->target_lang;
}
public function is_translation_complete() {
return $this->translation_complete;
}
public function save( $data ) {
$translations = array();
foreach ( $data['fields'] as $id => $field ) {
$translations[ $this->convert_id_to_translation_key( $id ) ] = $field['data'];
}
try {
$this->save_translations( $translations );
return new WPML_Ajax_Response( true, true );
} catch ( Exception $e ) {
return new WPML_Ajax_Response( false, 0 );
}
}
private function convert_id_to_translation_key( $id ) {
// This is to support the old api for saving translations.
return md5( $id );
}
public function requires_translation_complete_for_each_field() {
return true;
}
public function display_hide_completed_switcher() {
return true;
}
public function is_hide_empty_fields() {
return true;
}
public function save_translations( $translations ) {
}
}