|
1
|
|
|
<?php |
|
2
|
|
|
namespace PlaygroundGame\Entity; |
|
3
|
|
|
|
|
4
|
|
|
use PlaygroundGame\Entity\Game; |
|
5
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
6
|
|
|
use Doctrine\ORM\Mapping\HasLifecycleCallbacks; |
|
7
|
|
|
use Zend\InputFilter\InputFilter; |
|
8
|
|
|
use Zend\InputFilter\Factory as InputFactory; |
|
9
|
|
|
use Zend\InputFilter\InputFilterAwareInterface; |
|
10
|
|
|
use Zend\InputFilter\InputFilterInterface; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @ORM\Entity @HasLifecycleCallbacks |
|
14
|
|
|
* @ORM\Table(name="game_quiz") |
|
15
|
|
|
*/ |
|
16
|
|
|
class Quiz extends Game implements InputFilterAwareInterface |
|
17
|
|
|
{ |
|
18
|
|
|
const CLASSTYPE = 'quiz'; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Automatic Draw |
|
22
|
|
|
* @ORM\Column(name="draw_auto", type="boolean", nullable=false) |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $drawAuto = 0; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @ORM\Column(type="integer", nullable=false) |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $winners = 0; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @ORM\Column(type="integer", nullable=false) |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $substitutes = 0; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* display the stats about the quiz (how many entries + distribution of each answer |
|
38
|
|
|
* ) |
|
39
|
|
|
* entry : After each entry |
|
40
|
|
|
* game : At the end of the game |
|
41
|
|
|
* never : ... |
|
42
|
|
|
* |
|
43
|
|
|
* @ORM\Column(name="display_stats", type="string", nullable=false) |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $displayStats = 'never'; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* display the good answers |
|
49
|
|
|
* |
|
50
|
|
|
* question : After the answer to the question |
|
51
|
|
|
* entry : after each entry |
|
52
|
|
|
* game : at the end of the game |
|
53
|
|
|
* never : ... |
|
54
|
|
|
* |
|
55
|
|
|
* @ORM\Column(name="display_good_answers", type="string", nullable=false) |
|
56
|
|
|
*/ |
|
57
|
|
|
protected $displayGoodAnswers = 'never'; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @ORM\Column(type="boolean", nullable=false) |
|
61
|
|
|
*/ |
|
62
|
|
|
protected $timer = 0; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @ORM\Column(name="timer_duration", type="integer", nullable=false) |
|
66
|
|
|
*/ |
|
67
|
|
|
protected $timerDuration = 0; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @ORM\Column(name="question_grouping", type="integer", nullable=false) |
|
71
|
|
|
*/ |
|
72
|
|
|
protected $questionGrouping = 0; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @ORM\Column(name="victory_conditions", type="integer", nullable=false) |
|
76
|
|
|
*/ |
|
77
|
|
|
protected $victoryConditions = 0; |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @ORM\Column(name="max_points", type="integer", nullable=true) |
|
81
|
|
|
*/ |
|
82
|
|
|
protected $maxPoints = 0; |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @ORM\Column(name="max_correct_answers", type="integer", nullable=true) |
|
86
|
|
|
*/ |
|
87
|
|
|
protected $maxCorrectAnswers = 0; |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @ORM\OneToMany(targetEntity="QuizQuestion", mappedBy="quiz", cascade={"persist","remove"}) |
|
91
|
|
|
* @ORM\OrderBy({"position" = "ASC"}) |
|
92
|
|
|
**/ |
|
93
|
|
|
private $questions; |
|
94
|
|
|
|
|
95
|
|
|
public function __construct() |
|
96
|
|
|
{ |
|
97
|
|
|
parent::__construct(); |
|
98
|
|
|
$this->setClassType(self::CLASSTYPE); |
|
99
|
|
|
$this->questions = new \Doctrine\Common\Collections\ArrayCollection(); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @return string |
|
104
|
|
|
*/ |
|
105
|
|
|
public function getDisplayStats() |
|
106
|
|
|
{ |
|
107
|
|
|
return $this->displayStats; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @param string $displayStats |
|
112
|
|
|
*/ |
|
113
|
|
|
public function setDisplayStats($displayStats) |
|
114
|
|
|
{ |
|
115
|
|
|
$this->displayStats = $displayStats; |
|
116
|
|
|
|
|
117
|
|
|
return $this; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @return string |
|
122
|
|
|
*/ |
|
123
|
|
|
public function getDisplayGoodAnswers() |
|
124
|
|
|
{ |
|
125
|
|
|
return $this->displayGoodAnswers; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @param string $displayGoodAnswers |
|
130
|
|
|
*/ |
|
131
|
|
|
public function setDisplayGoodAnswers($displayGoodAnswers) |
|
132
|
|
|
{ |
|
133
|
|
|
$this->displayGoodAnswers = $displayGoodAnswers; |
|
134
|
|
|
|
|
135
|
|
|
return $this; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* @return integer |
|
140
|
|
|
*/ |
|
141
|
|
|
public function getDrawAuto() |
|
142
|
|
|
{ |
|
143
|
|
|
return $this->drawAuto; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* @param integer $drawAuto |
|
148
|
|
|
*/ |
|
149
|
|
|
public function setDrawAuto($drawAuto) |
|
150
|
|
|
{ |
|
151
|
|
|
$this->drawAuto = $drawAuto; |
|
152
|
|
|
|
|
153
|
|
|
return $this; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* @return integer |
|
158
|
|
|
*/ |
|
159
|
|
|
public function getWinners() |
|
160
|
|
|
{ |
|
161
|
|
|
return $this->winners; |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* @param integer $winners |
|
166
|
|
|
*/ |
|
167
|
|
|
public function setWinners($winners) |
|
168
|
|
|
{ |
|
169
|
|
|
$this->winners = $winners; |
|
170
|
|
|
|
|
171
|
|
|
return $this; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* @return integer |
|
176
|
|
|
*/ |
|
177
|
|
|
public function getSubstitutes() |
|
178
|
|
|
{ |
|
179
|
|
|
return $this->substitutes; |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* @param integer $substitutes |
|
184
|
|
|
*/ |
|
185
|
|
|
public function setSubstitutes($substitutes) |
|
186
|
|
|
{ |
|
187
|
|
|
$this->substitutes = $substitutes; |
|
188
|
|
|
|
|
189
|
|
|
return $this; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
/** |
|
193
|
|
|
* @return integer unknown_type |
|
194
|
|
|
*/ |
|
195
|
|
|
public function getTimer() |
|
196
|
|
|
{ |
|
197
|
|
|
return $this->timer; |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* @param unknown_type $timer |
|
202
|
|
|
*/ |
|
203
|
|
|
public function setTimer($timer) |
|
204
|
|
|
{ |
|
205
|
|
|
$this->timer = $timer; |
|
|
|
|
|
|
206
|
|
|
|
|
207
|
|
|
return $this; |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
/** |
|
211
|
|
|
* @return integer unknown_type |
|
212
|
|
|
*/ |
|
213
|
|
|
public function getTimerDuration() |
|
214
|
|
|
{ |
|
215
|
|
|
return $this->timerDuration; |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
/** |
|
219
|
|
|
* @param unknown_type $timerDuration |
|
220
|
|
|
*/ |
|
221
|
|
|
public function setTimerDuration($timerDuration) |
|
222
|
|
|
{ |
|
223
|
|
|
$this->timerDuration = $timerDuration; |
|
|
|
|
|
|
224
|
|
|
|
|
225
|
|
|
return $this; |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
public function getVictoryConditions() |
|
229
|
|
|
{ |
|
230
|
|
|
return $this->victoryConditions; |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
/** |
|
234
|
|
|
*/ |
|
235
|
|
|
public function setVictoryConditions($victoryConditions) |
|
236
|
|
|
{ |
|
237
|
|
|
$this->victoryConditions = $victoryConditions; |
|
238
|
|
|
|
|
239
|
|
|
return $this; |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
/** |
|
243
|
|
|
* @return integer unknown_type |
|
244
|
|
|
*/ |
|
245
|
|
|
public function getQuestionGrouping() |
|
246
|
|
|
{ |
|
247
|
|
|
return $this->questionGrouping; |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
/** |
|
251
|
|
|
* @param unknown_type $questionGrouping |
|
252
|
|
|
*/ |
|
253
|
|
|
public function setQuestionGrouping($questionGrouping) |
|
254
|
|
|
{ |
|
255
|
|
|
$this->questionGrouping = $questionGrouping; |
|
|
|
|
|
|
256
|
|
|
|
|
257
|
|
|
return $this; |
|
258
|
|
|
} |
|
259
|
|
|
|
|
260
|
|
|
/** |
|
261
|
|
|
* @param unknown_type $questions |
|
262
|
|
|
*/ |
|
263
|
|
|
public function setQuestions($questions) |
|
264
|
|
|
{ |
|
265
|
|
|
$this->questions = $questions; |
|
266
|
|
|
|
|
267
|
|
|
return $this; |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
/** |
|
271
|
|
|
* @return integer |
|
272
|
|
|
*/ |
|
273
|
|
|
public function getMaxPoints() |
|
274
|
|
|
{ |
|
275
|
|
|
return $this->maxPoints; |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
/** |
|
279
|
|
|
* @param integer maxPoints |
|
280
|
|
|
*/ |
|
281
|
|
|
public function setMaxPoints($maxPoints) |
|
282
|
|
|
{ |
|
283
|
|
|
$this->maxPoints = $maxPoints; |
|
284
|
|
|
|
|
285
|
|
|
return $this; |
|
286
|
|
|
} |
|
287
|
|
|
|
|
288
|
|
|
/** |
|
289
|
|
|
* @return integer |
|
290
|
|
|
*/ |
|
291
|
|
|
public function getMaxCorrectAnswers() |
|
292
|
|
|
{ |
|
293
|
|
|
return $this->maxCorrectAnswers; |
|
294
|
|
|
} |
|
295
|
|
|
|
|
296
|
|
|
/** |
|
297
|
|
|
* @param integer maxCorrectAnswers |
|
298
|
|
|
*/ |
|
299
|
|
|
public function setMaxCorrectAnswers($maxCorrectAnswers) |
|
300
|
|
|
{ |
|
301
|
|
|
$this->maxCorrectAnswers = $maxCorrectAnswers; |
|
302
|
|
|
|
|
303
|
|
|
return $this; |
|
304
|
|
|
} |
|
305
|
|
|
|
|
306
|
|
|
/** |
|
307
|
|
|
* Get question. |
|
308
|
|
|
* |
|
309
|
|
|
* @return \Doctrine\Common\Collections\Collection |
|
310
|
|
|
*/ |
|
311
|
|
|
public function getQuestions() |
|
312
|
|
|
{ |
|
313
|
|
|
return $this->questions; |
|
314
|
|
|
} |
|
315
|
|
|
|
|
316
|
|
|
/** |
|
317
|
|
|
* Add a question to the quiz. |
|
318
|
|
|
* |
|
319
|
|
|
* @param QuizQuestion $question |
|
320
|
|
|
* |
|
321
|
|
|
* @return void |
|
322
|
|
|
*/ |
|
323
|
|
|
public function addQuestion($question) |
|
324
|
|
|
{ |
|
325
|
|
|
$this->questions[] = $question; |
|
326
|
|
|
} |
|
327
|
|
|
|
|
328
|
|
|
/** |
|
329
|
|
|
* Convert the object to an array. |
|
330
|
|
|
* |
|
331
|
|
|
* @return array |
|
332
|
|
|
*/ |
|
333
|
|
|
public function getArrayCopy() |
|
334
|
|
|
{ |
|
335
|
|
|
$obj_vars = parent::getArrayCopy(); |
|
336
|
|
|
array_merge($obj_vars, get_object_vars($this)); |
|
337
|
|
|
|
|
338
|
|
|
return $obj_vars; |
|
339
|
|
|
} |
|
340
|
|
|
|
|
341
|
|
|
/** |
|
342
|
|
|
* Populate from an array. |
|
343
|
|
|
* |
|
344
|
|
|
* @param array $data |
|
345
|
|
|
*/ |
|
346
|
|
|
public function populate($data = array()) |
|
347
|
|
|
{ |
|
348
|
|
|
parent::populate($data); |
|
349
|
|
|
|
|
350
|
|
|
if (isset($data['winners']) && $data['winners'] !== null) { |
|
351
|
|
|
$this->winners = $data['winners']; |
|
352
|
|
|
} |
|
353
|
|
|
|
|
354
|
|
View Code Duplication |
if (isset($data['timer']) && $data['timer'] !== null) { |
|
|
|
|
|
|
355
|
|
|
$this->timer = $data['timer']; |
|
356
|
|
|
} |
|
357
|
|
|
if (isset($data['timerDuration']) && $data['timerDuration'] !== null) { |
|
358
|
|
|
$this->timerDuration = $data['timerDuration']; |
|
359
|
|
|
} |
|
360
|
|
|
if (isset($data['questionGrouping']) && $data['questionGrouping'] !== null) { |
|
361
|
|
|
$this->questionGrouping = $data['questionGrouping']; |
|
362
|
|
|
} |
|
363
|
|
|
|
|
364
|
|
|
if (isset($data['maxPoints']) && $data['maxPoints'] !== null) { |
|
365
|
|
|
$this->maxPoints = $data['maxPoints']; |
|
366
|
|
|
} |
|
367
|
|
|
|
|
368
|
|
|
if (isset($data['maxCorrectAnswers']) && $data['maxCorrectAnswers'] !== null) { |
|
369
|
|
|
$this->maxCorrectAnswers = $data['maxCorrectAnswers']; |
|
370
|
|
|
} |
|
371
|
|
|
|
|
372
|
|
|
if (isset($data['displayGoodAnswers']) && $data['displayGoodAnswers'] !== null) { |
|
373
|
|
|
$this->displayGoodAnswers = $data['displayGoodAnswers']; |
|
374
|
|
|
} |
|
375
|
|
|
|
|
376
|
|
|
if (isset($data['displayStats']) && $data['displayStats'] !== null) { |
|
377
|
|
|
$this->displayStats = $data['displayStats']; |
|
378
|
|
|
} |
|
379
|
|
|
} |
|
380
|
|
|
|
|
381
|
|
|
public function setInputFilter(InputFilterInterface $inputFilter) |
|
382
|
|
|
{ |
|
383
|
|
|
throw new \Exception("Not used"); |
|
384
|
|
|
} |
|
385
|
|
|
|
|
386
|
|
|
public function getInputFilter() |
|
387
|
|
|
{ |
|
388
|
|
|
if (!$this->inputFilter) { |
|
389
|
|
|
$inputFilter = new InputFilter(); |
|
|
|
|
|
|
390
|
|
|
$factory = new InputFactory(); |
|
391
|
|
|
|
|
392
|
|
|
$inputFilter = parent::getInputFilter(); |
|
393
|
|
|
|
|
394
|
|
|
$inputFilter->add($factory->createInput(array( |
|
395
|
|
|
'name' => 'id', |
|
396
|
|
|
'required' => true, |
|
397
|
|
|
'filters' => array( |
|
398
|
|
|
array('name' => 'Int'), |
|
399
|
|
|
), |
|
400
|
|
|
))); |
|
401
|
|
|
|
|
402
|
|
|
$inputFilter->add($factory->createInput(array( |
|
403
|
|
|
'name' => 'title', |
|
404
|
|
|
'required' => true, |
|
405
|
|
|
'filters' => array( |
|
406
|
|
|
array('name' => 'StripTags'), |
|
407
|
|
|
array('name' => 'StringTrim'), |
|
408
|
|
|
), |
|
409
|
|
|
'validators' => array( |
|
410
|
|
|
array( |
|
411
|
|
|
'name' => 'StringLength', |
|
412
|
|
|
'options' => array( |
|
413
|
|
|
'encoding' => 'UTF-8', |
|
414
|
|
|
'min' => 5, |
|
415
|
|
|
'max' => 255, |
|
416
|
|
|
|
|
417
|
|
|
), |
|
418
|
|
|
), |
|
419
|
|
|
), |
|
420
|
|
|
))); |
|
421
|
|
|
|
|
422
|
|
|
$inputFilter->add($factory->createInput(array( |
|
423
|
|
|
'name' => 'timer', |
|
424
|
|
|
'required' => false |
|
425
|
|
|
))); |
|
426
|
|
|
|
|
427
|
|
|
$inputFilter->add($factory->createInput(array( |
|
428
|
|
|
'name' => 'displayGoodAnswers', |
|
429
|
|
|
'required' => false |
|
430
|
|
|
))); |
|
431
|
|
|
|
|
432
|
|
|
$inputFilter->add($factory->createInput(array( |
|
433
|
|
|
'name' => 'displayStats', |
|
434
|
|
|
'required' => false |
|
435
|
|
|
))); |
|
436
|
|
|
|
|
437
|
|
|
$inputFilter->add($factory->createInput(array( |
|
438
|
|
|
'name' => 'identifier', |
|
439
|
|
|
'required' => true, |
|
440
|
|
|
'filters' => array( |
|
441
|
|
|
array('name' => 'StripTags'), |
|
442
|
|
|
array('name' => 'StringTrim'), |
|
443
|
|
|
array('name' => 'PlaygroundCore\Filter\Slugify'), |
|
444
|
|
|
), |
|
445
|
|
|
'validators' => array( |
|
446
|
|
|
array( |
|
447
|
|
|
'name' => 'StringLength', |
|
448
|
|
|
'options' => array( |
|
449
|
|
|
'encoding' => 'UTF-8', |
|
450
|
|
|
'min' => 5, |
|
451
|
|
|
'max' => 255, |
|
452
|
|
|
), |
|
453
|
|
|
), |
|
454
|
|
|
), |
|
455
|
|
|
))); |
|
456
|
|
|
|
|
457
|
|
|
$inputFilter->add($factory->createInput(array( |
|
458
|
|
|
'name' => 'winners', |
|
459
|
|
|
'required' => true, |
|
460
|
|
|
'validators' => array( |
|
461
|
|
|
array('name' => 'NotEmpty', ), |
|
462
|
|
|
array('name' => 'Int'), |
|
463
|
|
|
), |
|
464
|
|
|
))); |
|
465
|
|
|
|
|
466
|
|
|
$inputFilter->add($factory->createInput(array( |
|
467
|
|
|
'name' => 'substitutes', |
|
468
|
|
|
'required' => true, |
|
469
|
|
|
'validators' => array( |
|
470
|
|
|
array('name' => 'NotEmpty', ), |
|
471
|
|
|
array('name' => 'Int'), |
|
472
|
|
|
), |
|
473
|
|
|
))); |
|
474
|
|
|
|
|
475
|
|
|
$inputFilter->add($factory->createInput(array( |
|
476
|
|
|
'name' => 'victoryConditions', |
|
477
|
|
|
'required' => false, |
|
478
|
|
|
'validators' => array( |
|
479
|
|
|
array('name' => 'Digits', ), |
|
480
|
|
|
array('name' => 'Int'), |
|
481
|
|
|
), |
|
482
|
|
|
))); |
|
483
|
|
|
|
|
484
|
|
|
$this->inputFilter = $inputFilter; |
|
485
|
|
|
} |
|
486
|
|
|
|
|
487
|
|
|
return $this->inputFilter; |
|
488
|
|
|
} |
|
489
|
|
|
} |
|
490
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..