-
Notifications
You must be signed in to change notification settings - Fork 1
/
TextbrokerBudgetProofreading.php
314 lines (263 loc) · 12.8 KB
/
TextbrokerBudgetProofreading.php
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
<?php
// +---------------------------------------------------------------------------+
// | Copyright (c) 2012, Fabio Bacigalupo |
// | All rights reserved. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | o Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | o Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | o The names of the authors may not be used to endorse or promote |
// | products derived from this software without specific prior written |
// | permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
// | |
// +---------------------------------------------------------------------------+
// | textbroker-PHP5-Client 1.0 |
// +---------------------------------------------------------------------------+
// | TextbrokerBudgetProofreading.php |
// +---------------------------------------------------------------------------+
// | Authors: Fabio Bacigalupo <info1@open-haus.de> |
// +---------------------------------------------------------------------------+
require_once(dirname(__FILE__) . '/Textbroker.php');
/**
* BudgetProofreadingService
* Erstellung, Bearbeitung und Abnahme von Korrekturaufträgen
*
* Korrekturaufträge (im Folgenden BudgetProofreading genannt) können über jedes Budget erstellt werden, das aktiv und nicht im Test-Modus ist.
* BudgetProofreadings haben eine feste Bearbeitungszeit; die Kosten berechnen sich aus der Länge des zu prüfenden Textes,
* sodass keine nachträglichen Änderungen am Korrekturauftrag möglich oder notwendig sind.
* Einen Test-Modus gibt es für BudgetProofreadings nicht. BudgetProofreadings besitzen die gleichen Zustände wie andere BudgetOrders auch.
* Dieser Service ist nur für bereits angenommene Aufträge möglich.
*
* @package textbroker-PHP5-Client
* @author Fabio Bacigalupo <info1@open-haus.de>
*/
class TextbrokerBudgetProofreading extends Textbroker {
/**
* Singleton
*
* @return object
*/
public static function &singleton($budgetKey = null, $budgetId = null, $password = null, $location = self::BUDGET_LOCATION_DEFAULT) {
static $instance;
if (!isset($instance)) {
$class = __CLASS__;
$instance = new $class($budgetKey, $budgetId, $password, $location);
}
return $instance;
}
/**
*
*
* @param string $budgetKey
* @param string $budgetId
*/
function __construct($budgetKey = null, $budgetId = null, $password = null, $location = 'us') {
parent::__construct($budgetKey, $budgetId, $password, $location);
$this->setOptions(array(
'location' => $this->getUri() . 'budgetProofreadingService.php',
'uri' => $this->getUri(),
));
}
/**
* Rückgabe-Array:
* 'proofreading_id_created' – ID des erstellten BudgetProofreadings (int) ansonsten
* 'error' – Beschreibung des Fehlers, der die Erstellung verhindert hat (String)
*
* @param int $orderId - Die orderID bezeichnet in dieser Funktion die ID einer Budget-Order (OpenOrder), die korrigiert werden soll.
* @param string $instructions – Anweisung an den Lektor (String)
* @param string $text [optional] - der angepasste Text, wenn nicht mit dem Original gleich (String)
* @param string $title [optional] - (String) angepasster Titel, wenn nicht mit dem Original gleich
* @return array
* @throws TextbrokerBudgetProofreadingException
*/
public function create($orderId, $instructions = null, $text = null, $title = null) {
$result = $this->getClient()->create($this->salt, $this->hash, $this->budgetKey, $orderId, $instructions, $text, $title);
if (isset($result['error']) && !empty($result['error'])) {
throw new TextbrokerBudgetProofreadingException($result['error']);
}
return $result['proofreading_id_created'];
}
/**
* Liefert einen Array mit den wichtigsten Informationen
*
* Rückgabe-Array:
* word_count - die übermittelte Anzahl der Wörter
* cost_per_word - die Kosten pro Wort in der jeweiligen Einstufung
* cost_total - die Gesamtkosten für den Auftrag
* currency - die jeweilige Währung
*
* @param string $text Erwartet wird: der Text der zum Korrektorat gesendet werden soll
* @return array
* @throws TextbrokerBudgetProofreadingException
*/
public function getCosts($text) {
$result = $this->getClient()->getCosts($this->salt, $this->hash, $this->budgetKey, $text);
if (isset($result['error']) && !empty($result['error'])) {
throw new TextbrokerBudgetProofreadingException($result['error']);
}
return $result;
}
/**
* Verhält sich prinzipiell wie bei BudgetOrder auch. Der Unterschied besteht darin, dass der Text im Array-Element 'text' (aber nicht der Titel) die Unterschiede
* zwischen der ursprünglichen und der korrigierten Fassung aufzeigt. Es ist als HTML formatiert und sollte dem Benutzer angezeigt werden.
*
* @param int $orderId
* @return array
* @throws TextbrokerBudgetProofreadingException
*/
public function preview($orderId) {
$result = $this->getClient()->preview($this->salt, $this->hash, $this->budgetKey, $text);
if (isset($result['error']) && !empty($result['error'])) {
throw new TextbrokerBudgetProofreadingException($result['error']);
}
return $result;
}
/**
* Akzeptieren von fertiggestellten Proofreadings
*
* Bewertung – ein Integer zwischen 0 und 4, um zu akzeptieren.
* 0 = keine Bewertung abgeben, aber den Artikel annehmen.
* 1 = super
* 2 = gut
* 3 = geht so
* 4 = nicht so besonders
*
* Rückgabe-Array:
* result – "OK" wenn problemlos abgelaufen (String "OK")
* sandbox [optional] – wenn die Order im Textmodus betrieben wird = 1, sonst 0 (Integer)
* title [optional, falls OK] - der vom Autor vergebene Titel (String)
* text [optional, falls OK] - der Text (String)
* author – Autoren-Nickname (String)
* error [optional bei Fehlern] – die Fehlerbeschreibung (String)
*
* @param int $proofreadingId Proofreading-ID
* @param int $rating Bewertung – ein Integer zwischen 0 und 4, um zu akzeptieren.
* @param string $comment - Nachricht an den Autor – Ein Text mit Begründung der abgegebenen Bewertung (optional)
* @return array
*/
public function accept($proofreadingId, $rating = 0, $comment = null) {
$result = $this->getClient()->accept($this->salt, $this->hash, $this->budgetKey, $proofreadingId, $rating, $comment);
if (isset($result['error']) && !empty($result['error'])) {
throw new TextbrokerBudgetProofreadingException($result['error']);
}
return $result;
}
/**
* Den Bearbeitungsstatus des Auftrages abfragen
*
* Rückgabe-Array:
* budget_order_status – Kurze Beschreibung des Bearbeitungsstandes (String)
* budget_order_status_id – Zahl, die den Status beschreibt (vgl. BudgetOrder-Eigenschaften) (integer)
* budget_order_id – ID der BudgetOrder, die abgefragt wurde (integer)
* budget_order_created – Erstellungszeitpunkt des Auftrages als Unix Zeitstempel (integer)
* sandbox [optional] – wenn die Order im Textmodus betrieben wird = 1 (integer)
* error [optional bei Fehlern] – die Fehlerbeschreibung (String)
*
* @param int $proofreadingId Proofreading-ID
* @return array
*/
public function getStatus($proofreadingId) {
$result = $this->getClient()->getStatus($this->salt, $this->hash, $this->budgetKey, $proofreadingId);
if (isset($result['error']) && !empty($result['error'])) {
throw new TextbrokerBudgetProofreadingException($result['error']);
}
return $result;
}
/**
* Auflisten von Aufträgen, die den angegebenen Zustand haben
*
* Rückgabe-Array:
* ein Array aller Proofreading-IDs, die den Status erreicht haben. (Kann leer sein)
*
* @param int $status – numerischer Wert, der den abzufragenden Status identifiziert wie ACCEPTED = 5
* @return array
* @throws TextbrokerBudgetProofreadingException
*/
public function getOrdersByStatus($status) {
$result = $this->getClient()->getOrdersByStatus($this->salt, $this->hash, $this->budgetKey, $status);
if (isset($result['error']) && !empty($result['error'])) {
throw new TextbrokerBudgetProofreadingException($result['error']);
}
return $result;
}
/**
* Löschen von eingestellten Aufträgen vor ihrer Bearbeitung durch Autoren
*
* @param int $proofreadingId Proofreading-ID – die ID, die abgefragt werden soll.
* @return int proofreading_id_deleted – ID der gelöschten BudgetOrder (Integer)
* @throws TextbrokerBudgetProofreadingException
*/
public function delete($proofreadingId) {
$result = $this->getClient()->delete($this->salt, $this->hash, $this->budgetKey, $budgetOrderId);;
if (isset($result['error']) && !empty($result['error'])) {
throw new TextbrokerBudgetOrderException($result['error']);
}
return $result['proofreading_id_deleted'];
}
/**
*
*
* @param int $proofreadingId Proofreading-ID – die ID, die abgefragt werden soll.
* @return array
* @throws TextbrokerBudgetProofreadingException
*/
public function pickUp($proofreadingId) {
$result = $this->getClient()->pickUp($this->salt, $this->hash, $this->budgetKey, $proofreadingId);
if (isset($result['error']) && !empty($result['error'])) {
throw new TextbrokerBudgetProofreadingException($result['error']);
}
return $result;
}
/**
*
*
* @param int $proofreadingId Proofreading-ID – die ID, die abgefragt werden soll.
* @param string $comment
* @return array
* @throws TextbrokerBudgetProofreadingException
*/
public function revise($proofreadingId, $comment) {
$result = $this->getClient()->revise($this->salt, $this->hash, $this->budgetKey, $proofreadingId, $comment);
if (isset($result['error']) && !empty($result['error'])) {
throw new TextbrokerBudgetProofreadingException($result['error']);
}
return $result;
}
/**
*
*
* @param int $proofreadingId
* @return int
*/
public function reject($proofreadingId) {
$result = $this->getClient()->reject($this->salt, $this->hash, $this->budgetKey, $proofreadingId);
if (isset($result['error']) && !empty($result['error'])) {
throw new TextbrokerBudgetProofreadingException($result['error']);
}
return $result['proofreading_id_rejected'];
}
}
class TextbrokerBudgetProofreadingException extends TextbrokerException {
public function __construct($message, $code = 0) {
parent::__construct($message, $code);
}
}
?>