1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: device |
5
|
|
|
* Date: 23.02.16 |
6
|
|
|
* Time: 10:01 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace AppBundle\Entity; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
use Doctrine\Common\Collections\Criteria; |
13
|
|
|
use Doctrine\ORM\Mapping as ORM; |
14
|
|
|
use Gedmo\Mapping\Annotation as Gedmo; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* PassModule |
18
|
|
|
* |
19
|
|
|
* @ORM\Table(name="pass_module") |
20
|
|
|
* @ORM\Entity(repositoryClass="AppBundle\Repository\PassModuleRepository") |
21
|
|
|
*/ |
22
|
|
|
class PassModule implements \JsonSerializable |
23
|
|
|
{ |
24
|
|
|
const STATE_PASSED = 'passed'; |
25
|
|
|
const STATE_FAILED = 'failed'; |
26
|
|
|
const STATE_EXPIRED = 'expired'; |
27
|
|
|
/** |
28
|
|
|
* @ORM\Id |
29
|
|
|
* @ORM\GeneratedValue |
30
|
|
|
* @ORM\Column(type="integer") |
31
|
|
|
*/ |
32
|
|
|
private $id; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @ORM\Column(name="rating", type="float") |
36
|
|
|
*/ |
37
|
|
|
private $rating; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @ORM\Column(name="time_start", type="datetime") |
41
|
|
|
* @Gedmo\Timestampable(on="create") |
42
|
|
|
*/ |
43
|
|
|
private $timeStart; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @ORM\Column(name="time_finish", type="datetime", nullable=true) |
47
|
|
|
*/ |
48
|
|
|
private $timeFinish; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @ORM\Column(name="time_period", type="integer") |
52
|
|
|
*/ |
53
|
|
|
private $timePeriod; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @ORM\Column(name="is_active", type="boolean") |
57
|
|
|
*/ |
58
|
|
|
private $isActive; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\ModuleUser", inversedBy="passModules") |
62
|
|
|
*/ |
63
|
|
|
private $moduleUser; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Question", inversedBy="passModules") |
67
|
|
|
* @ORM\JoinColumn(onDelete="SET NULL") |
68
|
|
|
*/ |
69
|
|
|
private $currentQuestion; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @ORM\Column(type="array") |
73
|
|
|
*/ |
74
|
|
|
private $answeredQuestionIds; |
75
|
|
|
|
76
|
|
|
public function jsonSerialize() |
77
|
|
|
{ |
78
|
|
|
return [ |
79
|
|
|
'result' => $this->getAbsoluteResult(), |
80
|
|
|
'percent' => $this->getPercentResult(), |
81
|
|
|
'rating' => $this->getRating(), |
82
|
|
|
'timeStart' => $this->getTimeStart(), |
83
|
|
|
'timeFinish' => $this->getTimeFinish() |
84
|
|
|
]; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
|
88
|
27 |
|
public function __construct() |
89
|
|
|
{ |
90
|
27 |
|
$this->isActive = true; |
91
|
27 |
|
$this->rating = 0; |
92
|
27 |
|
$this->answeredQuestionIds = []; |
93
|
27 |
|
} |
94
|
|
|
|
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return mixed |
98
|
|
|
*/ |
99
|
1 |
|
public function getId() |
100
|
|
|
{ |
101
|
1 |
|
return $this->id; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return mixed |
106
|
|
|
*/ |
107
|
|
|
public function getRating() |
108
|
|
|
{ |
109
|
|
|
return $this->rating; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @param mixed $rating |
114
|
|
|
*/ |
115
|
27 |
|
public function setRating($rating) |
116
|
|
|
{ |
117
|
27 |
|
$this->rating = $rating; |
118
|
27 |
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @param mixed $rating |
122
|
|
|
*/ |
123
|
|
|
public function addRating($rating) |
124
|
|
|
{ |
125
|
|
|
$this->rating += $rating; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @return mixed |
130
|
|
|
*/ |
131
|
2 |
|
public function getTimeStart() |
132
|
|
|
{ |
133
|
2 |
|
return $this->timeStart; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @param mixed $timeStart |
138
|
|
|
*/ |
139
|
|
|
public function setTimeStart($timeStart) |
140
|
|
|
{ |
141
|
|
|
$this->timeStart = $timeStart; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @return mixed |
146
|
|
|
*/ |
147
|
|
|
public function getTimeFinish() |
148
|
|
|
{ |
149
|
|
|
return $this->timeFinish; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @param mixed $timeFinish |
154
|
|
|
*/ |
155
|
|
|
public function setTimeFinish($timeFinish) |
156
|
|
|
{ |
157
|
|
|
$this->timeFinish = $timeFinish; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @return mixed |
162
|
|
|
*/ |
163
|
2 |
|
public function getIsActive() |
164
|
|
|
{ |
165
|
2 |
|
return $this->isActive; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @param mixed $isActive |
170
|
|
|
*/ |
171
|
27 |
|
public function setIsActive($isActive) |
172
|
|
|
{ |
173
|
27 |
|
$this->isActive = $isActive; |
174
|
27 |
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @return mixed |
178
|
|
|
*/ |
179
|
2 |
|
public function getTimePeriod() |
180
|
|
|
{ |
181
|
2 |
|
return $this->timePeriod; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @param mixed $timePeriod |
186
|
|
|
*/ |
187
|
27 |
|
public function setTimePeriod($timePeriod) |
188
|
|
|
{ |
189
|
27 |
|
$this->timePeriod = $timePeriod; |
190
|
27 |
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @return mixed |
194
|
|
|
*/ |
195
|
2 |
|
public function getModuleUser() |
196
|
|
|
{ |
197
|
2 |
|
return $this->moduleUser; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @param mixed $moduleUser |
202
|
|
|
*/ |
203
|
27 |
|
public function setModuleUser(ModuleUser $moduleUser = null) |
204
|
|
|
{ |
205
|
27 |
|
$this->moduleUser = $moduleUser; |
206
|
27 |
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* @return mixed |
210
|
|
|
*/ |
211
|
1 |
|
public function getCurrentQuestion() |
212
|
|
|
{ |
213
|
1 |
|
return $this->currentQuestion; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* @param mixed $question |
218
|
|
|
*/ |
219
|
27 |
|
public function setCurrentQuestion(Question $question = null) |
220
|
|
|
{ |
221
|
27 |
|
$this->currentQuestion = $question; |
222
|
27 |
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* @return mixed |
226
|
|
|
*/ |
227
|
|
|
public function getAnsweredQuestionIds() |
228
|
|
|
{ |
229
|
|
|
return $this->answeredQuestionIds; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* @param $questionId |
234
|
|
|
* @return $this |
235
|
|
|
* @internal param Question $question |
236
|
|
|
*/ |
237
|
|
|
public function addAnsweredQuestionId($questionId) |
238
|
|
|
{ |
239
|
|
|
$this->answeredQuestionIds[] = $questionId; |
240
|
|
|
|
241
|
|
|
return $this; |
242
|
|
|
} |
243
|
|
|
|
244
|
1 |
|
public function getCountPassedQuestions() |
245
|
|
|
{ |
246
|
1 |
|
return count($this->answeredQuestionIds); |
247
|
|
|
} |
248
|
|
|
|
249
|
1 |
|
public function getAbsoluteResult() |
250
|
|
|
{ |
251
|
1 |
|
$countQuestions = $this->getModuleUser()->getModule()->getCountQuestions(); |
252
|
1 |
|
$maxResult = $this->getModuleUser()->getModule()->getRating(); |
253
|
1 |
|
return $this->rating * $maxResult / $countQuestions ; |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
public function getPercentResult() |
257
|
|
|
{ |
258
|
|
|
$countQuestions = $this->getModuleUser()->getModule()->getCountQuestions(); |
259
|
|
|
return $this->rating * 100 / $countQuestions ; |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
public function getStateResult() |
263
|
|
|
{ |
264
|
|
|
if($this->timeFinish === null) |
265
|
|
|
return self::STATE_EXPIRED; |
266
|
|
|
|
267
|
|
|
return $this->getPercentResult() >= $this->getModuleUser()->getModule()->getPersentSuccess() ? |
268
|
|
|
self::STATE_PASSED : self::STATE_FAILED; |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
} |
272
|
|
|
|