|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AppBundle\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use AppBundle\Entity\Infrasctucture\CreatorLoginTrait; |
|
6
|
|
|
use AppBundle\Service\HashGenerator; |
|
7
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
8
|
|
|
use Doctrine\Common\Collections\Criteria; |
|
9
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
10
|
|
|
use Doctrine\ORM\PersistentCollection; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @ORM\Table(name="events", uniqueConstraints={@ORM\UniqueConstraint(name="unique_events_date_name", columns={"date", "name"})}) |
|
14
|
|
|
* @ORM\Entity(repositoryClass="AppBundle\Entity\Repository\EventRepository") |
|
15
|
|
|
* @author Vehsamrak |
|
16
|
|
|
*/ |
|
17
|
|
|
class Event |
|
18
|
|
|
{ |
|
19
|
|
|
|
|
20
|
|
|
use CreatorLoginTrait; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var string |
|
24
|
|
|
* @ORM\Column(name="id", type="string", length=8) |
|
25
|
|
|
* @ORM\Id |
|
26
|
|
|
*/ |
|
27
|
|
|
private $id; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var \DateTime |
|
31
|
|
|
* @ORM\Column(name="date", type="datetime") |
|
32
|
|
|
*/ |
|
33
|
|
|
private $date; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var string |
|
37
|
|
|
* @ORM\Column(name="name", type="string", length=255) |
|
38
|
|
|
*/ |
|
39
|
|
|
private $name; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var string |
|
43
|
|
|
* @ORM\Column(name="description", type="text") |
|
44
|
|
|
*/ |
|
45
|
|
|
private $description; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var string |
|
49
|
|
|
* @ORM\Column(name="place", type="text") |
|
50
|
|
|
*/ |
|
51
|
|
|
private $place; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @var User |
|
55
|
|
|
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\User", inversedBy="events") |
|
56
|
|
|
* @ORM\JoinColumn(name="creator", referencedColumnName="login") |
|
57
|
|
|
*/ |
|
58
|
|
|
private $creator; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @var Image[]|ArrayCollection |
|
62
|
|
|
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\Image") |
|
63
|
|
|
* @ORM\JoinTable(name="event_images", |
|
64
|
|
|
* joinColumns={@ORM\JoinColumn(name="event_id", referencedColumnName="id")}, |
|
65
|
|
|
* inverseJoinColumns={@ORM\JoinColumn(name="image_name", referencedColumnName="name", unique=true, onDelete="CASCADE")} |
|
66
|
|
|
* ) |
|
67
|
|
|
*/ |
|
68
|
|
|
private $images; |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @var Link[]|ArrayCollection |
|
72
|
|
|
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\Link") |
|
73
|
|
|
* @ORM\JoinTable(name="event_links", |
|
74
|
2 |
|
* joinColumns={@ORM\JoinColumn(name="event_id", referencedColumnName="id")}, |
|
75
|
|
|
* inverseJoinColumns={@ORM\JoinColumn(name="link_id", referencedColumnName="id", unique=true, onDelete="CASCADE")} |
|
76
|
|
|
* ) |
|
77
|
|
|
*/ |
|
78
|
|
|
private $links; |
|
79
|
|
|
|
|
80
|
|
|
public function __construct( |
|
81
|
|
|
string $name, |
|
82
|
2 |
|
User $creator, |
|
83
|
2 |
|
\DateTime $date, |
|
84
|
2 |
|
string $description, |
|
85
|
2 |
|
string $place, |
|
86
|
2 |
|
HashGenerator $hashGenerator = null |
|
87
|
2 |
|
) |
|
88
|
2 |
|
{ |
|
89
|
2 |
|
$this->name = $name; |
|
90
|
|
|
$this->creator = $creator; |
|
91
|
9 |
|
$this->date = $date; |
|
92
|
|
|
$this->description = $description; |
|
93
|
9 |
|
$this->place = $place; |
|
94
|
|
|
$this->id = $hashGenerator ? $hashGenerator::generate() : HashGenerator::generate(); |
|
95
|
|
|
$this->images = new ArrayCollection(); |
|
96
|
18 |
|
$this->links = new ArrayCollection(); |
|
97
|
|
|
} |
|
98
|
18 |
|
|
|
99
|
|
|
public function getDate(): string |
|
100
|
|
|
{ |
|
101
|
1 |
|
return $this->date->format('Y-m-d H:i'); |
|
102
|
|
|
} |
|
103
|
1 |
|
|
|
104
|
1 |
|
public function getId(): string |
|
105
|
|
|
{ |
|
106
|
9 |
|
return $this->id; |
|
107
|
|
|
} |
|
108
|
9 |
|
|
|
109
|
|
|
public function setDate(\DateTime $date) |
|
110
|
|
|
{ |
|
111
|
1 |
|
$this->date = $date; |
|
112
|
|
|
} |
|
113
|
1 |
|
|
|
114
|
1 |
|
public function getName(): string |
|
115
|
|
|
{ |
|
116
|
9 |
|
return $this->name; |
|
117
|
|
|
} |
|
118
|
9 |
|
|
|
119
|
|
|
public function setName(string $name) |
|
120
|
|
|
{ |
|
121
|
1 |
|
$this->name = $name; |
|
122
|
|
|
} |
|
123
|
1 |
|
|
|
124
|
1 |
|
public function getDescription(): string |
|
125
|
|
|
{ |
|
126
|
17 |
|
return $this->description; |
|
127
|
|
|
} |
|
128
|
17 |
|
|
|
129
|
|
|
public function setDescription(string $description) |
|
130
|
|
|
{ |
|
131
|
|
|
$this->description = $description; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
11 |
|
public function getPlace(): string |
|
135
|
|
|
{ |
|
136
|
11 |
|
return $this->place; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
public function setPlace(string $place) |
|
140
|
|
|
{ |
|
141
|
|
|
$this->place = $place; |
|
142
|
10 |
|
} |
|
143
|
|
|
|
|
144
|
10 |
|
public function getCreator(): User |
|
145
|
|
|
{ |
|
146
|
|
|
return $this->creator; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
1 |
|
* @return Image[]|PersistentCollection|ArrayCollection |
|
151
|
|
|
*/ |
|
152
|
1 |
|
public function getImages() |
|
153
|
1 |
|
{ |
|
154
|
|
|
return $this->images; |
|
155
|
|
|
} |
|
156
|
1 |
|
|
|
157
|
|
|
/** |
|
158
|
1 |
|
* @return Link[]|PersistentCollection|ArrayCollection |
|
159
|
|
|
*/ |
|
160
|
|
|
public function getLinks() |
|
161
|
2 |
|
{ |
|
162
|
|
|
return $this->links; |
|
163
|
2 |
|
} |
|
164
|
2 |
|
|
|
165
|
|
|
/** |
|
166
|
1 |
|
* @return Image|null |
|
167
|
|
|
*/ |
|
168
|
1 |
|
public function getImageWithName(string $imageName) |
|
169
|
1 |
|
{ |
|
170
|
|
|
$criteria = Criteria::create()->where(Criteria::expr()->eq('name', $imageName)); |
|
171
|
2 |
|
$criteria->setMaxResults(1); |
|
172
|
|
|
|
|
173
|
2 |
|
/** @var ArrayCollection $imagesCollection */ |
|
174
|
2 |
|
$imagesCollection = $this->images->matching($criteria); |
|
175
|
|
|
|
|
176
|
1 |
|
return $imagesCollection->first() ?: null; |
|
177
|
|
|
} |
|
178
|
1 |
|
|
|
179
|
1 |
|
public function addImage(Image $image) |
|
180
|
|
|
{ |
|
181
|
|
|
$this->images->add($image); |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
public function removeImage(Image $image) |
|
185
|
|
|
{ |
|
186
|
|
|
$this->images->removeElement($image); |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
public function addLink(Link $link) |
|
190
|
|
|
{ |
|
191
|
|
|
$this->links->add($link); |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
public function removeLink(Link $link) |
|
195
|
|
|
{ |
|
196
|
|
|
$this->links->removeElement($link); |
|
197
|
|
|
} |
|
198
|
|
|
} |
|
199
|
|
|
|