1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Entity; |
4
|
|
|
|
5
|
|
|
use DateTimeImmutable; |
6
|
|
|
use DateTimeInterface; |
7
|
|
|
use Doctrine\ORM\Mapping as ORM; |
8
|
|
|
use Exception; |
9
|
|
|
use Symfony\Component\HttpFoundation\File\File; |
10
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
11
|
|
|
use Vich\UploaderBundle\Mapping\Annotation as Vich; |
12
|
|
|
use Gedmo\Mapping\Annotation as Gedmo; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @ORM\Entity(repositoryClass="App\Repository\ImageRepository") |
16
|
|
|
* @Vich\Uploadable |
17
|
|
|
*/ |
18
|
|
|
class Image extends AbstractAppEntity |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @ORM\Id() |
23
|
|
|
* @ORM\GeneratedValue() |
24
|
|
|
* @ORM\Column(type="integer") |
25
|
|
|
*/ |
26
|
|
|
private $id; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @ORM\Column(type="string", length=255, nullable=false) |
30
|
|
|
* @Assert\Length( |
31
|
|
|
* min=5, |
32
|
|
|
* max=255, |
33
|
|
|
* minMessage = "Title must be at least {{ limit }} characters", |
34
|
|
|
* maxMessage = "Title can not exceed {{ limit }} characters" |
35
|
|
|
* ) |
36
|
|
|
*/ |
37
|
|
|
private $title; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @ORM\Column(type="string", length=255) |
41
|
|
|
*/ |
42
|
|
|
private $image; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @Assert\Image() |
46
|
|
|
* @Vich\UploadableField(mapping="trick_images", fileNameProperty="image") |
47
|
|
|
* @Assert\File(maxSize="2M") |
48
|
|
|
* @var File |
49
|
|
|
*/ |
50
|
|
|
private $imageFile; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @ORM\ManyToOne(targetEntity="App\Entity\Trick", inversedBy="images", cascade={"persist"}) |
54
|
|
|
* @ORM\JoinColumn(onDelete="CASCADE") |
55
|
|
|
*/ |
56
|
|
|
private $trick; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @ORM\Column(type="datetime") |
60
|
|
|
* @Gedmo\Timestampable(on="update") |
61
|
|
|
*/ |
62
|
|
|
private $updatedAt; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @ORM\Column(type="boolean") |
66
|
|
|
*/ |
67
|
|
|
private $primaryImage = false; |
68
|
|
|
|
69
|
|
|
public function getId(): ?int |
70
|
|
|
{ |
71
|
|
|
return $this->id; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function getTitle(): ?string |
75
|
|
|
{ |
76
|
|
|
return $this->title; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function setTitle(?string $title): self |
80
|
|
|
{ |
81
|
|
|
$this->title = $title; |
82
|
|
|
|
83
|
|
|
return $this; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function getImage(): ?string |
87
|
|
|
{ |
88
|
|
|
return $this->image; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function getWebImage(): ?string |
92
|
|
|
{ |
93
|
|
|
return '/uploads/trick_images/' . $this->image; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
public function setImage(?string $image): self |
98
|
|
|
{ |
99
|
|
|
$this->image = $image; |
100
|
|
|
|
101
|
|
|
return $this; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function getTrick(): ?Trick |
105
|
|
|
{ |
106
|
|
|
return $this->trick; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function setTrick(?Trick $trick): self |
110
|
|
|
{ |
111
|
|
|
$this->trick = $trick; |
112
|
|
|
|
113
|
|
|
return $this; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function getUpdatedAt(): ?DateTimeInterface |
117
|
|
|
{ |
118
|
|
|
return $this->updatedAt; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function setUpdatedAt(DateTimeInterface $updatedAt): self |
122
|
|
|
{ |
123
|
|
|
$this->updatedAt = $updatedAt; |
124
|
|
|
|
125
|
|
|
return $this; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @return null|File |
130
|
|
|
*/ |
131
|
|
|
public function getImageFile(): ?File |
132
|
|
|
{ |
133
|
|
|
return $this->imageFile; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @param File $imageFile |
138
|
|
|
* @return Image |
139
|
|
|
* @throws Exception |
140
|
|
|
*/ |
141
|
|
|
public function setImageFile(File $imageFile): Image |
142
|
|
|
{ |
143
|
|
|
$this->imageFile = $imageFile; |
144
|
|
|
$this->updatedAt = new DateTimeImmutable(); |
145
|
|
|
|
146
|
|
|
return $this; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
public function __toString() |
150
|
|
|
{ |
151
|
|
|
return $this->getTitle(); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function getPrimaryImage(): ?bool |
155
|
|
|
{ |
156
|
|
|
return $this->primaryImage; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
public function setPrimaryImage(bool $primaryImage): self |
160
|
|
|
{ |
161
|
|
|
$this->primaryImage = $primaryImage; |
162
|
|
|
|
163
|
|
|
return $this; |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|