|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the Amplexor\XConnect library |
|
4
|
|
|
* |
|
5
|
|
|
* @license http://opensource.org/licenses/MIT |
|
6
|
|
|
* @link https://github.com/amplexor-drupal/xconnect/ |
|
7
|
|
|
* @version 1.0.0 |
|
8
|
|
|
* @package Amplexor.XConnect |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Amplexor\XConnect; |
|
15
|
|
|
|
|
16
|
|
|
use Amplexor\XConnect\Request\Order; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Class representing a translation request. |
|
20
|
|
|
*/ |
|
21
|
|
|
class Request |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* The order that is part of the request. |
|
25
|
|
|
* |
|
26
|
|
|
* @var Order |
|
27
|
|
|
*/ |
|
28
|
|
|
private $order; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* The files that are part of the request. |
|
32
|
|
|
* |
|
33
|
|
|
* @var array |
|
34
|
|
|
*/ |
|
35
|
|
|
private $files = array(); |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* The content that is part of the request. |
|
39
|
|
|
* |
|
40
|
|
|
* @var array |
|
41
|
|
|
*/ |
|
42
|
|
|
private $content = array(); |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Create a new request by passing the configuration to it. |
|
47
|
|
|
* |
|
48
|
|
|
* @param string $sourceLanguage |
|
49
|
|
|
* The source language for the request. |
|
50
|
|
|
* @param array $config |
|
51
|
|
|
* The configuration for the request: |
|
52
|
|
|
* - clientId : The client ID to order the translations for. |
|
53
|
|
|
* - orderNamePrefix : The order gets by default the following name: |
|
54
|
|
|
* translation_order_<date as YmdHis><microseconds as 3 digits>. |
|
55
|
|
|
* You can override the "translation_order_" with your own prefix. |
|
56
|
|
|
* (optional). |
|
57
|
|
|
* - templateId : The translation template ID. (optional). |
|
58
|
|
|
* - dueDate : What is the deadline for the file(s) to be translated. |
|
59
|
|
|
* The deadline should be set in days from the moment the translation |
|
60
|
|
|
* is ordered. (optional, default 0). |
|
61
|
|
|
* - issuedBy : The email address of the, by the translation known, issuer |
|
62
|
|
|
* of the translation. |
|
63
|
|
|
* - isConfidential : Is the content for the translation confidential? |
|
64
|
|
|
* (optional, default false). |
|
65
|
|
|
* - needsConfirmation : Should there be a conformation send when the |
|
66
|
|
|
* translation is ready? (optional, default true). |
|
67
|
|
|
* - needsQuotation : Should a quotation be created and send before the |
|
68
|
|
|
* translation is performed? (optional, default false). |
|
69
|
|
|
*/ |
|
70
|
18 |
|
public function __construct($sourceLanguage, array $config) |
|
71
|
|
|
{ |
|
72
|
18 |
|
$this->order = new Order($sourceLanguage, $config); |
|
73
|
18 |
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Get the order object from the request. |
|
77
|
|
|
* |
|
78
|
|
|
* @return Order |
|
79
|
|
|
* The order object. |
|
80
|
|
|
*/ |
|
81
|
18 |
|
public function getOrder() |
|
82
|
|
|
{ |
|
83
|
18 |
|
return $this->order; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Add a translation target language for the request. |
|
88
|
|
|
* |
|
89
|
|
|
* @param string $language |
|
90
|
|
|
* The language to translate the request to. |
|
91
|
|
|
*/ |
|
92
|
3 |
|
public function addTargetLanguage($language) |
|
93
|
|
|
{ |
|
94
|
3 |
|
$this->order->addTargetLanguage($language); |
|
95
|
3 |
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Add a translation instruction. |
|
99
|
|
|
* |
|
100
|
|
|
* @param string $instruction |
|
101
|
|
|
* The instruction to add to the request. |
|
102
|
|
|
*/ |
|
103
|
3 |
|
public function addInstruction($instruction) |
|
104
|
|
|
{ |
|
105
|
3 |
|
$this->order->addInstruction($instruction); |
|
106
|
3 |
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Set the reference for the translation. |
|
110
|
|
|
* |
|
111
|
|
|
* @param string $reference |
|
112
|
|
|
* The client refenece to use in all communication about the request. |
|
113
|
|
|
*/ |
|
114
|
3 |
|
public function setReference($reference) |
|
115
|
|
|
{ |
|
116
|
3 |
|
$this->order->setReference($reference); |
|
117
|
3 |
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* Get the translation files that are part of the request. |
|
121
|
|
|
* |
|
122
|
|
|
* @return array |
|
123
|
|
|
* Array of 'filename.ext' => 'full/path/to/filename.ext' |
|
124
|
|
|
*/ |
|
125
|
3 |
|
public function getFiles() |
|
126
|
|
|
{ |
|
127
|
3 |
|
return $this->files; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Add a file path to a file that needs to be translated. |
|
132
|
|
|
* |
|
133
|
|
|
* @param string $filePath |
|
134
|
|
|
* A local file path to the file that needs to be included in the request. |
|
135
|
|
|
*/ |
|
136
|
3 |
|
public function addFile($filePath) |
|
137
|
|
|
{ |
|
138
|
3 |
|
$fileName = basename($filePath); |
|
139
|
3 |
|
$this->files[$fileName] = $filePath; |
|
140
|
3 |
|
$this->getOrder()->addFile($fileName); |
|
141
|
3 |
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* Get the translation files content thatt are part of the request. |
|
145
|
|
|
* |
|
146
|
|
|
* @return array |
|
147
|
|
|
* Array of 'filename.ext' => 'content string'. |
|
148
|
|
|
*/ |
|
149
|
3 |
|
public function getContent() |
|
150
|
|
|
{ |
|
151
|
3 |
|
return $this->content; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* Add content strings to the request by providing a filename and string. |
|
156
|
|
|
* |
|
157
|
|
|
* @param string $fileName |
|
158
|
|
|
* The file name to use to pass the content string. |
|
159
|
|
|
* @param string $content |
|
160
|
|
|
* The file content as a string. |
|
161
|
|
|
*/ |
|
162
|
3 |
|
public function addContent($fileName, $content) |
|
163
|
|
|
{ |
|
164
|
3 |
|
$this->content[$fileName] = $content; |
|
165
|
3 |
|
$this->getOrder()->addFile($fileName); |
|
166
|
3 |
|
} |
|
167
|
|
|
} |
|
168
|
|
|
|