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 int |
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
|
2 |
|
*/ |
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
|
2 |
|
* inverseJoinColumns={@ORM\JoinColumn(name="image_id", referencedColumnName="id", unique=true)} |
65
|
2 |
|
* ) |
66
|
2 |
|
*/ |
67
|
2 |
|
private $images; |
68
|
2 |
|
|
69
|
2 |
|
public function __construct( |
70
|
|
|
string $name, |
71
|
6 |
|
User $creator, |
72
|
|
|
\DateTime $date, |
73
|
6 |
|
string $description |
74
|
|
|
) |
75
|
|
|
{ |
76
|
3 |
|
$this->name = $name; |
77
|
|
|
$this->creator = $creator; |
78
|
3 |
|
$this->date = $date; |
79
|
|
|
$this->description = $description; |
80
|
|
|
$this->id = HashGenerator::generate(); |
|
|
|
|
81
|
1 |
|
$this->images = new ArrayCollection(); |
82
|
|
|
} |
83
|
1 |
|
|
84
|
1 |
|
public function getDate(): string |
85
|
|
|
{ |
86
|
1 |
|
return $this->date->format('Y-m-d H:i'); |
87
|
|
|
} |
88
|
1 |
|
|
89
|
1 |
|
public function getId(): string |
90
|
|
|
{ |
91
|
1 |
|
return $this->id; |
92
|
|
|
} |
93
|
1 |
|
|
94
|
1 |
|
public function setDate(\DateTime $date) |
95
|
|
|
{ |
96
|
|
|
$this->date = $date; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function getName(): string |
100
|
|
|
{ |
101
|
|
|
return $this->name; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function setName(string $name) |
105
|
|
|
{ |
106
|
|
|
$this->name = $name; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function getDescription(): string |
110
|
|
|
{ |
111
|
|
|
return $this->description; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function setDescription(string $description) |
115
|
|
|
{ |
116
|
|
|
$this->description = $description; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @return Image[]|PersistentCollection |
121
|
|
|
*/ |
122
|
|
|
public function getImages() |
123
|
|
|
{ |
124
|
|
|
return $this->images; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @return Image|null |
129
|
|
|
*/ |
130
|
|
|
public function getImageWithName(string $imageName) |
131
|
|
|
{ |
132
|
|
|
$criteria = Criteria::create()->where(Criteria::expr()->eq('name', $imageName)); |
133
|
|
|
$criteria->setMaxResults(1); |
134
|
|
|
|
135
|
|
|
/** @var ArrayCollection $imagesCollection */ |
136
|
|
|
$imagesCollection = $this->images->matching($criteria); |
137
|
|
|
|
138
|
|
|
return $imagesCollection->first() ?: null; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public function addImage(Image $image) |
142
|
|
|
{ |
143
|
|
|
$this->images->add($image); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
public function removeImage(Image $image) |
147
|
|
|
{ |
148
|
|
|
$this->images->removeElement($image); |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.