]> Raphaël G. Git Repositories - airbundle/blob - Entity/Country.php
Fix coalesce warning
[airbundle] / Entity / Country.php
1 <?php declare(strict_types=1);
2
3 /*
4 * This file is part of the Rapsys AirBundle package.
5 *
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Rapsys\AirBundle\Entity;
13
14 use Doctrine\Common\Collections\Collection;
15 use Doctrine\Common\Collections\ArrayCollection;
16 use Doctrine\ORM\Event\PreUpdateEventArgs;
17
18 /**
19 * Country
20 */
21 class Country {
22 /**
23 * Primary key
24 */
25 private ?int $id = null;
26
27 /**
28 * Create datetime
29 */
30 private \DateTime $created;
31
32 /**
33 * Update datetime
34 */
35 private \DateTime $updated;
36
37 /**
38 * Users collection
39 */
40 private Collection $users;
41
42 /**
43 * Constructor
44 *
45 * @param string $code The country code
46 * @param string $alpha The country alpha
47 * @param string $title The country title
48 */
49 public function __construct(private string $code, private string $alpha, private string $title) {
50 //Set defaults
51 $this->created = new \DateTime('now');
52 $this->updated = new \DateTime('now');
53
54 //Set collections
55 $this->users = new ArrayCollection();
56 }
57
58 /**
59 * Get id
60 *
61 * @return integer
62 */
63 public function getId(): ?int {
64 return $this->id;
65 }
66
67 /**
68 * Set code
69 *
70 * @param string $code
71 *
72 * @return Country
73 */
74 public function setCode(string $code): Country {
75 $this->code = $code;
76
77 return $this;
78 }
79
80 /**
81 * Get code
82 *
83 * @return string
84 */
85 public function getCode(): string {
86 return $this->code;
87 }
88
89 /**
90 * Set alpha
91 *
92 * @param string $alpha
93 *
94 * @return Country
95 */
96 public function setAlpha(string $alpha): Country {
97 $this->alpha = $alpha;
98
99 return $this;
100 }
101
102 /**
103 * Get alpha
104 *
105 * @return string
106 */
107 public function getAlpha(): string {
108 return $this->alpha;
109 }
110
111 /**
112 * Set title
113 *
114 * @param string $title
115 *
116 * @return Country
117 */
118 public function setTitle(string $title): Country {
119 $this->title = $title;
120
121 return $this;
122 }
123
124 /**
125 * Get title
126 *
127 * @return string
128 */
129 public function getTitle(): string {
130 return $this->title;
131 }
132
133 /**
134 * Set created
135 *
136 * @param \DateTime $created
137 *
138 * @return Country
139 */
140 public function setCreated(\DateTime $created): Country {
141 $this->created = $created;
142
143 return $this;
144 }
145
146 /**
147 * Get created
148 *
149 * @return \DateTime
150 */
151 public function getCreated(): \DateTime {
152 return $this->created;
153 }
154
155 /**
156 * Set updated
157 *
158 * @param \DateTime $updated
159 *
160 * @return Country
161 */
162 public function setUpdated(\DateTime $updated): Country {
163 $this->updated = $updated;
164
165 return $this;
166 }
167
168 /**
169 * Get updated
170 *
171 * @return \DateTime
172 */
173 public function getUpdated(): \DateTime {
174 return $this->updated;
175 }
176
177 /**
178 * Add user
179 *
180 * @param User $user
181 *
182 * @return Country
183 */
184 public function addUser(User $user): User {
185 $this->users[] = $user;
186
187 return $this;
188 }
189
190 /**
191 * Remove user
192 *
193 * @param User $user
194 */
195 public function removeUser(User $user): bool {
196 return $this->users->removeElement($user);
197 }
198
199 /**
200 * Get users
201 *
202 * @return ArrayCollection
203 */
204 public function getUsers(): ArrayCollection {
205 return $this->users;
206 }
207
208 /**
209 * {@inheritdoc}
210 */
211 public function preUpdate(PreUpdateEventArgs $eventArgs) {
212 //Check that we have an country instance
213 if (($country = $eventArgs->getObject()) instanceof Country) {
214 //Set updated value
215 $country->setUpdated(new \DateTime('now'));
216 }
217 }
218
219 /**
220 * Returns a string representation of the country
221 *
222 * @return string
223 */
224 public function __toString(): string {
225 return $this->title;
226 }
227 }