1
|
|
|
<?php |
2
|
|
|
namespace Transmission\Model; |
3
|
|
|
|
4
|
|
|
use Transmission\Util\PropertyMapper; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* @author Ramon Kleiss <[email protected]> |
8
|
|
|
*/ |
9
|
|
|
class Torrent extends AbstractModel |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var integer |
13
|
|
|
*/ |
14
|
|
|
protected $id; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var integer |
18
|
|
|
*/ |
19
|
|
|
protected $eta; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var integer |
23
|
|
|
*/ |
24
|
|
|
protected $size; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $name; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
protected $hash; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var Status |
38
|
|
|
*/ |
39
|
|
|
protected $status; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var boolean |
43
|
|
|
*/ |
44
|
|
|
protected $finished; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var integer |
48
|
|
|
*/ |
49
|
|
|
protected $startDate; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var integer |
53
|
|
|
*/ |
54
|
|
|
protected $uploadRate; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var integer |
58
|
|
|
*/ |
59
|
|
|
protected $downloadRate; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @var integer |
63
|
|
|
*/ |
64
|
|
|
protected $peersConnected; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @var double |
68
|
|
|
*/ |
69
|
|
|
protected $percentDone; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @var array |
73
|
|
|
*/ |
74
|
|
|
protected $files = array(); |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @var array |
78
|
|
|
*/ |
79
|
|
|
protected $peers = array(); |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @var array |
83
|
|
|
*/ |
84
|
|
|
protected $trackers = array(); |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @var array |
88
|
|
|
*/ |
89
|
|
|
protected $trackerStats = array(); |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @var double |
93
|
|
|
*/ |
94
|
|
|
protected $uploadRatio; |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @var string |
98
|
|
|
*/ |
99
|
|
|
protected $downloadDir; |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @var integer |
103
|
|
|
*/ |
104
|
|
|
protected $downloadedEver; |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @var integer |
108
|
|
|
*/ |
109
|
|
|
protected $uploadedEver; |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @var double |
113
|
|
|
*/ |
114
|
|
|
protected $metadataPercentComplete; |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @param integer $id |
118
|
|
|
*/ |
119
|
|
|
public function setId($id) |
120
|
|
|
{ |
121
|
|
|
$this->id = (integer) $id; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @return integer |
126
|
|
|
*/ |
127
|
|
|
public function getId() |
128
|
|
|
{ |
129
|
|
|
return $this->id; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @param integer $eta |
134
|
|
|
*/ |
135
|
|
|
public function setEta($eta) |
136
|
|
|
{ |
137
|
|
|
$this->eta = (integer) $eta; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @return integer |
142
|
|
|
*/ |
143
|
|
|
public function getEta() |
144
|
|
|
{ |
145
|
|
|
return $this->eta; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @param integer $size |
150
|
|
|
*/ |
151
|
|
|
public function setSize($size) |
152
|
|
|
{ |
153
|
|
|
$this->size = (integer) $size; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @return integer |
158
|
|
|
*/ |
159
|
|
|
public function getSize() |
160
|
|
|
{ |
161
|
|
|
return $this->size; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @param string $name |
166
|
|
|
*/ |
167
|
|
|
public function setName($name) |
168
|
|
|
{ |
169
|
|
|
$this->name = (string) $name; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @return string |
174
|
|
|
*/ |
175
|
|
|
public function getName() |
176
|
|
|
{ |
177
|
|
|
return $this->name; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @param string $hash |
182
|
|
|
*/ |
183
|
|
|
public function setHash($hash) |
184
|
|
|
{ |
185
|
|
|
$this->hash = (string) $hash; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @return string |
190
|
|
|
*/ |
191
|
|
|
public function getHash() |
192
|
|
|
{ |
193
|
|
|
return $this->hash; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* @param integer|Status $status |
198
|
|
|
*/ |
199
|
|
|
public function setStatus($status) |
200
|
|
|
{ |
201
|
|
|
$this->status = new Status($status); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* @return integer |
206
|
|
|
*/ |
207
|
|
|
public function getStatus() |
208
|
|
|
{ |
209
|
|
|
return $this->status->getValue(); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* @param boolean $finished |
214
|
|
|
*/ |
215
|
|
|
public function setFinished($finished) |
216
|
|
|
{ |
217
|
|
|
$this->finished = (boolean) $finished; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* @return boolean |
222
|
|
|
*/ |
223
|
|
|
public function isFinished() |
224
|
|
|
{ |
225
|
|
|
return ($this->finished || (int) $this->getPercentDone() == 100); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* @var integer $startDate |
230
|
|
|
*/ |
231
|
|
|
public function setStartDate($startDate) |
232
|
|
|
{ |
233
|
|
|
$this->startDate = (integer) $startDate; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* @return integer |
238
|
|
|
*/ |
239
|
|
|
public function getStartDate() |
240
|
|
|
{ |
241
|
|
|
return $this->startDate; |
242
|
|
|
} |
243
|
|
|
/** |
244
|
|
|
* @var integer $rate |
245
|
|
|
*/ |
246
|
|
|
public function setUploadRate($rate) |
247
|
|
|
{ |
248
|
|
|
$this->uploadRate = (integer) $rate; |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* @return integer |
253
|
|
|
*/ |
254
|
|
|
public function getUploadRate() |
255
|
|
|
{ |
256
|
|
|
return $this->uploadRate; |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* @param integer $rate |
261
|
|
|
*/ |
262
|
|
|
public function setDownloadRate($rate) |
263
|
|
|
{ |
264
|
|
|
$this->downloadRate = (integer) $rate; |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
/** |
268
|
|
|
* @param integer $peersConnected |
269
|
|
|
*/ |
270
|
|
|
public function setPeersConnected($peersConnected) |
271
|
|
|
{ |
272
|
|
|
$this->peersConnected = (integer) $peersConnected; |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* @return integer |
277
|
|
|
*/ |
278
|
|
|
public function getPeersConnected() |
279
|
|
|
{ |
280
|
|
|
return $this->peersConnected; |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* @return integer |
285
|
|
|
*/ |
286
|
|
|
public function getDownloadRate() |
287
|
|
|
{ |
288
|
|
|
return $this->downloadRate; |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
/** |
292
|
|
|
* @param double $done |
293
|
|
|
*/ |
294
|
|
|
public function setPercentDone($done) |
295
|
|
|
{ |
296
|
|
|
$this->percentDone = (double) $done; |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
/** |
300
|
|
|
* @return double |
301
|
|
|
*/ |
302
|
|
|
public function getPercentDone() |
303
|
|
|
{ |
304
|
|
|
return $this->percentDone * 100.0; |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
/** |
308
|
|
|
* @param array $files |
309
|
|
|
*/ |
310
|
|
|
public function setFiles(array $files) |
311
|
|
|
{ |
312
|
|
|
$this->files = array_map(function ($file) { |
313
|
|
|
return PropertyMapper::map(new File(), $file); |
314
|
|
|
}, $files); |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
/** |
318
|
|
|
* @return array |
319
|
|
|
*/ |
320
|
|
|
public function getFiles() |
321
|
|
|
{ |
322
|
|
|
return $this->files; |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
/** |
326
|
|
|
* @param array $peers |
327
|
|
|
*/ |
328
|
|
|
public function setPeers(array $peers) |
329
|
|
|
{ |
330
|
|
|
$this->peers = array_map(function ($peer) { |
331
|
|
|
return PropertyMapper::map(new Peer(), $peer); |
332
|
|
|
}, $peers); |
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
/** |
336
|
|
|
* @return array |
337
|
|
|
*/ |
338
|
|
|
public function getPeers() |
339
|
|
|
{ |
340
|
|
|
return $this->peers; |
341
|
|
|
} |
342
|
|
|
/** |
343
|
|
|
* @param array $trackerStats |
344
|
|
|
*/ |
345
|
|
|
public function setTrackerStats(array $trackerStats) |
346
|
|
|
{ |
347
|
|
|
$this->trackerStats = array_map(function ($trackerStats) { |
348
|
|
|
return PropertyMapper::map(new TrackerStats(), $trackerStats); |
349
|
|
|
}, $trackerStats); |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
/** |
353
|
|
|
* @return array |
354
|
|
|
*/ |
355
|
|
|
public function getTrackerStats() |
356
|
|
|
{ |
357
|
|
|
return $this->trackerStats; |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
/** |
361
|
|
|
* @param array $trackers |
362
|
|
|
*/ |
363
|
|
|
public function setTrackers(array $trackers) |
364
|
|
|
{ |
365
|
|
|
$this->trackers = array_map(function ($tracker) { |
366
|
|
|
return PropertyMapper::map(new Tracker(), $tracker); |
367
|
|
|
}, $trackers); |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
/** |
371
|
|
|
* @return array |
372
|
|
|
*/ |
373
|
|
|
public function getTrackers() |
374
|
|
|
{ |
375
|
|
|
return $this->trackers; |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
/** |
379
|
|
|
* @param double $ratio |
380
|
|
|
*/ |
381
|
|
|
public function setUploadRatio($ratio) |
382
|
|
|
{ |
383
|
|
|
$this->uploadRatio = (double) $ratio; |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
/** |
387
|
|
|
* @return double |
388
|
|
|
*/ |
389
|
|
|
public function getUploadRatio() |
390
|
|
|
{ |
391
|
|
|
return $this->uploadRatio; |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
/** |
395
|
|
|
* @return boolean |
396
|
|
|
*/ |
397
|
|
|
public function isStopped() |
398
|
|
|
{ |
399
|
|
|
return $this->status->isStopped(); |
400
|
|
|
} |
401
|
|
|
|
402
|
|
|
/** |
403
|
|
|
* @return boolean |
404
|
|
|
*/ |
405
|
|
|
public function isChecking() |
406
|
|
|
{ |
407
|
|
|
return $this->status->isChecking(); |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
/** |
411
|
|
|
* @return boolean |
412
|
|
|
*/ |
413
|
|
|
public function isDownloading() |
414
|
|
|
{ |
415
|
|
|
return $this->status->isDownloading(); |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
/** |
419
|
|
|
* @return boolean |
420
|
|
|
*/ |
421
|
|
|
public function isSeeding() |
422
|
|
|
{ |
423
|
|
|
return $this->status->isSeeding(); |
424
|
|
|
} |
425
|
|
|
|
426
|
|
|
/** |
427
|
|
|
* @return string |
428
|
|
|
*/ |
429
|
|
|
public function getDownloadDir() |
430
|
|
|
{ |
431
|
|
|
return $this->downloadDir; |
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
/** |
435
|
|
|
* @param string $downloadDir |
436
|
|
|
*/ |
437
|
|
|
public function setDownloadDir($downloadDir) |
438
|
|
|
{ |
439
|
|
|
$this->downloadDir = $downloadDir; |
440
|
|
|
} |
441
|
|
|
|
442
|
|
|
/** |
443
|
|
|
* @return int |
444
|
|
|
*/ |
445
|
|
|
public function getDownloadedEver() { |
446
|
|
|
return $this->downloadedEver; |
447
|
|
|
} |
448
|
|
|
|
449
|
|
|
/** |
450
|
|
|
* @param int $downloadedEver |
451
|
|
|
*/ |
452
|
|
|
public function setDownloadedEver($downloadedEver) { |
453
|
|
|
$this->downloadedEver = $downloadedEver; |
454
|
|
|
} |
455
|
|
|
|
456
|
|
|
/** |
457
|
|
|
* @return int |
458
|
|
|
*/ |
459
|
|
|
public function getUploadedEver() { |
460
|
|
|
return $this->uploadedEver; |
461
|
|
|
} |
462
|
|
|
|
463
|
|
|
/** |
464
|
|
|
* @param int $uploadedEver |
465
|
|
|
*/ |
466
|
|
|
public function setUploadedEver($uploadedEver) { |
467
|
|
|
$this->uploadedEver = $uploadedEver; |
468
|
|
|
} |
469
|
|
|
|
470
|
|
|
/** |
471
|
|
|
* @return double |
472
|
|
|
*/ |
473
|
|
|
public function getMetadataPercentComplete() { |
474
|
|
|
return $this->metadataPercentComplete; |
475
|
|
|
} |
476
|
|
|
|
477
|
|
|
/** |
478
|
|
|
* @param double $metadataPercentComplete |
479
|
|
|
*/ |
480
|
|
|
public function setMetadataPercentComplete($metadataPercentComplete) { |
481
|
|
|
$this->metadataPercentComplete = $metadataPercentComplete; |
482
|
|
|
} |
483
|
|
|
|
484
|
|
|
/** |
485
|
|
|
* {@inheritDoc} |
486
|
|
|
*/ |
487
|
|
|
public static function getMapping() |
488
|
|
|
{ |
489
|
|
|
return array( |
490
|
|
|
'id' => 'id', |
491
|
|
|
'eta' => 'eta', |
492
|
|
|
'sizeWhenDone' => 'size', |
493
|
|
|
'name' => 'name', |
494
|
|
|
'status' => 'status', |
495
|
|
|
'isFinished' => 'finished', |
496
|
|
|
'rateUpload' => 'uploadRate', |
497
|
|
|
'rateDownload' => 'downloadRate', |
498
|
|
|
'percentDone' => 'percentDone', |
499
|
|
|
'metadataPercentComplete' => 'metadataPercentComplete', |
500
|
|
|
'files' => 'files', |
501
|
|
|
'peers' => 'peers', |
502
|
|
|
'peersConnected' => 'peersConnected', |
503
|
|
|
'trackers' => 'trackers', |
504
|
|
|
'trackerStats' => 'trackerStats', |
505
|
|
|
'startDate' => 'startDate', |
506
|
|
|
'uploadRatio' => 'uploadRatio', |
507
|
|
|
'hashString' => 'hash', |
508
|
|
|
'downloadDir' => 'downloadDir', |
509
|
|
|
'downloadedEver' => 'downloadedEver', |
510
|
|
|
'uploadedEver' => 'uploadedEver' |
511
|
|
|
); |
512
|
|
|
} |
513
|
|
|
} |
514
|
|
|
|