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