|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Stfalcon\Bundle\EventBundle\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use Application\Bundle\DefaultBundle\Entity\TicketCost; |
|
6
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
7
|
|
|
use Gedmo\Mapping\Annotation as Gedmo; |
|
8
|
|
|
use Application\Bundle\UserBundle\Entity\User; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Stfalcon\Bundle\EventBundle\Entity\Ticket. |
|
12
|
|
|
* |
|
13
|
|
|
* @ORM\Table(name="event__tickets") |
|
14
|
|
|
* @ORM\Entity(repositoryClass="Stfalcon\Bundle\EventBundle\Repository\TicketRepository") |
|
15
|
|
|
*/ |
|
16
|
|
|
class Ticket |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var int |
|
20
|
|
|
* |
|
21
|
|
|
* @ORM\Column(name="id", type="integer") |
|
22
|
|
|
* @ORM\Id |
|
23
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
|
24
|
|
|
*/ |
|
25
|
|
|
private $id; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Сумма для оплаты. |
|
29
|
|
|
* |
|
30
|
|
|
* @var float |
|
31
|
|
|
* |
|
32
|
|
|
* @ORM\Column(name="amount", type="decimal", precision=10, scale=2) |
|
33
|
|
|
*/ |
|
34
|
|
|
private $amount; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Сумма без учета скидки. |
|
38
|
|
|
* |
|
39
|
|
|
* @var float |
|
40
|
|
|
* |
|
41
|
|
|
* @ORM\Column(name="amount_without_discount", type="decimal", precision=10, scale=2) |
|
42
|
|
|
*/ |
|
43
|
|
|
private $amountWithoutDiscount; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var PromoCode |
|
47
|
|
|
* |
|
48
|
|
|
* @ORM\ManyToOne(targetEntity="PromoCode") |
|
49
|
|
|
* @ORM\JoinColumn(name="promo_code_id", referencedColumnName="id", onDelete="SET NULL") |
|
50
|
|
|
*/ |
|
51
|
|
|
private $promoCode; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @var Event |
|
55
|
|
|
* |
|
56
|
|
|
* @ORM\ManyToOne(targetEntity="Event", inversedBy="tickets") |
|
57
|
|
|
* @ORM\JoinColumn(name="event_id", referencedColumnName="id", onDelete="CASCADE") |
|
58
|
|
|
*/ |
|
59
|
|
|
private $event; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @var TicketCost |
|
63
|
|
|
* |
|
64
|
|
|
* @ORM\ManyToOne(targetEntity="Application\Bundle\DefaultBundle\Entity\TicketCost", inversedBy="tickets") |
|
65
|
|
|
* @ORM\JoinColumn(name="ticket_cost_id", referencedColumnName="id", onDelete="SET NULL") |
|
66
|
|
|
*/ |
|
67
|
|
|
private $ticketCost; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* На кого выписан билет. Т.е. участник не обязательно плательщик. |
|
71
|
|
|
* |
|
72
|
|
|
* @var User |
|
73
|
|
|
* |
|
74
|
|
|
* @ORM\ManyToOne(targetEntity="Application\Bundle\UserBundle\Entity\User", inversedBy="tickets") |
|
75
|
|
|
* @ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="CASCADE") |
|
76
|
|
|
*/ |
|
77
|
|
|
private $user; |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @var \Stfalcon\Bundle\EventBundle\Entity\Payment |
|
81
|
|
|
* |
|
82
|
|
|
* @ORM\ManyToOne(targetEntity="Stfalcon\Bundle\EventBundle\Entity\Payment", inversedBy="tickets") |
|
83
|
|
|
* @ORM\JoinColumn(name="payment_id", referencedColumnName="id", onDelete="SET NULL") |
|
84
|
|
|
*/ |
|
85
|
|
|
private $payment; |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @var \DateTime |
|
89
|
|
|
* |
|
90
|
|
|
* @ORM\Column(name="created_at", type="datetime") |
|
91
|
|
|
* |
|
92
|
|
|
* @Gedmo\Timestampable(on="create") |
|
93
|
|
|
*/ |
|
94
|
|
|
private $createdAt; |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @var \DateTime |
|
98
|
|
|
* |
|
99
|
|
|
* @ORM\Column(name="updated_at", type="datetime") |
|
100
|
|
|
* |
|
101
|
|
|
* @Gedmo\Timestampable(on="update") |
|
102
|
|
|
*/ |
|
103
|
|
|
private $updatedAt; |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @var bool |
|
107
|
|
|
* |
|
108
|
|
|
* @ORM\Column(name="used", type="boolean") |
|
109
|
|
|
*/ |
|
110
|
|
|
private $used = false; |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @var bool |
|
114
|
|
|
* |
|
115
|
|
|
* @ORM\Column(name="has_discount", type="boolean") |
|
116
|
|
|
*/ |
|
117
|
|
|
private $hasDiscount = false; |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* Get id. |
|
121
|
|
|
* |
|
122
|
|
|
* @return int |
|
123
|
|
|
*/ |
|
124
|
|
|
public function getId() |
|
125
|
|
|
{ |
|
126
|
|
|
return $this->id; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* @return TicketCost |
|
131
|
|
|
*/ |
|
132
|
|
|
public function getTicketCost() |
|
133
|
|
|
{ |
|
134
|
|
|
return $this->ticketCost; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @param TicketCost $ticketCost |
|
139
|
|
|
* |
|
140
|
|
|
* @return $this |
|
141
|
|
|
*/ |
|
142
|
|
|
public function setTicketCost($ticketCost) |
|
143
|
|
|
{ |
|
144
|
|
|
$this->ticketCost = $ticketCost; |
|
145
|
|
|
$this->ticketCost->addTicket($this); |
|
146
|
|
|
|
|
147
|
|
|
return $this; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* @return Event |
|
152
|
|
|
*/ |
|
153
|
|
|
public function getEvent() |
|
154
|
|
|
{ |
|
155
|
|
|
return $this->event; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* @param Event $event |
|
160
|
|
|
* |
|
161
|
|
|
* @return $this |
|
162
|
|
|
*/ |
|
163
|
|
|
public function setEvent(Event $event) |
|
164
|
|
|
{ |
|
165
|
|
|
$this->event = $event; |
|
166
|
|
|
|
|
167
|
|
|
return $this; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* @return bool |
|
172
|
|
|
*/ |
|
173
|
|
|
public function hasPayment() |
|
174
|
|
|
{ |
|
175
|
|
|
return (bool) $this->getPayment(); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* @return Payment |
|
180
|
|
|
*/ |
|
181
|
|
|
public function getPayment() |
|
182
|
|
|
{ |
|
183
|
|
|
return $this->payment; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* @param Payment|null $payment |
|
188
|
|
|
*/ |
|
189
|
|
|
public function setPayment($payment) |
|
190
|
|
|
{ |
|
191
|
|
|
$this->payment = $payment; |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
/** |
|
195
|
|
|
* @param User $user |
|
196
|
|
|
* |
|
197
|
|
|
* @return $this |
|
198
|
|
|
*/ |
|
199
|
|
|
public function setUser(User $user) |
|
200
|
|
|
{ |
|
201
|
|
|
$this->user = $user; |
|
202
|
|
|
|
|
203
|
|
|
return $this; |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
/** |
|
207
|
|
|
* @return User |
|
208
|
|
|
*/ |
|
209
|
|
|
public function getUser() |
|
210
|
|
|
{ |
|
211
|
|
|
return $this->user; |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
/** |
|
215
|
|
|
* @return \DateTime |
|
216
|
|
|
*/ |
|
217
|
|
|
public function getCreatedAt() |
|
218
|
|
|
{ |
|
219
|
|
|
return $this->createdAt; |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
/** |
|
223
|
|
|
* @param \DateTime $createdAt |
|
224
|
|
|
*/ |
|
225
|
|
|
public function setCreatedAt($createdAt) |
|
226
|
|
|
{ |
|
227
|
|
|
$this->createdAt = $createdAt; |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
/** |
|
231
|
|
|
* @return \DateTime |
|
232
|
|
|
*/ |
|
233
|
|
|
public function getUpdatedAt() |
|
234
|
|
|
{ |
|
235
|
|
|
return $this->updatedAt; |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
/** |
|
239
|
|
|
* @param \DateTime $updatedAt |
|
240
|
|
|
*/ |
|
241
|
|
|
public function setUpdatedAt($updatedAt) |
|
242
|
|
|
{ |
|
243
|
|
|
$this->updatedAt = $updatedAt; |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
/** |
|
247
|
|
|
* Checking if ticket is "paid". |
|
248
|
|
|
* |
|
249
|
|
|
* @return bool |
|
250
|
|
|
*/ |
|
251
|
|
|
public function isPaid() |
|
252
|
|
|
{ |
|
253
|
|
|
return (bool) ($this->hasPayment() && $this->getPayment()->isPaid()); |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
/** |
|
257
|
|
|
* Mark ticket as "used". |
|
258
|
|
|
* |
|
259
|
|
|
* @param bool $used |
|
260
|
|
|
*/ |
|
261
|
|
|
public function setUsed($used) |
|
262
|
|
|
{ |
|
263
|
|
|
$this->used = $used; |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
|
|
/** |
|
267
|
|
|
* Checking if ticket is "used". |
|
268
|
|
|
* |
|
269
|
|
|
* @return bool |
|
270
|
|
|
*/ |
|
271
|
|
|
public function isUsed() |
|
272
|
|
|
{ |
|
273
|
|
|
return $this->used; |
|
274
|
|
|
} |
|
275
|
|
|
|
|
276
|
|
|
/** |
|
277
|
|
|
* Generate unique md5 hash for ticket. |
|
278
|
|
|
* |
|
279
|
|
|
* @return string |
|
280
|
|
|
*/ |
|
281
|
|
|
public function getHash() |
|
282
|
|
|
{ |
|
283
|
|
|
return md5($this->getId().$this->getCreatedAt()->format('Y-m-d H:i:s')); |
|
284
|
|
|
} |
|
285
|
|
|
|
|
286
|
|
|
/** |
|
287
|
|
|
* @return string |
|
288
|
|
|
*/ |
|
289
|
|
|
public function __toString() |
|
290
|
|
|
{ |
|
291
|
|
|
return (string) $this->getId().' ('.$this->getUser()->getFullname().')'; |
|
292
|
|
|
} |
|
293
|
|
|
|
|
294
|
|
|
/** |
|
295
|
|
|
* @param float $amount |
|
296
|
|
|
* |
|
297
|
|
|
* @return Ticket |
|
298
|
|
|
*/ |
|
299
|
|
|
public function setAmount($amount) |
|
300
|
|
|
{ |
|
301
|
|
|
// мы можем устанавливать/обновлять стоимость только для билетов |
|
302
|
|
|
// с неоплаченными платежами |
|
303
|
|
|
// if ($this->hasPayment() && $this->getPayment()->isPending()) { |
|
304
|
|
|
$this->amount = $amount; |
|
305
|
|
|
// $this->getPayment()->recalculateAmount(); |
|
306
|
|
|
// } |
|
307
|
|
|
return $this; |
|
308
|
|
|
} |
|
309
|
|
|
|
|
310
|
|
|
/** |
|
311
|
|
|
* @return float |
|
312
|
|
|
*/ |
|
313
|
|
|
public function getAmount() |
|
314
|
|
|
{ |
|
315
|
|
|
return $this->amount; |
|
316
|
|
|
} |
|
317
|
|
|
|
|
318
|
|
|
/** |
|
319
|
|
|
* @param float $amountWithoutDiscount |
|
320
|
|
|
* |
|
321
|
|
|
* @return $this |
|
322
|
|
|
*/ |
|
323
|
|
|
public function setAmountWithoutDiscount($amountWithoutDiscount) |
|
324
|
|
|
{ |
|
325
|
|
|
$this->amountWithoutDiscount = $amountWithoutDiscount; |
|
326
|
|
|
|
|
327
|
|
|
return $this; |
|
328
|
|
|
} |
|
329
|
|
|
|
|
330
|
|
|
/** |
|
331
|
|
|
* @return float |
|
332
|
|
|
*/ |
|
333
|
|
|
public function getAmountWithoutDiscount() |
|
334
|
|
|
{ |
|
335
|
|
|
return $this->amountWithoutDiscount; |
|
336
|
|
|
} |
|
337
|
|
|
|
|
338
|
|
|
/** |
|
339
|
|
|
* @param \Stfalcon\Bundle\EventBundle\Entity\PromoCode $promoCode |
|
340
|
|
|
* |
|
341
|
|
|
* @return $this |
|
342
|
|
|
*/ |
|
343
|
|
|
public function setPromoCode($promoCode) |
|
344
|
|
|
{ |
|
345
|
|
|
$this->promoCode = $promoCode; |
|
346
|
|
|
|
|
347
|
|
|
return $this; |
|
348
|
|
|
} |
|
349
|
|
|
|
|
350
|
|
|
/** |
|
351
|
|
|
* @return \Stfalcon\Bundle\EventBundle\Entity\PromoCode |
|
352
|
|
|
*/ |
|
353
|
|
|
public function getPromoCode() |
|
354
|
|
|
{ |
|
355
|
|
|
return $this->promoCode; |
|
356
|
|
|
} |
|
357
|
|
|
|
|
358
|
|
|
/** |
|
359
|
|
|
* @return bool |
|
360
|
|
|
*/ |
|
361
|
|
|
public function hasPromoCode() |
|
362
|
|
|
{ |
|
363
|
|
|
return !empty($this->promoCode); |
|
364
|
|
|
} |
|
365
|
|
|
|
|
366
|
|
|
/** |
|
367
|
|
|
* @param bool $hasDiscount |
|
368
|
|
|
*/ |
|
369
|
|
|
public function setHasDiscount($hasDiscount) |
|
370
|
|
|
{ |
|
371
|
|
|
$this->hasDiscount = $hasDiscount; |
|
372
|
|
|
} |
|
373
|
|
|
|
|
374
|
|
|
/** |
|
375
|
|
|
* @return bool |
|
376
|
|
|
*/ |
|
377
|
|
|
public function getHasDiscount() |
|
378
|
|
|
{ |
|
379
|
|
|
return $this->hasDiscount; |
|
380
|
|
|
} |
|
381
|
|
|
|
|
382
|
|
|
/** |
|
383
|
|
|
* @return string |
|
384
|
|
|
*/ |
|
385
|
|
|
public function generatePdfFilename() |
|
386
|
|
|
{ |
|
387
|
|
|
return 'ticket-'.$this->getEvent()->getSlug().'.pdf'; |
|
388
|
|
|
} |
|
389
|
|
|
} |
|
390
|
|
|
|