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 User |
49
|
|
|
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\User", inversedBy="events") |
50
|
|
|
* @ORM\JoinColumn(name="creator", referencedColumnName="login") |
51
|
|
|
*/ |
52
|
|
|
private $creator; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Image") |
56
|
|
|
* @ORM\JoinColumn(name="image_id", referencedColumnName="id") |
57
|
|
|
*/ |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var Image[]|ArrayCollection |
61
|
|
|
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\Image", orphanRemoval=true) |
62
|
|
|
* @ORM\JoinTable(name="event_images", |
63
|
|
|
* joinColumns={@ORM\JoinColumn(name="event_id", referencedColumnName="id")}, |
64
|
|
|
* inverseJoinColumns={@ORM\JoinColumn(name="image_name", referencedColumnName="name", unique=true)} |
65
|
|
|
* ) |
66
|
|
|
*/ |
67
|
|
|
private $images; |
68
|
|
|
|
69
|
2 |
|
public function __construct( |
70
|
|
|
string $name, |
71
|
|
|
User $creator, |
72
|
|
|
\DateTime $date, |
73
|
|
|
string $description, |
74
|
|
|
HashGenerator $hashGenerator = null |
75
|
|
|
) |
76
|
|
|
{ |
77
|
2 |
|
$this->name = $name; |
78
|
2 |
|
$this->creator = $creator; |
79
|
2 |
|
$this->date = $date; |
80
|
2 |
|
$this->description = $description; |
81
|
2 |
|
$this->id = $hashGenerator ? $hashGenerator::generate() : HashGenerator::generate(); |
82
|
2 |
|
$this->images = new ArrayCollection(); |
83
|
2 |
|
} |
84
|
|
|
|
85
|
6 |
|
public function getDate(): string |
86
|
|
|
{ |
87
|
6 |
|
return $this->date->format('Y-m-d H:i'); |
88
|
|
|
} |
89
|
|
|
|
90
|
12 |
|
public function getId(): string |
91
|
|
|
{ |
92
|
12 |
|
return $this->id; |
93
|
|
|
} |
94
|
|
|
|
95
|
1 |
|
public function setDate(\DateTime $date) |
96
|
|
|
{ |
97
|
1 |
|
$this->date = $date; |
98
|
1 |
|
} |
99
|
|
|
|
100
|
6 |
|
public function getName(): string |
101
|
|
|
{ |
102
|
6 |
|
return $this->name; |
103
|
|
|
} |
104
|
|
|
|
105
|
1 |
|
public function setName(string $name) |
106
|
|
|
{ |
107
|
1 |
|
$this->name = $name; |
108
|
1 |
|
} |
109
|
|
|
|
110
|
6 |
|
public function getDescription(): string |
111
|
|
|
{ |
112
|
6 |
|
return $this->description; |
113
|
|
|
} |
114
|
|
|
|
115
|
1 |
|
public function setDescription(string $description) |
116
|
|
|
{ |
117
|
1 |
|
$this->description = $description; |
118
|
1 |
|
} |
119
|
|
|
|
120
|
5 |
|
public function getCreator(): User |
121
|
|
|
{ |
122
|
5 |
|
return $this->creator; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @return Image[]|PersistentCollection |
127
|
|
|
*/ |
128
|
8 |
|
public function getImages() |
129
|
|
|
{ |
130
|
8 |
|
return $this->images; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @return Image|null |
135
|
|
|
*/ |
136
|
1 |
|
public function getImageWithName(string $imageName) |
137
|
|
|
{ |
138
|
1 |
|
$criteria = Criteria::create()->where(Criteria::expr()->eq('name', $imageName)); |
139
|
1 |
|
$criteria->setMaxResults(1); |
140
|
|
|
|
141
|
|
|
/** @var ArrayCollection $imagesCollection */ |
142
|
1 |
|
$imagesCollection = $this->images->matching($criteria); |
143
|
|
|
|
144
|
1 |
|
return $imagesCollection->first() ?: null; |
145
|
|
|
} |
146
|
|
|
|
147
|
2 |
|
public function addImage(Image $image) |
148
|
|
|
{ |
149
|
2 |
|
$this->images->add($image); |
150
|
2 |
|
} |
151
|
|
|
|
152
|
1 |
|
public function removeImage(Image $image) |
153
|
|
|
{ |
154
|
1 |
|
$this->images->removeElement($image); |
155
|
1 |
|
} |
156
|
|
|
} |
157
|
|
|
|