]> Raphaël G. Git Repositories - airbundle/blob - Entity/Snippet.php
Improve modified computing
[airbundle] / Entity / Snippet.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\ORM\Event\PreUpdateEventArgs;
15
16 /**
17 * Snippet
18 */
19 class Snippet {
20 /**
21 * Primary key
22 */
23 private ?int $id = null;
24
25 /**
26 * @var string
27 */
28 private ?string $description = null;
29
30 /**
31 * @var string
32 */
33 private ?string $class = null;
34
35 /**
36 * @var string
37 */
38 private ?string $short = null;
39
40 /**
41 * @var integer
42 */
43 private ?int $rate = null;
44
45 /**
46 * @var bool
47 */
48 private ?bool $hat = null;
49
50 /**
51 * @var string
52 */
53 private ?string $contact = null;
54
55 /**
56 * @var string
57 */
58 private ?string $donate = null;
59
60 /**
61 * @var string
62 */
63 private ?string $link = null;
64
65 /**
66 * @var string
67 */
68 private ?string $profile = null;
69
70 /**
71 * Create datetime
72 */
73 private \DateTime $created;
74
75 /**
76 * Update datetime
77 */
78 private \DateTime $updated;
79
80 /**
81 * Constructor
82 *
83 * @param string $locale The locale
84 * @param Location $location The location instance
85 * @param User $user The user instance
86 */
87 public function __construct(private string $locale, private Location $location, private User $user) {
88 //Set defaults
89 $this->created = new \DateTime('now');
90 $this->updated = new \DateTime('now');
91 }
92
93 /**
94 * Get id
95 *
96 * @return integer
97 */
98 public function getId(): ?int {
99 return $this->id;
100 }
101
102 /**
103 * Set locale
104 *
105 * @param string $locale
106 *
107 * @return Snippet
108 */
109 public function setLocale(string $locale): Snippet {
110 $this->locale = $locale;
111
112 return $this;
113 }
114
115 /**
116 * Get locale
117 *
118 * @return string
119 */
120 public function getLocale(): string {
121 return $this->locale;
122 }
123
124 /**
125 * Set description
126 *
127 * @param string $description
128 *
129 * @return Snippet
130 */
131 public function setDescription(?string $description): Snippet {
132 $this->description = $description;
133
134 return $this;
135 }
136
137 /**
138 * Get description
139 *
140 * @return string
141 */
142 public function getDescription(): ?string {
143 return $this->description;
144 }
145
146 /**
147 * Set class
148 *
149 * @param string $class
150 *
151 * @return Snippet
152 */
153 public function setClass(?string $class): Snippet {
154 $this->class = $class;
155
156 return $this;
157 }
158
159 /**
160 * Get class
161 *
162 * @return string
163 */
164 public function getClass(): ?string {
165 return $this->class;
166 }
167
168 /**
169 * Set short
170 *
171 * @param string $short
172 *
173 * @return Snippet
174 */
175 public function setShort(?string $short): Snippet {
176 $this->short = $short;
177
178 return $this;
179 }
180
181 /**
182 * Get short
183 *
184 * @return string
185 */
186 public function getShort(): ?string {
187 return $this->short;
188 }
189
190 /**
191 * Set rate
192 *
193 * @param int $rate
194 *
195 * @return Snippet
196 */
197 public function setRate(?int $rate): Snippet {
198 $this->rate = $rate;
199
200 return $this;
201 }
202
203 /**
204 * Get rate
205 *
206 * @return int
207 */
208 public function getRate(): ?int {
209 return $this->rate;
210 }
211
212 /**
213 * Set hat
214 *
215 * @param bool $hat
216 *
217 * @return User
218 */
219 public function setHat(?bool $hat): Snippet {
220 $this->hat = $hat;
221
222 return $this;
223 }
224
225 /**
226 * Get hat
227 *
228 * @return bool
229 */
230 public function getHat(): ?bool {
231 return $this->hat;
232 }
233 /**
234 * Set contact
235 *
236 * @param string $contact
237 *
238 * @return Snippet
239 */
240 public function setContact(?string $contact): Snippet {
241 $this->contact = $contact;
242
243 return $this;
244 }
245
246 /**
247 * Get contact
248 *
249 * @return string
250 */
251 public function getContact(): ?string {
252 return $this->contact;
253 }
254
255 /**
256 * Set donate
257 *
258 * @param string $donate
259 *
260 * @return Snippet
261 */
262 public function setDonate(?string $donate): Snippet {
263 $this->donate = $donate;
264
265 return $this;
266 }
267
268 /**
269 * Get donate
270 *
271 * @return string
272 */
273 public function getDonate(): ?string {
274 return $this->donate;
275 }
276
277 /**
278 * Set link
279 *
280 * @param string $link
281 *
282 * @return Snippet
283 */
284 public function setLink(?string $link): Snippet {
285 $this->link = $link;
286
287 return $this;
288 }
289
290 /**
291 * Get link
292 *
293 * @return string
294 */
295 public function getLink(): ?string {
296 return $this->link;
297 }
298
299 /**
300 * Set profile
301 *
302 * @param string $profile
303 *
304 * @return Snippet
305 */
306 public function setProfile(?string $profile): Snippet {
307 $this->profile = $profile;
308
309 return $this;
310 }
311
312 /**
313 * Get profile
314 *
315 * @return string
316 */
317 public function getProfile(): ?string {
318 return $this->profile;
319 }
320
321 /**
322 * Set created
323 *
324 * @param \DateTime $created
325 *
326 * @return Snippet
327 */
328 public function setCreated(\DateTime $created): Snippet {
329 $this->created = $created;
330
331 return $this;
332 }
333
334 /**
335 * Get created
336 *
337 * @return \DateTime
338 */
339 public function getCreated(): \DateTime {
340 return $this->created;
341 }
342
343 /**
344 * Set updated
345 *
346 * @param \DateTime $updated
347 *
348 * @return Snippet
349 */
350 public function setUpdated(\DateTime $updated): Snippet {
351 $this->updated = $updated;
352
353 return $this;
354 }
355
356 /**
357 * Get updated
358 *
359 * @return \DateTime
360 */
361 public function getUpdated(): \DateTime {
362 return $this->updated;
363 }
364
365 /**
366 * Set location
367 *
368 * @param Location $location
369 *
370 * @return Snippet
371 */
372 public function setLocation(Location $location): Snippet {
373 $this->location = $location;
374
375 return $this;
376 }
377
378 /**
379 * Get location
380 *
381 * @return Location
382 */
383 public function getLocation(): Location {
384 return $this->location;
385 }
386
387 /**
388 * Set user
389 *
390 * @param User $user
391 *
392 * @return Snippet
393 */
394 public function setUser(User $user): Snippet {
395 $this->user = $user;
396
397 return $this;
398 }
399
400 /**
401 * Get user
402 *
403 * @return User
404 */
405 public function getUser(): User {
406 return $this->user;
407 }
408
409 /**
410 * {@inheritdoc}
411 */
412 public function preUpdate(PreUpdateEventArgs $eventArgs) {
413 //Check that we have an snippet instance
414 if (($snippet = $eventArgs->getObject()) instanceof Snippet) {
415 //Set updated value
416 $snippet->setUpdated(new \DateTime('now'));
417 }
418 }
419 }