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 AnimeDb\Bundle\AppBundle\Service\Downloader\Entity\BaseEntity; |
15
|
|
|
use AnimeDb\Bundle\AppBundle\Service\Downloader\Entity\ImageInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Item images. |
19
|
|
|
* |
20
|
|
|
* @ORM\Entity |
21
|
|
|
* @ORM\Table(name="image") |
22
|
|
|
* |
23
|
|
|
* @author Peter Gribanov <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
class Image extends BaseEntity implements ImageInterface |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @ORM\Id |
29
|
|
|
* @ORM\GeneratedValue |
30
|
|
|
* @ORM\Column(type="integer") |
31
|
|
|
* |
32
|
|
|
* @var int |
33
|
|
|
*/ |
34
|
|
|
protected $id = 0; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @ORM\Column(type="string", length=256) |
38
|
|
|
* @Assert\NotBlank() |
39
|
|
|
* |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
protected $source = ''; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @ORM\ManyToOne(targetEntity="Item", inversedBy="images", cascade={"persist"}) |
46
|
|
|
* @ORM\JoinColumn(name="item", referencedColumnName="id") |
47
|
|
|
* |
48
|
|
|
* @var Item |
49
|
|
|
*/ |
50
|
|
|
protected $item; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return int |
54
|
|
|
*/ |
55
|
1 |
|
public function getId() |
56
|
|
|
{ |
57
|
1 |
|
return $this->id; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param string $source |
62
|
|
|
* |
63
|
|
|
* @return Image |
64
|
|
|
*/ |
65
|
2 |
|
public function setSource($source) |
66
|
|
|
{ |
67
|
2 |
|
$this->setFilename($source); |
68
|
|
|
|
69
|
2 |
|
return $this; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return string |
74
|
|
|
*/ |
75
|
2 |
|
public function getSource() |
76
|
|
|
{ |
77
|
2 |
|
return $this->getFilename(); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return string |
82
|
|
|
*/ |
83
|
3 |
|
public function getFilename() |
84
|
|
|
{ |
85
|
3 |
|
return $this->source ?: parent::getFilename(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @param string $filename |
90
|
|
|
* |
91
|
|
|
* @return Image |
92
|
|
|
*/ |
93
|
3 |
|
public function setFilename($filename) |
94
|
|
|
{ |
95
|
3 |
|
$this->source = $filename; |
96
|
3 |
|
parent::setFilename($filename); |
97
|
|
|
|
98
|
3 |
|
return $this; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param Item $item |
103
|
|
|
* |
104
|
|
|
* @return Image |
105
|
|
|
*/ |
106
|
1 |
|
public function setItem(Item $item = null) |
107
|
|
|
{ |
108
|
1 |
|
if ($this->item !== $item) { |
109
|
|
|
// romove link on this item for old item |
110
|
1 |
|
if ($this->item instanceof Item) { |
111
|
1 |
|
$tmp = $this->item; |
112
|
1 |
|
$this->item = null; |
113
|
1 |
|
$tmp->removeImage($this); |
114
|
1 |
|
} |
115
|
1 |
|
$this->item = $item; |
116
|
|
|
// add link on this item |
117
|
1 |
|
if ($item instanceof Item) { |
118
|
1 |
|
$this->item->addImage($this); |
119
|
1 |
|
} |
120
|
1 |
|
} |
121
|
|
|
|
122
|
1 |
|
return $this; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @return Item |
127
|
|
|
*/ |
128
|
1 |
|
public function getItem() |
129
|
|
|
{ |
130
|
1 |
|
return $this->item; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @return string |
135
|
|
|
*/ |
136
|
1 |
|
public function __toString() |
137
|
|
|
{ |
138
|
1 |
|
return $this->getSource(); |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|