|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the feedback project. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Florian Moser <[email protected]> |
|
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 App\Entity; |
|
13
|
|
|
|
|
14
|
|
|
use App\Entity\Base\BaseEntity; |
|
15
|
|
|
use App\Entity\Traits\IdTrait; |
|
16
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
17
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* an event determines how the questionnaire looks like. |
|
21
|
|
|
* |
|
22
|
|
|
* @ORM\Entity() |
|
23
|
|
|
* @ORM\HasLifecycleCallbacks |
|
24
|
|
|
*/ |
|
25
|
|
|
class Event extends BaseEntity |
|
26
|
|
|
{ |
|
27
|
|
|
use IdTrait; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var string |
|
31
|
|
|
* |
|
32
|
|
|
* @ORM\Column(type="text") |
|
33
|
|
|
*/ |
|
34
|
|
|
private $name; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var string |
|
38
|
|
|
* |
|
39
|
|
|
* @ORM\Column(type="text") |
|
40
|
|
|
*/ |
|
41
|
|
|
private $date; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var string |
|
45
|
|
|
* |
|
46
|
|
|
* @ORM\Column(type="text") |
|
47
|
|
|
*/ |
|
48
|
|
|
private $feedbackStartTime; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var string |
|
52
|
|
|
* |
|
53
|
|
|
* @ORM\Column(type="text") |
|
54
|
|
|
*/ |
|
55
|
|
|
private $feedbackEndTime; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @var string |
|
59
|
|
|
* |
|
60
|
|
|
* @ORM\Column(type="text") |
|
61
|
|
|
*/ |
|
62
|
|
|
private $template; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @var string |
|
66
|
|
|
* |
|
67
|
|
|
* @ORM\Column(type="text") |
|
68
|
|
|
*/ |
|
69
|
|
|
private $templateName; |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @var bool |
|
73
|
|
|
* |
|
74
|
|
|
* @ORM\Column(type="boolean") |
|
75
|
|
|
*/ |
|
76
|
|
|
private $hasLecture = false; |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @var bool |
|
80
|
|
|
* |
|
81
|
|
|
* @ORM\Column(type="boolean") |
|
82
|
|
|
*/ |
|
83
|
|
|
private $hasExercise = false; |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @var bool |
|
87
|
|
|
* |
|
88
|
|
|
* @ORM\Column(type="boolean") |
|
89
|
|
|
*/ |
|
90
|
|
|
private $finalTemplateVersionLoaded = false; |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @var Participant[]|ArrayCollection |
|
94
|
|
|
* |
|
95
|
|
|
* @ORM\OneToMany(targetEntity="App\Entity\Participant", mappedBy="event") |
|
96
|
|
|
*/ |
|
97
|
|
|
private $participants; |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @var Semester |
|
101
|
|
|
* |
|
102
|
|
|
* @ORM\ManyToOne(targetEntity="App\Entity\Semester", inversedBy="events") |
|
103
|
|
|
*/ |
|
104
|
|
|
private $semester; |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Event constructor. |
|
108
|
|
|
*/ |
|
109
|
|
|
public function __construct() |
|
110
|
|
|
{ |
|
111
|
|
|
$this->participants = new ArrayCollection(); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
public function getName(): string |
|
115
|
|
|
{ |
|
116
|
|
|
return $this->name; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function setName(string $name): void |
|
120
|
|
|
{ |
|
121
|
|
|
$this->name = $name; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
public function getFeedbackStartTime(): string |
|
125
|
|
|
{ |
|
126
|
|
|
return $this->feedbackStartTime; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
public function setFeedbackStartTime(string $feedbackStartTime): void |
|
130
|
|
|
{ |
|
131
|
|
|
$this->feedbackStartTime = $feedbackStartTime; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
public function getFeedbackEndTime(): string |
|
135
|
|
|
{ |
|
136
|
|
|
return $this->feedbackEndTime; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
public function setFeedbackEndTime(string $feedbackEndTime): void |
|
140
|
|
|
{ |
|
141
|
|
|
$this->feedbackEndTime = $feedbackEndTime; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
public function getTemplate(): string |
|
145
|
|
|
{ |
|
146
|
|
|
return $this->template; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
public function setTemplate(string $template): void |
|
150
|
|
|
{ |
|
151
|
|
|
$this->template = $template; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
public function getHasLecture(): bool |
|
155
|
|
|
{ |
|
156
|
|
|
return $this->hasLecture; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
public function setHasLecture(bool $hasLecture): void |
|
160
|
|
|
{ |
|
161
|
|
|
$this->hasLecture = $hasLecture; |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
public function getHasExercise(): bool |
|
165
|
|
|
{ |
|
166
|
|
|
return $this->hasExercise; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
public function setHasExercise(bool $hasExercise): void |
|
170
|
|
|
{ |
|
171
|
|
|
$this->hasExercise = $hasExercise; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* @return Participant[]|ArrayCollection |
|
176
|
|
|
*/ |
|
177
|
|
|
public function getParticipants() |
|
178
|
|
|
{ |
|
179
|
|
|
return $this->participants; |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
public function getDate(): string |
|
183
|
|
|
{ |
|
184
|
|
|
return $this->date; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
public function setDate(string $date): void |
|
188
|
|
|
{ |
|
189
|
|
|
$this->date = $date; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
public function getTemplateName(): string |
|
193
|
|
|
{ |
|
194
|
|
|
return $this->templateName; |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
public function setTemplateName(string $templateName): void |
|
198
|
|
|
{ |
|
199
|
|
|
$this->templateName = $templateName; |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
public function getSemester(): Semester |
|
203
|
|
|
{ |
|
204
|
|
|
return $this->semester; |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
public function setSemester(Semester $semester): void |
|
208
|
|
|
{ |
|
209
|
|
|
$this->semester = $semester; |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* which categories should be displayed to the user. |
|
214
|
|
|
* |
|
215
|
|
|
* @return array |
|
216
|
|
|
*/ |
|
217
|
|
|
public function getCategoryWhitelist() |
|
218
|
|
|
{ |
|
219
|
|
|
$base = ['event']; |
|
220
|
|
|
if ($this->getHasExercise()) { |
|
221
|
|
|
$base[] = 'exercise'; |
|
222
|
|
|
} |
|
223
|
|
|
if ($this->getHasLecture()) { |
|
224
|
|
|
$base[] = 'lecture'; |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
return $base; |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
public function isFinalTemplateVersionLoaded(): bool |
|
231
|
|
|
{ |
|
232
|
|
|
return $this->finalTemplateVersionLoaded; |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
public function setFinalTemplateVersionLoaded(bool $finalTemplateVersionLoaded): void |
|
236
|
|
|
{ |
|
237
|
|
|
$this->finalTemplateVersionLoaded = $finalTemplateVersionLoaded; |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
/** |
|
241
|
|
|
* @return bool |
|
242
|
|
|
*/ |
|
243
|
|
|
public function feedbackHasStarted() |
|
244
|
|
|
{ |
|
245
|
|
|
$now = new \DateTime(); |
|
246
|
|
|
$today = $now->format('Y-m-d'); |
|
247
|
|
|
$time = $now->format('H:i'); |
|
248
|
|
|
|
|
249
|
|
|
return $today > $this->getDate() || ($today === $this->getDate() && $time >= $this->getFeedbackStartTime()); |
|
250
|
|
|
} |
|
251
|
|
|
|
|
252
|
|
|
/** |
|
253
|
|
|
* @return string |
|
254
|
|
|
*/ |
|
255
|
|
|
public function getTemplateFilePath() |
|
256
|
|
|
{ |
|
257
|
|
|
return 'templates/' . $this->getTemplateName(); |
|
258
|
|
|
} |
|
259
|
|
|
|
|
260
|
|
|
/** |
|
261
|
|
|
* @param $publicDir |
|
262
|
|
|
*/ |
|
263
|
|
|
public function loadTemplateIfSafe($publicDir) |
|
264
|
|
|
{ |
|
265
|
|
|
if ($this->finalTemplateVersionLoaded) { |
|
266
|
|
|
return; |
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
|
|
if ($this->feedbackHasStarted()) { |
|
270
|
|
|
$this->finalTemplateVersionLoaded = true; |
|
271
|
|
|
} |
|
272
|
|
|
|
|
273
|
|
|
$filePath = $publicDir . '/' . $this->getTemplateFilePath(); |
|
274
|
|
|
if (file_exists($filePath)) { |
|
275
|
|
|
$this->template = file_get_contents($filePath); |
|
276
|
|
|
} |
|
277
|
|
|
} |
|
278
|
|
|
|
|
279
|
|
|
/** |
|
280
|
|
|
* @return Answer[] |
|
281
|
|
|
*/ |
|
282
|
|
|
public function getPublicFeedback() |
|
283
|
|
|
{ |
|
284
|
|
|
//to preserve privacy, no feedback shown if not enough participants |
|
285
|
|
|
if ($this->getParticipants()->count() <= 5) { |
|
286
|
|
|
return []; |
|
287
|
|
|
} |
|
288
|
|
|
|
|
289
|
|
|
$feedback = []; |
|
290
|
|
|
foreach ($this->getParticipants() as $participant) { |
|
291
|
|
|
foreach ($participant->getAnswers() as $answer) { |
|
292
|
|
|
if (!$answer->isPrivate()) { |
|
293
|
|
|
$feedback[] = $answer; |
|
294
|
|
|
} |
|
295
|
|
|
} |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
return $feedback; |
|
299
|
|
|
} |
|
300
|
|
|
} |
|
301
|
|
|
|