1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Application\Bundle\DefaultBundle\Entity; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
6
|
|
|
use Stfalcon\Bundle\EventBundle\Entity\Event; |
7
|
|
|
use Doctrine\ORM\Mapping as ORM; |
8
|
|
|
use Stfalcon\Bundle\EventBundle\Entity\Ticket; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @ORM\Table(name="event__ticketsCost") |
12
|
|
|
* @ORM\Entity(repositoryClass="Application\Bundle\DefaultBundle\Repository\TicketCostRepository") |
13
|
|
|
*/ |
14
|
|
|
class TicketCost |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var int |
18
|
|
|
* |
19
|
|
|
* @ORM\Column(name="id", type="integer") |
20
|
|
|
* @ORM\Id |
21
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
22
|
|
|
*/ |
23
|
|
|
private $id; |
24
|
|
|
/** |
25
|
|
|
* @var Event |
26
|
|
|
* |
27
|
|
|
* @ORM\ManyToOne(targetEntity="Stfalcon\Bundle\EventBundle\Entity\Event", inversedBy="ticketsCost") |
28
|
|
|
* @ORM\JoinColumn(name="event_id", referencedColumnName="id", onDelete="cascade") |
29
|
|
|
*/ |
30
|
|
|
private $event; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var ArrayCollection |
34
|
|
|
* |
35
|
|
|
* @ORM\OneToMany(targetEntity="Stfalcon\Bundle\EventBundle\Entity\Ticket", |
36
|
|
|
* mappedBy="ticketCost", |
37
|
|
|
* cascade={"persist"}) |
38
|
|
|
*/ |
39
|
|
|
private $tickets; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var int |
43
|
|
|
* |
44
|
|
|
* @ORM\Column(name="count", type="integer", nullable=true) |
45
|
|
|
*/ |
46
|
|
|
private $count; |
47
|
|
|
/** |
48
|
|
|
* Сумма для оплаты. |
49
|
|
|
* |
50
|
|
|
* @var float |
51
|
|
|
* |
52
|
|
|
* @ORM\Column(name="amount", type="decimal", precision=10, scale=2) |
53
|
|
|
*/ |
54
|
|
|
private $amount; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Альтернативна сума оплати. |
58
|
|
|
* |
59
|
|
|
* @var float |
60
|
|
|
* |
61
|
|
|
* @ORM\Column(name="alt_amount", type="decimal", precision=10, scale=2) |
62
|
|
|
*/ |
63
|
|
|
private $altAmount; |
64
|
|
|
/** |
65
|
|
|
* @var int |
66
|
|
|
* |
67
|
|
|
* @ORM\Column(name="sold_count", type="integer", nullable=true) |
68
|
|
|
*/ |
69
|
|
|
private $soldCount = 0; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @var bool |
73
|
|
|
* |
74
|
|
|
* @ORM\Column(name="enabled", type="boolean", nullable=false, options={"default":"1"}) |
75
|
|
|
*/ |
76
|
|
|
private $enabled = true; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @var bool |
80
|
|
|
* |
81
|
|
|
* @ORM\Column(name="unlimited", type="boolean", nullable=false, options={"default":"0"}) |
82
|
|
|
*/ |
83
|
|
|
private $unlimited = false; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @var string |
87
|
|
|
* |
88
|
|
|
* @ORM\Column(name="name", type="string", nullable=false) |
89
|
|
|
*/ |
90
|
|
|
private $name; |
91
|
|
|
/** |
92
|
|
|
* @var int |
93
|
|
|
*/ |
94
|
|
|
private $temporaryCount = 0; |
95
|
|
|
|
96
|
|
|
public function __construct() |
97
|
|
|
{ |
98
|
|
|
$this->tickets = new ArrayCollection(); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @return int |
103
|
|
|
*/ |
104
|
|
|
public function getId() |
105
|
|
|
{ |
106
|
|
|
return $this->id; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @return float |
111
|
|
|
*/ |
112
|
|
|
public function getAmountByTemporaryCount() |
113
|
|
|
{ |
114
|
|
|
++$this->temporaryCount; |
115
|
|
|
|
116
|
|
|
return $this->getAmount(); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @return bool |
121
|
|
|
*/ |
122
|
|
|
public function isHaveTemporaryCount() |
123
|
|
|
{ |
124
|
|
|
return $this->unlimited || ($this->soldCount + $this->temporaryCount) < $this->count; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @return mixed |
129
|
|
|
*/ |
130
|
|
|
public function getTickets() |
131
|
|
|
{ |
132
|
|
|
return $this->tickets; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @param mixed $tickets |
137
|
|
|
* |
138
|
|
|
* @return $this |
139
|
|
|
*/ |
140
|
|
|
public function setTickets($tickets) |
141
|
|
|
{ |
142
|
|
|
$this->tickets = $tickets; |
143
|
|
|
|
144
|
|
|
return $this; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @param $ticket |
149
|
|
|
* |
150
|
|
|
* @return $this |
151
|
|
|
*/ |
152
|
|
|
public function addTicket($ticket) |
153
|
|
|
{ |
154
|
|
|
if (!$this->tickets->contains($ticket)) { |
155
|
|
|
$this->tickets->add($ticket); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
return $this; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @return float |
163
|
|
|
*/ |
164
|
|
|
public function getAltAmount() |
165
|
|
|
{ |
166
|
|
|
return $this->altAmount; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @param float $altAmount |
171
|
|
|
* |
172
|
|
|
* @return $this |
173
|
|
|
*/ |
174
|
|
|
public function setAltAmount($altAmount) |
175
|
|
|
{ |
176
|
|
|
$this->altAmount = $altAmount; |
177
|
|
|
|
178
|
|
|
return $this; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @return string |
183
|
|
|
*/ |
184
|
|
|
public function getName() |
185
|
|
|
{ |
186
|
|
|
return $this->name; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* @param string $name |
191
|
|
|
* |
192
|
|
|
* @return $this |
193
|
|
|
*/ |
194
|
|
|
public function setName($name) |
195
|
|
|
{ |
196
|
|
|
$this->name = $name; |
197
|
|
|
|
198
|
|
|
return $this; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* @return Event |
203
|
|
|
*/ |
204
|
|
|
public function getEvent() |
205
|
|
|
{ |
206
|
|
|
return $this->event; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* @param Event $event |
211
|
|
|
* |
212
|
|
|
* @return $this |
213
|
|
|
*/ |
214
|
|
|
public function setEvent($event) |
215
|
|
|
{ |
216
|
|
|
$this->event = $event; |
217
|
|
|
|
218
|
|
|
return $this; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* @return int |
223
|
|
|
*/ |
224
|
|
|
public function getCount() |
225
|
|
|
{ |
226
|
|
|
return $this->count; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* @param int $count |
231
|
|
|
* |
232
|
|
|
* @return $this |
233
|
|
|
*/ |
234
|
|
|
public function setCount($count) |
235
|
|
|
{ |
236
|
|
|
$this->count = $count; |
237
|
|
|
|
238
|
|
|
return $this; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* @return float |
243
|
|
|
*/ |
244
|
|
|
public function getAmount() |
245
|
|
|
{ |
246
|
|
|
return $this->amount; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* @param float $amount |
251
|
|
|
* |
252
|
|
|
* @return $this |
253
|
|
|
*/ |
254
|
|
|
public function setAmount($amount) |
255
|
|
|
{ |
256
|
|
|
$this->amount = $amount; |
257
|
|
|
|
258
|
|
|
return $this; |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* @return int |
263
|
|
|
*/ |
264
|
|
|
public function getSoldCount() |
265
|
|
|
{ |
266
|
|
|
return $this->soldCount; |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* @param int $soldCount |
271
|
|
|
* |
272
|
|
|
* @return $this |
273
|
|
|
*/ |
274
|
|
|
public function setSoldCount($soldCount) |
275
|
|
|
{ |
276
|
|
|
$this->soldCount = $soldCount; |
277
|
|
|
|
278
|
|
|
return $this; |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
/** |
282
|
|
|
* @return int |
283
|
|
|
*/ |
284
|
|
|
public function recalculateSoldCount() |
285
|
|
|
{ |
286
|
|
|
$soldCount = 0; |
287
|
|
|
/** @var Ticket $ticket */ |
288
|
|
|
foreach ($this->getTickets() as $ticket) { |
289
|
|
|
if ($ticket->isPaid()) { |
290
|
|
|
++$soldCount; |
291
|
|
|
} |
292
|
|
|
} |
293
|
|
|
$this->soldCount = $soldCount; |
294
|
|
|
|
295
|
|
|
if (!$this->unlimited && $this->isEnabled()) { |
296
|
|
|
$this->setEnabled($this->count > $this->soldCount); |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
return $this->soldCount; |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
/** |
303
|
|
|
* @return $this |
304
|
|
|
*/ |
305
|
|
|
public function decSoldCount() |
306
|
|
|
{ |
307
|
|
|
--$this->soldCount; |
308
|
|
|
|
309
|
|
|
return $this; |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
/** |
313
|
|
|
* @return bool |
314
|
|
|
*/ |
315
|
|
|
public function isEnabled() |
316
|
|
|
{ |
317
|
|
|
return $this->enabled; |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
/** |
321
|
|
|
* @param bool $enabled |
322
|
|
|
* |
323
|
|
|
* @return $this |
324
|
|
|
*/ |
325
|
|
|
public function setEnabled($enabled) |
326
|
|
|
{ |
327
|
|
|
$this->enabled = $enabled; |
328
|
|
|
|
329
|
|
|
return $this; |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
/** |
333
|
|
|
* @return bool |
334
|
|
|
*/ |
335
|
|
|
public function isUnlimited() |
336
|
|
|
{ |
337
|
|
|
return $this->unlimited; |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
/** |
341
|
|
|
* @param bool $unlimited |
342
|
|
|
* |
343
|
|
|
* @return $this |
344
|
|
|
*/ |
345
|
|
|
public function setUnlimited($unlimited) |
346
|
|
|
{ |
347
|
|
|
$this->unlimited = $unlimited; |
348
|
|
|
|
349
|
|
|
return $this; |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
/** |
353
|
|
|
* @return string |
354
|
|
|
*/ |
355
|
|
|
public function __toString() |
356
|
|
|
{ |
357
|
|
|
return $this->event->getName().'-'.$this->getName(); |
358
|
|
|
} |
359
|
|
|
} |
360
|
|
|
|