Completed
Push — 0.4.27 ( ccec78...7bd732 )
by Peter
02:28
created

Item::getDateEnd()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 2
eloc 2
nc 2
nop 0
crap 2
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
namespace AnimeDb\Bundle\CatalogBundle\Entity;
10
11
use Doctrine\ORM\Mapping as ORM;
12
use Symfony\Component\Validator\Constraints as Assert;
13
use Doctrine\Common\Collections\ArrayCollection;
14
use Symfony\Component\Validator\ExecutionContextInterface;
15
use Doctrine\Bundle\DoctrineBundle\Registry;
16
use AnimeDb\Bundle\AppBundle\Service\Downloader\Entity\BaseEntity;
17
use AnimeDb\Bundle\AppBundle\Service\Downloader\Entity\ImageInterface;
18
19
/**
20
 * Item.
21
 *
22
 * @ORM\Entity
23
 * @ORM\Table(name="item")
24
 * @ORM\HasLifecycleCallbacks
25
 * @ORM\Entity(repositoryClass="AnimeDb\Bundle\CatalogBundle\Repository\Item")
26
 * @Assert\Callback(methods={"isPathValid"})
27
 *
28
 * @author  Peter Gribanov <[email protected]>
29
 */
30
class Item extends BaseEntity implements ImageInterface
31
{
32
    /**
33
     * @ORM\Id
34
     * @ORM\GeneratedValue
35
     * @ORM\Column(type="integer")
36
     *
37
     * @var int
38
     */
39
    protected $id = 0;
40
41
    /**
42
     * @ORM\Column(type="string", length=256)
43
     * @Assert\NotBlank()
44
     *
45
     * @var string
46
     */
47
    protected $name = '';
48
49
    /**
50
     * @ORM\OneToMany(targetEntity="Name", mappedBy="item", cascade={"persist", "remove"}, orphanRemoval=true)
51
     *
52
     * @var ArrayCollection
53
     */
54
    protected $names;
55
56
    /**
57
     * @ORM\ManyToOne(targetEntity="Type", inversedBy="items", cascade={"persist"})
58
     * @ORM\JoinColumn(name="type", referencedColumnName="id")
59
     *
60
     * @var Type
61
     */
62
    protected $type;
63
64
    /**
65
     * @ORM\Column(type="date")
66
     * @Assert\Date()
67
     *
68
     * @var \DateTime
69
     */
70
    protected $date_premiere;
71
72
    /**
73
     * @ORM\Column(type="date", nullable=true)
74
     * @Assert\Date()
75
     *
76
     * @var \DateTime|null
77
     */
78
    protected $date_end;
79
80
    /**
81
     * @ORM\ManyToMany(targetEntity="Genre", inversedBy="items", cascade={"persist"})
82
     * @ORM\JoinTable(name="items_genres")
83
     *
84
     * @var ArrayCollection
85
     */
86
    protected $genres;
87
88
    /**
89
     * @ORM\ManyToMany(targetEntity="Label", inversedBy="items", cascade={"persist"})
90
     * @ORM\JoinTable(name="items_labels")
91
     *
92
     * @var ArrayCollection
93
     */
94
    protected $labels;
95
96
    /**
97
     * @ORM\ManyToOne(targetEntity="Country", inversedBy="items", cascade={"persist"})
98
     * @ORM\JoinColumn(name="country", referencedColumnName="id")
99
     *
100
     * @var Country
101
     */
102
    protected $country;
103
104
    /**
105
     * @ORM\Column(type="integer", nullable=true)
106
     * @Assert\Type(type="integer", message="The value {{ value }} is not a valid {{ type }}.")
107
     *
108
     * @var int
109
     */
110
    protected $duration = 0;
111
112
    /**
113
     * @ORM\Column(type="text", nullable=true)
114
     *
115
     * @var string
116
     */
117
    protected $summary = '';
118
119
    /**
120
     * @ORM\Column(type="string", length=256, nullable=true)
121
     *
122
     * @var string
123
     */
124
    protected $path = '';
125
126
    /**
127
     * @ORM\ManyToOne(targetEntity="Storage", inversedBy="items", cascade={"persist"})
128
     * @ORM\JoinColumn(name="storage", referencedColumnName="id")
129
     *
130
     * @var Storage
131
     */
132
    protected $storage;
133
134
    /**
135
     * @ORM\Column(type="text", nullable=true)
136
     *
137
     * @var string
138
     */
139
    protected $episodes = '';
140
141
    /**
142
     * Translate (subtitles and voice).
143
     *
144
     * @ORM\Column(type="string", length=256, nullable=true)
145
     *
146
     * @var string
147
     */
148
    protected $translate = '';
149
150
    /**
151
     * @ORM\Column(type="text", nullable=true)
152
     *
153
     * @var string
154
     */
155
    protected $file_info = '';
156
157
    /**
158
     * @ORM\OneToMany(targetEntity="Source", mappedBy="item", cascade={"persist", "remove"}, orphanRemoval=true)
159
     *
160
     * @var ArrayCollection
161
     */
162
    protected $sources;
163
164
    /**
165
     * @ORM\Column(type="string", length=256, nullable=true)
166
     *
167
     * @var string
168
     */
169
    protected $cover = '';
170
171
    /**
172
     * Number of episodes.
173
     *
174
     * @ORM\Column(type="string", length=5, nullable=true)
175
     * @Assert\Regex(
176
     *     pattern="/^(\d{1,4}\+?)$/",
177
     *     message="The number of episodes should be a number and can contain a '+' to denote the continuation of production"
178
     * )
179
     *
180
     * @var string
181
     */
182
    protected $episodes_number = '';
183
184
    /**
185
     * @ORM\Column(type="datetime")
186
     *
187
     * @var \DateTime
188
     */
189
    protected $date_add;
190
191
    /**
192
     * @ORM\Column(type="datetime")
193
     *
194
     * @var \DateTime
195
     */
196
    protected $date_update;
197
198
    /**
199
     * @ORM\OneToMany(targetEntity="Image", mappedBy="item", cascade={"persist", "remove"}, orphanRemoval=true)
200
     *
201
     * @var ArrayCollection
202
     */
203
    protected $images;
204
205
    /**
206
     * @ORM\Column(type="integer", nullable=true)
207
     * @Assert\Type(type="integer", message="The value {{ value }} is not a valid {{ type }}.")
208
     *
209
     * @var int
210
     */
211
    protected $rating = 0;
212
213
    /**
214
     * @ORM\ManyToOne(targetEntity="Studio", inversedBy="items", cascade={"persist"})
215
     * @ORM\JoinColumn(name="studio", referencedColumnName="id")
216
     *
217
     * @var Studio
218
     */
219
    protected $studio;
220
221
    /**
222
     * @var string
223
     */
224
    protected $not_cleared_path = '';
225
226 118
    public function __construct()
227
    {
228 118
        $this->genres = new ArrayCollection();
229 118
        $this->labels = new ArrayCollection();
230 118
        $this->names = new ArrayCollection();
231 118
        $this->sources = new ArrayCollection();
232 118
        $this->images = new ArrayCollection();
233 118
        $this->date_add = new \DateTime();
234 118
        $this->date_update = new \DateTime();
235 118
    }
236
237
    /**
238
     * @return int
239
     */
240 1
    public function getId()
241
    {
242 1
        return $this->id;
243
    }
244
245
    /**
246
     * @param string $name
247
     *
248
     * @return Item
249
     */
250 7
    public function setName($name)
251
    {
252 7
        $this->name = $name;
253
254 7
        return $this;
255
    }
256
257
    /**
258
     * @return string
259
     */
260 2
    public function getName()
261
    {
262 2
        return $this->name;
263
    }
264
265
    /**
266
     * @param \DateTime|null $date_premiere
267
     *
268
     * @return Item
269
     */
270 1
    public function setDatePremiere(\DateTime $date_premiere = null)
271
    {
272 1
        $this->date_premiere = $date_premiere ? clone $date_premiere : $date_premiere;
273
274 1
        return $this;
275
    }
276
277
    /**
278
     * @return \DateTime
279
     */
280 1
    public function getDatePremiere()
281
    {
282 1
        return $this->date_premiere ? clone $this->date_premiere : null;
283
    }
284
285
    /**
286
     * @param \DateTime|null $date_end
287
     *
288
     * @return Item
289
     */
290 1
    public function setDateEnd(\DateTime $date_end = null)
291
    {
292 1
        $this->date_end = $date_end ? clone $date_end : null;
293
294 1
        return $this;
295
    }
296
297
    /**
298
     * @return \DateTime|null
299
     */
300 1
    public function getDateEnd()
301
    {
302 1
        return $this->date_end ? clone $this->date_end : null;
303
    }
304
305
    /**
306
     * @param int $duration
307
     *
308
     * @return Item
309
     */
310 1
    public function setDuration($duration)
311
    {
312 1
        $this->duration = $duration;
313
314 1
        return $this;
315
    }
316
317
    /**
318
     * @return int
319
     */
320 1
    public function getDuration()
321
    {
322 1
        return $this->duration;
323
    }
324
325
    /**
326
     * @param string $summary
327
     *
328
     * @return Item
329
     */
330 1
    public function setSummary($summary)
331
    {
332 1
        $this->summary = $summary;
333
334 1
        return $this;
335
    }
336
337
    /**
338
     * @return string
339
     */
340 1
    public function getSummary()
341
    {
342 1
        return $this->summary;
343
    }
344
345
    /**
346
     * @param string $path
347
     *
348
     * @return Item
349
     */
350 8
    public function setPath($path)
351
    {
352 8
        if ($path) {
353 4
            $this->not_cleared_path = $path;
354 4
            $this->doClearPath();
355
        } else {
356 4
            $this->path = '';
357
        }
358
359 8
        return $this;
360
    }
361
362
    /**
363
     * @return string
364
     */
365 6
    public function getPath()
366
    {
367
        // path not cleared
368 6
        if ($this->not_cleared_path) {
369 3
            return $this->not_cleared_path;
370
        }
371
        // use storage path as prefix
372 3
        if ($this->getStorage() instanceof Storage && $this->getStorage()->getPath()) {
373 1
            return $this->getStorage()->getPath().$this->path;
374
        }
375
376 2
        return $this->path;
377
    }
378
379
    /**
380
     * Get real path.
381
     *
382
     * Need for tests
383
     *
384
     * @return string
385
     */
386 4
    public function getRealPath()
387
    {
388 4
        return $this->path;
389
    }
390
391
    /**
392
     * @param string $episodes
393
     *
394
     * @return Item
395
     */
396 1
    public function setEpisodes($episodes)
397
    {
398 1
        $this->episodes = $episodes;
399
400 1
        return $this;
401
    }
402
403
    /**
404
     * @return string
405
     */
406 1
    public function getEpisodes()
407
    {
408 1
        return $this->episodes;
409
    }
410
411
    /**
412
     * @param string $translate
413
     *
414
     * @return Item
415
     */
416 1
    public function setTranslate($translate)
417
    {
418 1
        $this->translate = $translate;
419
420 1
        return $this;
421
    }
422
423
    /**
424
     * @return string
425
     */
426 1
    public function getTranslate()
427
    {
428 1
        return $this->translate;
429
    }
430
431
    /**
432
     * @param string $fileInfo
433
     *
434
     * @return Item
435
     */
436 1
    public function setFileInfo($fileInfo)
437
    {
438 1
        $this->file_info = $fileInfo;
439
440 1
        return $this;
441
    }
442
443
    /**
444
     * @return string
445
     */
446 1
    public function getFileInfo()
447
    {
448 1
        return $this->file_info;
449
    }
450
451
    /**
452
     * @param Name $name
453
     *
454
     * @return Item
455
     */
456 View Code Duplication
    public function addName(Name $name)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
457
    {
458
        $names = array_map('strval', $this->names->toArray());
459
        if (!in_array($name->getName(), $names)) {
460
            $this->names->add($name);
461
            $name->setItem($this);
462
        }
463
464
        return $this;
465
    }
466
467
    /**
468
     * @param Name $name
469
     *
470
     * @return Item
471
     */
472
    public function removeName(Name $name)
473
    {
474
        if ($this->names->contains($name)) {
475
            $this->names->removeElement($name);
476
            $name->setItem(null);
477
        }
478
479
        return $this;
480
    }
481
482
    /**
483
     * @return ArrayCollection
484
     */
485
    public function getNames()
486
    {
487
        return $this->names;
488
    }
489
490
    /**
491
     * @param Type $type
492
     *
493
     * @return Item
494
     */
495 2 View Code Duplication
    public function setType(Type $type = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
496
    {
497 2
        if ($this->type !== $type) {
498
            // romove link on this item for old type
499 2
            if ($this->type instanceof Type) {
500 1
                $tmp = $this->type;
501 1
                $this->type = null;
502 1
                $tmp->removeItem($this);
503
            }
504 2
            $this->type = $type;
505
            // add link on this item
506 2
            if ($this->type instanceof Type) {
507 2
                $this->type->addItem($this);
508
            }
509
        }
510
511 2
        return $this;
512
    }
513
514
    /**
515
     * @return Type
516
     */
517 2
    public function getType()
518
    {
519 2
        return $this->type;
520
    }
521
522
    /**
523
     * @param Genre $genre
524
     *
525
     * @return Item
526
     */
527 2
    public function addGenre(Genre $genre)
528
    {
529 2
        if (!$this->genres->contains($genre)) {
530 2
            $this->genres->add($genre);
531 2
            $genre->addItem($this);
532
        }
533
534 2
        return $this;
535
    }
536
537
    /**
538
     * @param Genre $genre
539
     *
540
     * @return Item
541
     */
542 1
    public function removeGenre(Genre $genre)
543
    {
544 1
        if ($this->genres->contains($genre)) {
545 1
            $this->genres->removeElement($genre);
546 1
            $genre->removeItem($this);
547
        }
548
549 1
        return $this;
550
    }
551
552
    /**
553
     * @return ArrayCollection
554
     */
555 2
    public function getGenres()
556
    {
557 2
        return $this->genres;
558
    }
559
560
    /**
561
     * @param Label $label
562
     *
563
     * @return Item
564
     */
565 1
    public function addLabel(Label $label)
566
    {
567 1
        if (!$this->labels->contains($label)) {
568 1
            $this->labels->add($label);
569 1
            $label->addItem($this);
570
        }
571
572 1
        return $this;
573
    }
574
575
    /**
576
     * @param Label $label
577
     *
578
     * @return Item
579
     */
580 1
    public function removeLabel(Label $label)
581
    {
582 1
        if ($this->labels->contains($label)) {
583 1
            $this->labels->removeElement($label);
584 1
            $label->removeItem($this);
585
        }
586
587 1
        return $this;
588
    }
589
590
    /**
591
     * @return ArrayCollection
592
     */
593 1
    public function getLabels()
594
    {
595 1
        return $this->labels;
596
    }
597
598
    /**
599
     * @param Country $country
600
     *
601
     * @return Item
602
     */
603 2 View Code Duplication
    public function setCountry(Country $country = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
604
    {
605 2
        if ($this->country !== $country) {
606
            // romove link on this item for old country
607 2
            if ($this->country instanceof Country) {
608 1
                $tmp = $this->country;
609 1
                $this->country = null;
610 1
                $tmp->removeItem($this);
611
            }
612 2
            $this->country = $country;
613
            // add link on this item
614 2
            if ($this->country instanceof Country) {
615 2
                $this->country->addItem($this);
616
            }
617
        }
618
619 2
        return $this;
620
    }
621
622
    /**
623
     * @return Country
624
     */
625 2
    public function getCountry()
626
    {
627 2
        return $this->country;
628
    }
629
630
    /**
631
     * @param Storage $storage
632
     *
633
     * @return Item
634
     */
635 7 View Code Duplication
    public function setStorage(Storage $storage = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
636
    {
637 7
        if ($this->storage !== $storage) {
638
            // romove link on this item for old storage
639 7
            if ($this->storage instanceof Storage) {
640 1
                $tmp = $this->storage;
641 1
                $this->storage = null;
642 1
                $tmp->removeItem($this);
643
            }
644 7
            $this->storage = $storage;
645
            // add link on this item
646 7
            if ($this->storage instanceof Storage) {
647 7
                $this->storage->addItem($this);
648
            }
649
        }
650 7
        $this->doClearPath();
651
652 7
        return $this;
653
    }
654
655
    /**
656
     * @return Storage
657
     */
658 10
    public function getStorage()
659
    {
660 10
        return $this->storage;
661
    }
662
663
    /**
664
     * @param string $cover
665
     *
666
     * @return Item
667
     */
668 1
    public function setCover($cover)
669
    {
670 1
        $this->setFilename($cover);
671
672 1
        return $this;
673
    }
674
675
    /**
676
     * @return string
677
     */
678 1
    public function getCover()
679
    {
680 1
        return $this->getFilename();
681
    }
682
683
    /**
684
     * @return string
685
     */
686 2
    public function getFilename()
687
    {
688 2
        return $this->cover ?: parent::getFilename();
689
    }
690
691
    /**
692
     * @param string $filename
693
     *
694
     * @return Item
695
     */
696 2
    public function setFilename($filename)
697
    {
698 2
        $this->cover = $filename;
699 2
        parent::setFilename($filename);
700
701 2
        return $this;
702
    }
703
704
    /**
705
     * @param Source $source
706
     *
707
     * @return Item
708
     */
709 View Code Duplication
    public function addSource(Source $source)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
710
    {
711
        $sources = array_map('strval', $this->sources->toArray());
712
        if (!in_array($source->getUrl(), $sources)) {
713
            $this->sources->add($source);
714
            $source->setItem($this);
715
        }
716
717
        return $this;
718
    }
719
720
    /**
721
     * @param Source $source
722
     *
723
     * @return Item
724
     */
725
    public function removeSource(Source $source)
726
    {
727
        if ($this->sources->contains($source)) {
728
            $this->sources->removeElement($source);
729
            $source->setItem(null);
730
        }
731
732
        return $this;
733
    }
734
735
    /**
736
     * @return ArrayCollection
737
     */
738
    public function getSources()
739
    {
740
        return $this->sources;
741
    }
742
743
    /**
744
     * @param Image $image
745
     *
746
     * @return Item
747
     */
748 View Code Duplication
    public function addImage(Image $image)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
749
    {
750
        $images = array_map('strval', $this->images->toArray());
751
        if (!in_array($image->getSource(), $images)) {
752
            $this->images->add($image);
753
            $image->setItem($this);
754
        }
755
756
        return $this;
757
    }
758
759
    /**
760
     * @param Image $image
761
     *
762
     * @return Item
763
     */
764
    public function removeImage(Image $image)
765
    {
766
        if ($this->images->contains($image)) {
767
            $this->images->removeElement($image);
768
            $image->setItem(null);
769
        }
770
771
        return $this;
772
    }
773
774
    /**
775
     * @return ArrayCollection
776
     */
777
    public function getImages()
778
    {
779
        return $this->images;
780
    }
781
782
    /**
783
     * @param string $episodes_number
784
     *
785
     * @return Item
786
     */
787 1
    public function setEpisodesNumber($episodes_number)
788
    {
789 1
        $this->episodes_number = $episodes_number;
790
791 1
        return $this;
792
    }
793
794
    /**
795
     * @return string
796
     */
797 1
    public function getEpisodesNumber()
798
    {
799 1
        return $this->episodes_number;
800
    }
801
802
    /**
803
     * @param \DateTime $date_add
804
     *
805
     * @return Item
806
     */
807 1
    public function setDateAdd(\DateTime $date_add)
808
    {
809 1
        $this->date_add = clone $date_add;
810
811 1
        return $this;
812
    }
813
814
    /**
815
     * @return \DateTime
816
     */
817 1
    public function getDateAdd()
818
    {
819 1
        return clone $this->date_add;
820
    }
821
822
    /**
823
     * @param \DateTime $date_update
824
     *
825
     * @return Item
826
     */
827 2
    public function setDateUpdate(\DateTime $date_update)
828
    {
829 2
        $this->date_update = clone $date_update;
830
831 2
        return $this;
832
    }
833
834
    /**
835
     * @return \DateTime
836
     */
837 2
    public function getDateUpdate()
838
    {
839 2
        return clone $this->date_update;
840
    }
841
842
    /**
843
     * @param int $rating
844
     *
845
     * @return Item
846
     */
847 1
    public function setRating($rating)
848
    {
849 1
        $this->rating = $rating;
850
851 1
        return $this;
852
    }
853
854
    /**
855
     * @return int
856
     */
857 1
    public function getRating()
858
    {
859 1
        return $this->rating;
860
    }
861
862
    /**
863
     * @param Studio $studio
864
     *
865
     * @return Item
866
     */
867 1 View Code Duplication
    public function setStudio(Studio $studio = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
868
    {
869 1
        if ($this->studio !== $studio) {
870
            // romove link on this item for old studio
871 1
            if ($this->studio instanceof Studio) {
872 1
                $tmp = $this->studio;
873 1
                $this->studio = null;
874 1
                $tmp->removeItem($this);
875
            }
876 1
            $this->studio = $studio;
877
            // add link on this item
878 1
            if ($this->studio instanceof Studio) {
879 1
                $this->studio->addItem($this);
880
            }
881
        }
882
883 1
        return $this;
884
    }
885
886
    /**
887
     * @return Studio
888
     */
889 1
    public function getStudio()
890
    {
891 1
        return $this->studio;
892
    }
893
894
    /**
895
     * @ORM\PreUpdate
896
     */
897 1
    public function doChangeDateUpdate()
898
    {
899 1
        $this->date_update = new \DateTime();
900 1
    }
901
902
    /**
903
     * Is valid path for current type.
904
     *
905
     * @param ExecutionContextInterface $context
906
     */
907 4
    public function isPathValid(ExecutionContextInterface $context)
908
    {
909 4
        if ($this->getStorage() instanceof Storage && $this->getStorage()->isPathRequired() && !$this->getPath()) {
910 1
            $context->addViolationAt('path', 'Path is required to fill for current type of storage');
0 ignored issues
show
Deprecated Code introduced by
The method Symfony\Component\Valida...rface::addViolationAt() has been deprecated with message: since version 2.5, to be removed in 3.0. Use {@link Context\ExecutionContextInterface::buildViolation()} instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
911
        }
912 4
    }
913
914
    /**
915
     * Freeze item.
916
     *
917
     * @param Registry $doctrine
918
     *
919
     * @return Item
920
     */
921 1
    public function freez(Registry $doctrine)
922
    {
923 1
        $em = $doctrine->getManager();
924
        // create reference to existing entity
925 1
        if ($this->country) {
926 1
            $this->country = $em->getReference(get_class($this->country), $this->country->getId());
927
        }
928 1
        if ($this->storage) {
929 1
            $this->storage = $em->getReference(get_class($this->storage), $this->storage->getId());
930
        }
931 1
        $this->type = $em->getReference(get_class($this->type), $this->type->getId());
932 1
        foreach ($this->genres as $key => $genre) {
933 1
            $this->genres[$key] = $em->getReference(get_class($genre), $genre->getId());
934
        }
935
936 1
        return $this;
937
    }
938
939
    /**
940
     * Remove storage path in item path.
941
     *
942
     * @ORM\PrePersist
943
     * @ORM\PreUpdate
944
     */
945 8
    public function doClearPath()
946
    {
947
        if (
948 8
            $this->not_cleared_path &&
949 8
            $this->getStorage() instanceof Storage &&
950 8
            $this->getStorage()->getPath() &&
951 8
            strpos($this->not_cleared_path, $this->getStorage()->getPath()) === 0
952
        ) {
953 1
            $this->path = substr($this->not_cleared_path, strlen($this->getStorage()->getPath()));
954 1
            $this->not_cleared_path = '';
955
        }
956 8
    }
957
958
    /**
959
     * Get item name for url.
960
     *
961
     * @return string
962
     */
963 5
    public function getUrlName()
964
    {
965 5
        return trim(preg_replace('/[\/\s:]+/', '_', $this->name), '_');
966
    }
967
968
    /**
969
     * @return string
970
     */
971 1
    public function __toString()
972
    {
973 1
        return $this->getName();
974
    }
975
}
976