1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* AnimeDb package. |
4
|
|
|
* |
5
|
|
|
* @author Peter Gribanov <[email protected]> |
6
|
|
|
* @copyright Copyright (c) 2011, Peter Gribanov |
7
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 GPL v3 |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace AnimeDb\Bundle\CatalogBundle\Entity; |
11
|
|
|
|
12
|
|
|
use Doctrine\ORM\Mapping as ORM; |
13
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
14
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
15
|
|
|
use Symfony\Component\Validator\ExecutionContextInterface; |
16
|
|
|
use Doctrine\Bundle\DoctrineBundle\Registry; |
17
|
|
|
use AnimeDb\Bundle\AppBundle\Service\Downloader\Entity\BaseEntity; |
18
|
|
|
use AnimeDb\Bundle\AppBundle\Service\Downloader\Entity\ImageInterface; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Item. |
22
|
|
|
* |
23
|
|
|
* @ORM\Entity |
24
|
|
|
* @ORM\Table(name="item") |
25
|
|
|
* @ORM\HasLifecycleCallbacks |
26
|
|
|
* @ORM\Entity(repositoryClass="AnimeDb\Bundle\CatalogBundle\Repository\Item") |
27
|
|
|
* @Assert\Callback(methods={"isPathValid"}) |
28
|
|
|
* |
29
|
|
|
* @author Peter Gribanov <[email protected]> |
30
|
|
|
*/ |
31
|
|
|
class Item extends BaseEntity implements ImageInterface |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* @ORM\Id |
35
|
|
|
* @ORM\GeneratedValue |
36
|
|
|
* @ORM\Column(type="integer") |
37
|
|
|
* |
38
|
|
|
* @var int |
39
|
|
|
*/ |
40
|
|
|
protected $id = 0; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @ORM\Column(type="string", length=256) |
44
|
|
|
* @Assert\NotBlank() |
45
|
|
|
* |
46
|
|
|
* @var string |
47
|
|
|
*/ |
48
|
|
|
protected $name = ''; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @ORM\OneToMany(targetEntity="Name", mappedBy="item", cascade={"persist", "remove"}, orphanRemoval=true) |
52
|
|
|
* |
53
|
|
|
* @var ArrayCollection |
54
|
|
|
*/ |
55
|
|
|
protected $names; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @ORM\ManyToOne(targetEntity="Type", inversedBy="items", cascade={"persist"}) |
59
|
|
|
* @ORM\JoinColumn(name="type", referencedColumnName="id") |
60
|
|
|
* |
61
|
|
|
* @var Type |
62
|
|
|
*/ |
63
|
|
|
protected $type; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @ORM\Column(type="date") |
67
|
|
|
* @Assert\Date() |
68
|
|
|
* |
69
|
|
|
* @var \DateTime |
70
|
|
|
*/ |
71
|
|
|
protected $date_premiere; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @ORM\Column(type="date", nullable=true) |
75
|
|
|
* @Assert\Date() |
76
|
|
|
* |
77
|
|
|
* @var \DateTime|null |
78
|
|
|
*/ |
79
|
|
|
protected $date_end; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @ORM\ManyToMany(targetEntity="Genre", inversedBy="items", cascade={"persist"}) |
83
|
|
|
* @ORM\JoinTable(name="items_genres") |
84
|
|
|
* |
85
|
|
|
* @var ArrayCollection |
86
|
|
|
*/ |
87
|
|
|
protected $genres; |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @ORM\ManyToMany(targetEntity="Label", inversedBy="items", cascade={"persist"}) |
91
|
|
|
* @ORM\JoinTable(name="items_labels") |
92
|
|
|
* |
93
|
|
|
* @var ArrayCollection |
94
|
|
|
*/ |
95
|
|
|
protected $labels; |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @ORM\ManyToOne(targetEntity="Country", inversedBy="items", cascade={"persist"}) |
99
|
|
|
* @ORM\JoinColumn(name="country", referencedColumnName="id") |
100
|
|
|
* |
101
|
|
|
* @var Country |
102
|
|
|
*/ |
103
|
|
|
protected $country; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @ORM\Column(type="integer", nullable=true) |
107
|
|
|
* @Assert\Type(type="integer", message="The value {{ value }} is not a valid {{ type }}.") |
108
|
|
|
* |
109
|
|
|
* @var int |
110
|
|
|
*/ |
111
|
|
|
protected $duration = 0; |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @ORM\Column(type="text", nullable=true) |
115
|
|
|
* |
116
|
|
|
* @var string |
117
|
|
|
*/ |
118
|
|
|
protected $summary = ''; |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @ORM\Column(type="string", length=256, nullable=true) |
122
|
|
|
* |
123
|
|
|
* @var string |
124
|
|
|
*/ |
125
|
|
|
protected $path = ''; |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @ORM\ManyToOne(targetEntity="Storage", inversedBy="items", cascade={"persist"}) |
129
|
|
|
* @ORM\JoinColumn(name="storage", referencedColumnName="id") |
130
|
|
|
* |
131
|
|
|
* @var Storage |
132
|
|
|
*/ |
133
|
|
|
protected $storage; |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @ORM\Column(type="text", nullable=true) |
137
|
|
|
* |
138
|
|
|
* @var string |
139
|
|
|
*/ |
140
|
|
|
protected $episodes = ''; |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Translate (subtitles and voice). |
144
|
|
|
* |
145
|
|
|
* @ORM\Column(type="string", length=256, nullable=true) |
146
|
|
|
* |
147
|
|
|
* @var string |
148
|
|
|
*/ |
149
|
|
|
protected $translate = ''; |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @ORM\Column(type="text", nullable=true) |
153
|
|
|
* |
154
|
|
|
* @var string |
155
|
|
|
*/ |
156
|
|
|
protected $file_info = ''; |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @ORM\OneToMany(targetEntity="Source", mappedBy="item", cascade={"persist", "remove"}, orphanRemoval=true) |
160
|
|
|
* |
161
|
|
|
* @var ArrayCollection |
162
|
|
|
*/ |
163
|
|
|
protected $sources; |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @ORM\Column(type="string", length=256, nullable=true) |
167
|
|
|
* |
168
|
|
|
* @var string |
169
|
|
|
*/ |
170
|
|
|
protected $cover = ''; |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* Number of episodes. |
174
|
|
|
* |
175
|
|
|
* @ORM\Column(type="string", length=5, nullable=true) |
176
|
|
|
* @Assert\Regex( |
177
|
|
|
* pattern="/^(\d{1,4}\+?)$/", |
178
|
|
|
* message="The number of episodes should be a number and can contain a '+' to denote the continuation of production" |
179
|
|
|
* ) |
180
|
|
|
* |
181
|
|
|
* @var string |
182
|
|
|
*/ |
183
|
|
|
protected $episodes_number = ''; |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @ORM\Column(type="datetime") |
187
|
|
|
* |
188
|
|
|
* @var \DateTime |
189
|
|
|
*/ |
190
|
|
|
protected $date_add; |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @ORM\Column(type="datetime") |
194
|
|
|
* |
195
|
|
|
* @var \DateTime |
196
|
|
|
*/ |
197
|
|
|
protected $date_update; |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @ORM\OneToMany(targetEntity="Image", mappedBy="item", cascade={"persist", "remove"}, orphanRemoval=true) |
201
|
|
|
* |
202
|
|
|
* @var ArrayCollection |
203
|
|
|
*/ |
204
|
|
|
protected $images; |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @ORM\Column(type="integer", nullable=true) |
208
|
|
|
* @Assert\Type(type="integer", message="The value {{ value }} is not a valid {{ type }}.") |
209
|
|
|
* |
210
|
|
|
* @var int |
211
|
|
|
*/ |
212
|
|
|
protected $rating = 0; |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @ORM\ManyToOne(targetEntity="Studio", inversedBy="items", cascade={"persist"}) |
216
|
|
|
* @ORM\JoinColumn(name="studio", referencedColumnName="id") |
217
|
|
|
* |
218
|
|
|
* @var Studio |
219
|
|
|
*/ |
220
|
|
|
protected $studio; |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* @var string |
224
|
|
|
*/ |
225
|
|
|
protected $not_cleared_path = ''; |
226
|
|
|
|
227
|
118 |
|
public function __construct() |
228
|
|
|
{ |
229
|
118 |
|
$this->genres = new ArrayCollection(); |
230
|
118 |
|
$this->labels = new ArrayCollection(); |
231
|
118 |
|
$this->names = new ArrayCollection(); |
232
|
118 |
|
$this->sources = new ArrayCollection(); |
233
|
118 |
|
$this->images = new ArrayCollection(); |
234
|
118 |
|
$this->date_add = new \DateTime(); |
235
|
118 |
|
$this->date_update = new \DateTime(); |
236
|
118 |
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @return int |
240
|
|
|
*/ |
241
|
1 |
|
public function getId() |
242
|
|
|
{ |
243
|
1 |
|
return $this->id; |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* @param string $name |
248
|
|
|
* |
249
|
|
|
* @return Item |
250
|
|
|
*/ |
251
|
7 |
|
public function setName($name) |
252
|
|
|
{ |
253
|
7 |
|
$this->name = $name; |
254
|
|
|
|
255
|
7 |
|
return $this; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* @return string |
260
|
|
|
*/ |
261
|
2 |
|
public function getName() |
262
|
|
|
{ |
263
|
2 |
|
return $this->name; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* @param \DateTime|null $date_premiere |
268
|
|
|
* |
269
|
|
|
* @return Item |
270
|
|
|
*/ |
271
|
1 |
|
public function setDatePremiere(\DateTime $date_premiere = null) |
272
|
|
|
{ |
273
|
1 |
|
$this->date_premiere = $date_premiere ? clone $date_premiere : $date_premiere; |
274
|
|
|
|
275
|
1 |
|
return $this; |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* @return \DateTime |
280
|
|
|
*/ |
281
|
1 |
|
public function getDatePremiere() |
282
|
|
|
{ |
283
|
1 |
|
return $this->date_premiere ? clone $this->date_premiere : null; |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* @param \DateTime|null $date_end |
288
|
|
|
* |
289
|
|
|
* @return Item |
290
|
|
|
*/ |
291
|
1 |
|
public function setDateEnd(\DateTime $date_end = null) |
292
|
|
|
{ |
293
|
1 |
|
$this->date_end = $date_end ? clone $date_end : null; |
294
|
|
|
|
295
|
1 |
|
return $this; |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* @return \DateTime|null |
300
|
|
|
*/ |
301
|
1 |
|
public function getDateEnd() |
302
|
|
|
{ |
303
|
1 |
|
return $this->date_end ? clone $this->date_end : null; |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* @param int $duration |
308
|
|
|
* |
309
|
|
|
* @return Item |
310
|
|
|
*/ |
311
|
1 |
|
public function setDuration($duration) |
312
|
|
|
{ |
313
|
1 |
|
$this->duration = $duration; |
314
|
|
|
|
315
|
1 |
|
return $this; |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
/** |
319
|
|
|
* @return int |
320
|
|
|
*/ |
321
|
1 |
|
public function getDuration() |
322
|
|
|
{ |
323
|
1 |
|
return $this->duration; |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
/** |
327
|
|
|
* @param string $summary |
328
|
|
|
* |
329
|
|
|
* @return Item |
330
|
|
|
*/ |
331
|
1 |
|
public function setSummary($summary) |
332
|
|
|
{ |
333
|
1 |
|
$this->summary = $summary; |
334
|
|
|
|
335
|
1 |
|
return $this; |
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
/** |
339
|
|
|
* @return string |
340
|
|
|
*/ |
341
|
1 |
|
public function getSummary() |
342
|
|
|
{ |
343
|
1 |
|
return $this->summary; |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
/** |
347
|
|
|
* @param string $path |
348
|
|
|
* |
349
|
|
|
* @return Item |
350
|
|
|
*/ |
351
|
8 |
|
public function setPath($path) |
352
|
|
|
{ |
353
|
8 |
|
if ($path) { |
354
|
4 |
|
$this->not_cleared_path = $path; |
355
|
4 |
|
$this->doClearPath(); |
356
|
4 |
|
} else { |
357
|
4 |
|
$this->path = ''; |
358
|
|
|
} |
359
|
|
|
|
360
|
8 |
|
return $this; |
361
|
|
|
} |
362
|
|
|
|
363
|
|
|
/** |
364
|
|
|
* @return string |
365
|
|
|
*/ |
366
|
6 |
|
public function getPath() |
367
|
|
|
{ |
368
|
|
|
// path not cleared |
369
|
6 |
|
if ($this->not_cleared_path) { |
370
|
3 |
|
return $this->not_cleared_path; |
371
|
|
|
} |
372
|
|
|
// use storage path as prefix |
373
|
3 |
|
if ($this->getStorage() instanceof Storage && $this->getStorage()->getPath()) { |
374
|
1 |
|
return $this->getStorage()->getPath().$this->path; |
375
|
|
|
} |
376
|
|
|
|
377
|
2 |
|
return $this->path; |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
/** |
381
|
|
|
* Get real path. |
382
|
|
|
* |
383
|
|
|
* Need for tests |
384
|
|
|
* |
385
|
|
|
* @return string |
386
|
|
|
*/ |
387
|
4 |
|
public function getRealPath() |
388
|
|
|
{ |
389
|
4 |
|
return $this->path; |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
/** |
393
|
|
|
* @param string $episodes |
394
|
|
|
* |
395
|
|
|
* @return Item |
396
|
|
|
*/ |
397
|
1 |
|
public function setEpisodes($episodes) |
398
|
|
|
{ |
399
|
1 |
|
$this->episodes = $episodes; |
400
|
|
|
|
401
|
1 |
|
return $this; |
402
|
|
|
} |
403
|
|
|
|
404
|
|
|
/** |
405
|
|
|
* @return string |
406
|
|
|
*/ |
407
|
1 |
|
public function getEpisodes() |
408
|
|
|
{ |
409
|
1 |
|
return $this->episodes; |
410
|
|
|
} |
411
|
|
|
|
412
|
|
|
/** |
413
|
|
|
* @param string $translate |
414
|
|
|
* |
415
|
|
|
* @return Item |
416
|
|
|
*/ |
417
|
1 |
|
public function setTranslate($translate) |
418
|
|
|
{ |
419
|
1 |
|
$this->translate = $translate; |
420
|
|
|
|
421
|
1 |
|
return $this; |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
/** |
425
|
|
|
* @return string |
426
|
|
|
*/ |
427
|
1 |
|
public function getTranslate() |
428
|
|
|
{ |
429
|
1 |
|
return $this->translate; |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
/** |
433
|
|
|
* @param string $fileInfo |
434
|
|
|
* |
435
|
|
|
* @return Item |
436
|
|
|
*/ |
437
|
1 |
|
public function setFileInfo($fileInfo) |
438
|
|
|
{ |
439
|
1 |
|
$this->file_info = $fileInfo; |
440
|
|
|
|
441
|
1 |
|
return $this; |
442
|
|
|
} |
443
|
|
|
|
444
|
|
|
/** |
445
|
|
|
* @return string |
446
|
|
|
*/ |
447
|
1 |
|
public function getFileInfo() |
448
|
|
|
{ |
449
|
1 |
|
return $this->file_info; |
450
|
|
|
} |
451
|
|
|
|
452
|
|
|
/** |
453
|
|
|
* @param Name $name |
454
|
|
|
* |
455
|
|
|
* @return Item |
456
|
|
|
*/ |
457
|
|
View Code Duplication |
public function addName(Name $name) |
|
|
|
|
458
|
|
|
{ |
459
|
|
|
$names = array_map('strval', $this->names->toArray()); |
460
|
|
|
if (!in_array($name->getName(), $names)) { |
461
|
|
|
$this->names->add($name); |
462
|
|
|
$name->setItem($this); |
463
|
|
|
} |
464
|
|
|
|
465
|
|
|
return $this; |
466
|
|
|
} |
467
|
|
|
|
468
|
|
|
/** |
469
|
|
|
* @param Name $name |
470
|
|
|
* |
471
|
|
|
* @return Item |
472
|
|
|
*/ |
473
|
|
|
public function removeName(Name $name) |
474
|
|
|
{ |
475
|
|
|
if ($this->names->contains($name)) { |
476
|
|
|
$this->names->removeElement($name); |
477
|
|
|
$name->setItem(null); |
478
|
|
|
} |
479
|
|
|
|
480
|
|
|
return $this; |
481
|
|
|
} |
482
|
|
|
|
483
|
|
|
/** |
484
|
|
|
* @return ArrayCollection |
485
|
|
|
*/ |
486
|
|
|
public function getNames() |
487
|
|
|
{ |
488
|
|
|
return $this->names; |
489
|
|
|
} |
490
|
|
|
|
491
|
|
|
/** |
492
|
|
|
* @param Type $type |
493
|
|
|
* |
494
|
|
|
* @return Item |
495
|
|
|
*/ |
496
|
2 |
View Code Duplication |
public function setType(Type $type = null) |
|
|
|
|
497
|
|
|
{ |
498
|
2 |
|
if ($this->type !== $type) { |
499
|
|
|
// romove link on this item for old type |
500
|
2 |
|
if ($this->type instanceof Type) { |
501
|
1 |
|
$tmp = $this->type; |
502
|
1 |
|
$this->type = null; |
503
|
1 |
|
$tmp->removeItem($this); |
504
|
1 |
|
} |
505
|
2 |
|
$this->type = $type; |
506
|
|
|
// add link on this item |
507
|
2 |
|
if ($this->type instanceof Type) { |
508
|
2 |
|
$this->type->addItem($this); |
509
|
2 |
|
} |
510
|
2 |
|
} |
511
|
|
|
|
512
|
2 |
|
return $this; |
513
|
|
|
} |
514
|
|
|
|
515
|
|
|
/** |
516
|
|
|
* @return Type |
517
|
|
|
*/ |
518
|
2 |
|
public function getType() |
519
|
|
|
{ |
520
|
2 |
|
return $this->type; |
521
|
|
|
} |
522
|
|
|
|
523
|
|
|
/** |
524
|
|
|
* @param Genre $genre |
525
|
|
|
* |
526
|
|
|
* @return Item |
527
|
|
|
*/ |
528
|
2 |
|
public function addGenre(Genre $genre) |
529
|
|
|
{ |
530
|
2 |
|
if (!$this->genres->contains($genre)) { |
531
|
2 |
|
$this->genres->add($genre); |
532
|
2 |
|
$genre->addItem($this); |
533
|
2 |
|
} |
534
|
|
|
|
535
|
2 |
|
return $this; |
536
|
|
|
} |
537
|
|
|
|
538
|
|
|
/** |
539
|
|
|
* @param Genre $genre |
540
|
|
|
* |
541
|
|
|
* @return Item |
542
|
|
|
*/ |
543
|
1 |
|
public function removeGenre(Genre $genre) |
544
|
|
|
{ |
545
|
1 |
|
if ($this->genres->contains($genre)) { |
546
|
1 |
|
$this->genres->removeElement($genre); |
547
|
1 |
|
$genre->removeItem($this); |
548
|
1 |
|
} |
549
|
|
|
|
550
|
1 |
|
return $this; |
551
|
|
|
} |
552
|
|
|
|
553
|
|
|
/** |
554
|
|
|
* @return ArrayCollection |
555
|
|
|
*/ |
556
|
2 |
|
public function getGenres() |
557
|
|
|
{ |
558
|
2 |
|
return $this->genres; |
559
|
|
|
} |
560
|
|
|
|
561
|
|
|
/** |
562
|
|
|
* @param Label $label |
563
|
|
|
* |
564
|
|
|
* @return Item |
565
|
|
|
*/ |
566
|
1 |
|
public function addLabel(Label $label) |
567
|
|
|
{ |
568
|
1 |
|
if (!$this->labels->contains($label)) { |
569
|
1 |
|
$this->labels->add($label); |
570
|
1 |
|
$label->addItem($this); |
571
|
1 |
|
} |
572
|
|
|
|
573
|
1 |
|
return $this; |
574
|
|
|
} |
575
|
|
|
|
576
|
|
|
/** |
577
|
|
|
* @param Label $label |
578
|
|
|
* |
579
|
|
|
* @return Item |
580
|
|
|
*/ |
581
|
1 |
|
public function removeLabel(Label $label) |
582
|
|
|
{ |
583
|
1 |
|
if ($this->labels->contains($label)) { |
584
|
1 |
|
$this->labels->removeElement($label); |
585
|
1 |
|
$label->removeItem($this); |
586
|
1 |
|
} |
587
|
|
|
|
588
|
1 |
|
return $this; |
589
|
|
|
} |
590
|
|
|
|
591
|
|
|
/** |
592
|
|
|
* @return ArrayCollection |
593
|
|
|
*/ |
594
|
1 |
|
public function getLabels() |
595
|
|
|
{ |
596
|
1 |
|
return $this->labels; |
597
|
|
|
} |
598
|
|
|
|
599
|
|
|
/** |
600
|
|
|
* @param Country $country |
601
|
|
|
* |
602
|
|
|
* @return Item |
603
|
|
|
*/ |
604
|
2 |
View Code Duplication |
public function setCountry(Country $country = null) |
|
|
|
|
605
|
|
|
{ |
606
|
2 |
|
if ($this->country !== $country) { |
607
|
|
|
// romove link on this item for old country |
608
|
2 |
|
if ($this->country instanceof Country) { |
609
|
1 |
|
$tmp = $this->country; |
610
|
1 |
|
$this->country = null; |
611
|
1 |
|
$tmp->removeItem($this); |
612
|
1 |
|
} |
613
|
2 |
|
$this->country = $country; |
614
|
|
|
// add link on this item |
615
|
2 |
|
if ($this->country instanceof Country) { |
616
|
2 |
|
$this->country->addItem($this); |
617
|
2 |
|
} |
618
|
2 |
|
} |
619
|
|
|
|
620
|
2 |
|
return $this; |
621
|
|
|
} |
622
|
|
|
|
623
|
|
|
/** |
624
|
|
|
* @return Country |
625
|
|
|
*/ |
626
|
2 |
|
public function getCountry() |
627
|
|
|
{ |
628
|
2 |
|
return $this->country; |
629
|
|
|
} |
630
|
|
|
|
631
|
|
|
/** |
632
|
|
|
* @param Storage $storage |
633
|
|
|
* |
634
|
|
|
* @return Item |
635
|
|
|
*/ |
636
|
7 |
View Code Duplication |
public function setStorage(Storage $storage = null) |
|
|
|
|
637
|
|
|
{ |
638
|
7 |
|
if ($this->storage !== $storage) { |
639
|
|
|
// romove link on this item for old storage |
640
|
7 |
|
if ($this->storage instanceof Storage) { |
641
|
1 |
|
$tmp = $this->storage; |
642
|
1 |
|
$this->storage = null; |
643
|
1 |
|
$tmp->removeItem($this); |
644
|
1 |
|
} |
645
|
7 |
|
$this->storage = $storage; |
646
|
|
|
// add link on this item |
647
|
7 |
|
if ($this->storage instanceof Storage) { |
648
|
7 |
|
$this->storage->addItem($this); |
649
|
7 |
|
} |
650
|
7 |
|
} |
651
|
7 |
|
$this->doClearPath(); |
652
|
|
|
|
653
|
7 |
|
return $this; |
654
|
|
|
} |
655
|
|
|
|
656
|
|
|
/** |
657
|
|
|
* @return Storage |
658
|
|
|
*/ |
659
|
10 |
|
public function getStorage() |
660
|
|
|
{ |
661
|
10 |
|
return $this->storage; |
662
|
|
|
} |
663
|
|
|
|
664
|
|
|
/** |
665
|
|
|
* @param string $cover |
666
|
|
|
* |
667
|
|
|
* @return Item |
668
|
|
|
*/ |
669
|
1 |
|
public function setCover($cover) |
670
|
|
|
{ |
671
|
1 |
|
$this->setFilename($cover); |
672
|
|
|
|
673
|
1 |
|
return $this; |
674
|
|
|
} |
675
|
|
|
|
676
|
|
|
/** |
677
|
|
|
* @return string |
678
|
|
|
*/ |
679
|
1 |
|
public function getCover() |
680
|
|
|
{ |
681
|
1 |
|
return $this->getFilename(); |
682
|
|
|
} |
683
|
|
|
|
684
|
|
|
/** |
685
|
|
|
* @return string |
686
|
|
|
*/ |
687
|
2 |
|
public function getFilename() |
688
|
|
|
{ |
689
|
2 |
|
return $this->cover ?: parent::getFilename(); |
690
|
|
|
} |
691
|
|
|
|
692
|
|
|
/** |
693
|
|
|
* @param string $filename |
694
|
|
|
* |
695
|
|
|
* @return Item |
696
|
|
|
*/ |
697
|
2 |
|
public function setFilename($filename) |
698
|
|
|
{ |
699
|
2 |
|
$this->cover = $filename; |
700
|
2 |
|
parent::setFilename($filename); |
701
|
|
|
|
702
|
2 |
|
return $this; |
703
|
|
|
} |
704
|
|
|
|
705
|
|
|
/** |
706
|
|
|
* @param Source $source |
707
|
|
|
* |
708
|
|
|
* @return Item |
709
|
|
|
*/ |
710
|
|
View Code Duplication |
public function addSource(Source $source) |
|
|
|
|
711
|
|
|
{ |
712
|
|
|
$sources = array_map('strval', $this->sources->toArray()); |
713
|
|
|
if (!in_array($source->getUrl(), $sources)) { |
714
|
|
|
$this->sources->add($source); |
715
|
|
|
$source->setItem($this); |
716
|
|
|
} |
717
|
|
|
|
718
|
|
|
return $this; |
719
|
|
|
} |
720
|
|
|
|
721
|
|
|
/** |
722
|
|
|
* @param Source $source |
723
|
|
|
* |
724
|
|
|
* @return Item |
725
|
|
|
*/ |
726
|
|
|
public function removeSource(Source $source) |
727
|
|
|
{ |
728
|
|
|
if ($this->sources->contains($source)) { |
729
|
|
|
$this->sources->removeElement($source); |
730
|
|
|
$source->setItem(null); |
731
|
|
|
} |
732
|
|
|
|
733
|
|
|
return $this; |
734
|
|
|
} |
735
|
|
|
|
736
|
|
|
/** |
737
|
|
|
* @return ArrayCollection |
738
|
|
|
*/ |
739
|
|
|
public function getSources() |
740
|
|
|
{ |
741
|
|
|
return $this->sources; |
742
|
|
|
} |
743
|
|
|
|
744
|
|
|
/** |
745
|
|
|
* @param Image $image |
746
|
|
|
* |
747
|
|
|
* @return Item |
748
|
|
|
*/ |
749
|
|
View Code Duplication |
public function addImage(Image $image) |
|
|
|
|
750
|
|
|
{ |
751
|
|
|
$images = array_map('strval', $this->images->toArray()); |
752
|
|
|
if (!in_array($image->getSource(), $images)) { |
753
|
|
|
$this->images->add($image); |
754
|
|
|
$image->setItem($this); |
755
|
|
|
} |
756
|
|
|
|
757
|
|
|
return $this; |
758
|
|
|
} |
759
|
|
|
|
760
|
|
|
/** |
761
|
|
|
* @param Image $image |
762
|
|
|
* |
763
|
|
|
* @return Item |
764
|
|
|
*/ |
765
|
|
|
public function removeImage(Image $image) |
766
|
|
|
{ |
767
|
|
|
if ($this->images->contains($image)) { |
768
|
|
|
$this->images->removeElement($image); |
769
|
|
|
$image->setItem(null); |
770
|
|
|
} |
771
|
|
|
|
772
|
|
|
return $this; |
773
|
|
|
} |
774
|
|
|
|
775
|
|
|
/** |
776
|
|
|
* @return ArrayCollection |
777
|
|
|
*/ |
778
|
|
|
public function getImages() |
779
|
|
|
{ |
780
|
|
|
return $this->images; |
781
|
|
|
} |
782
|
|
|
|
783
|
|
|
/** |
784
|
|
|
* @param string $episodes_number |
785
|
|
|
* |
786
|
|
|
* @return Item |
787
|
|
|
*/ |
788
|
1 |
|
public function setEpisodesNumber($episodes_number) |
789
|
|
|
{ |
790
|
1 |
|
$this->episodes_number = $episodes_number; |
791
|
|
|
|
792
|
1 |
|
return $this; |
793
|
|
|
} |
794
|
|
|
|
795
|
|
|
/** |
796
|
|
|
* @return string |
797
|
|
|
*/ |
798
|
1 |
|
public function getEpisodesNumber() |
799
|
|
|
{ |
800
|
1 |
|
return $this->episodes_number; |
801
|
|
|
} |
802
|
|
|
|
803
|
|
|
/** |
804
|
|
|
* @param \DateTime $date_add |
805
|
|
|
* |
806
|
|
|
* @return Item |
807
|
|
|
*/ |
808
|
1 |
|
public function setDateAdd(\DateTime $date_add) |
809
|
|
|
{ |
810
|
1 |
|
$this->date_add = clone $date_add; |
811
|
|
|
|
812
|
1 |
|
return $this; |
813
|
|
|
} |
814
|
|
|
|
815
|
|
|
/** |
816
|
|
|
* @return \DateTime |
817
|
|
|
*/ |
818
|
1 |
|
public function getDateAdd() |
819
|
|
|
{ |
820
|
1 |
|
return clone $this->date_add; |
821
|
|
|
} |
822
|
|
|
|
823
|
|
|
/** |
824
|
|
|
* @param \DateTime $date_update |
825
|
|
|
* |
826
|
|
|
* @return Item |
827
|
|
|
*/ |
828
|
2 |
|
public function setDateUpdate(\DateTime $date_update) |
829
|
|
|
{ |
830
|
2 |
|
$this->date_update = clone $date_update; |
831
|
|
|
|
832
|
2 |
|
return $this; |
833
|
|
|
} |
834
|
|
|
|
835
|
|
|
/** |
836
|
|
|
* @return \DateTime |
837
|
|
|
*/ |
838
|
2 |
|
public function getDateUpdate() |
839
|
|
|
{ |
840
|
2 |
|
return clone $this->date_update; |
841
|
|
|
} |
842
|
|
|
|
843
|
|
|
/** |
844
|
|
|
* @param int $rating |
845
|
|
|
* |
846
|
|
|
* @return Item |
847
|
|
|
*/ |
848
|
1 |
|
public function setRating($rating) |
849
|
|
|
{ |
850
|
1 |
|
$this->rating = $rating; |
851
|
|
|
|
852
|
1 |
|
return $this; |
853
|
|
|
} |
854
|
|
|
|
855
|
|
|
/** |
856
|
|
|
* @return int |
857
|
|
|
*/ |
858
|
1 |
|
public function getRating() |
859
|
|
|
{ |
860
|
1 |
|
return $this->rating; |
861
|
|
|
} |
862
|
|
|
|
863
|
|
|
/** |
864
|
|
|
* @param Studio $studio |
865
|
|
|
* |
866
|
|
|
* @return Item |
867
|
|
|
*/ |
868
|
1 |
View Code Duplication |
public function setStudio(Studio $studio = null) |
|
|
|
|
869
|
|
|
{ |
870
|
1 |
|
if ($this->studio !== $studio) { |
871
|
|
|
// romove link on this item for old studio |
872
|
1 |
|
if ($this->studio instanceof Studio) { |
873
|
1 |
|
$tmp = $this->studio; |
874
|
1 |
|
$this->studio = null; |
875
|
1 |
|
$tmp->removeItem($this); |
876
|
1 |
|
} |
877
|
1 |
|
$this->studio = $studio; |
878
|
|
|
// add link on this item |
879
|
1 |
|
if ($this->studio instanceof Studio) { |
880
|
1 |
|
$this->studio->addItem($this); |
881
|
1 |
|
} |
882
|
1 |
|
} |
883
|
|
|
|
884
|
1 |
|
return $this; |
885
|
|
|
} |
886
|
|
|
|
887
|
|
|
/** |
888
|
|
|
* @return Studio |
889
|
|
|
*/ |
890
|
1 |
|
public function getStudio() |
891
|
|
|
{ |
892
|
1 |
|
return $this->studio; |
893
|
|
|
} |
894
|
|
|
|
895
|
|
|
/** |
896
|
|
|
* @ORM\PreUpdate |
897
|
|
|
*/ |
898
|
1 |
|
public function doChangeDateUpdate() |
899
|
|
|
{ |
900
|
1 |
|
$this->date_update = new \DateTime(); |
901
|
1 |
|
} |
902
|
|
|
|
903
|
|
|
/** |
904
|
|
|
* Is valid path for current type. |
905
|
|
|
* |
906
|
|
|
* @param ExecutionContextInterface $context |
907
|
|
|
*/ |
908
|
4 |
|
public function isPathValid(ExecutionContextInterface $context) |
909
|
|
|
{ |
910
|
4 |
|
if ($this->getStorage() instanceof Storage && $this->getStorage()->isPathRequired() && !$this->getPath()) { |
911
|
1 |
|
$context->addViolationAt('path', 'Path is required to fill for current type of storage'); |
|
|
|
|
912
|
1 |
|
} |
913
|
4 |
|
} |
914
|
|
|
|
915
|
|
|
/** |
916
|
|
|
* Freeze item. |
917
|
|
|
* |
918
|
|
|
* @param Registry $doctrine |
919
|
|
|
* |
920
|
|
|
* @return Item |
921
|
|
|
*/ |
922
|
1 |
|
public function freez(Registry $doctrine) |
923
|
|
|
{ |
924
|
1 |
|
$em = $doctrine->getManager(); |
925
|
|
|
// create reference to existing entity |
926
|
1 |
|
if ($this->country) { |
927
|
1 |
|
$this->country = $em->getReference(get_class($this->country), $this->country->getId()); |
928
|
1 |
|
} |
929
|
1 |
|
if ($this->storage) { |
930
|
1 |
|
$this->storage = $em->getReference(get_class($this->storage), $this->storage->getId()); |
931
|
1 |
|
} |
932
|
1 |
|
$this->type = $em->getReference(get_class($this->type), $this->type->getId()); |
933
|
1 |
|
foreach ($this->genres as $key => $genre) { |
934
|
1 |
|
$this->genres[$key] = $em->getReference(get_class($genre), $genre->getId()); |
935
|
1 |
|
} |
936
|
|
|
|
937
|
1 |
|
return $this; |
938
|
|
|
} |
939
|
|
|
|
940
|
|
|
/** |
941
|
|
|
* Remove storage path in item path. |
942
|
|
|
* |
943
|
|
|
* @ORM\PrePersist |
944
|
|
|
* @ORM\PreUpdate |
945
|
|
|
*/ |
946
|
8 |
|
public function doClearPath() |
947
|
|
|
{ |
948
|
|
|
if ( |
949
|
8 |
|
$this->not_cleared_path && |
950
|
8 |
|
$this->getStorage() instanceof Storage && |
951
|
8 |
|
$this->getStorage()->getPath() && |
952
|
2 |
|
strpos($this->not_cleared_path, $this->getStorage()->getPath()) === 0 |
953
|
8 |
|
) { |
954
|
1 |
|
$this->path = substr($this->not_cleared_path, strlen($this->getStorage()->getPath())); |
955
|
1 |
|
$this->not_cleared_path = ''; |
956
|
1 |
|
} |
957
|
8 |
|
} |
958
|
|
|
|
959
|
|
|
/** |
960
|
|
|
* Get item name for url. |
961
|
|
|
* |
962
|
|
|
* @return string |
963
|
|
|
*/ |
964
|
5 |
|
public function getUrlName() |
965
|
|
|
{ |
966
|
5 |
|
return trim(preg_replace('/[\/\s:]+/', '_', $this->name), '_'); |
967
|
|
|
} |
968
|
|
|
|
969
|
|
|
/** |
970
|
|
|
* @return string |
971
|
|
|
*/ |
972
|
1 |
|
public function __toString() |
973
|
|
|
{ |
974
|
1 |
|
return $this->getName(); |
975
|
|
|
} |
976
|
|
|
} |
977
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.