|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Components\Forms; |
|
4
|
|
|
|
|
5
|
|
|
use App\Repositories\ProgramRepository; |
|
6
|
|
|
use App\Models\ProvinceModel; |
|
7
|
|
|
use App\Models\BlockModel; |
|
8
|
|
|
use App\Models\MealModel; |
|
9
|
|
|
use App\Models\MeetingModel; |
|
10
|
|
|
use Nette\Application\UI\Form; |
|
11
|
|
|
use App\Services\SkautIS\UserService; |
|
12
|
|
|
use Nette\Forms\Controls\SubmitButton; |
|
13
|
|
|
use Nette\Utils\ArrayHash; |
|
14
|
|
|
|
|
15
|
|
|
class VisitorForm extends BaseForm |
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
const TEMPLATE_NAME = 'VisitorForm'; |
|
19
|
|
|
|
|
20
|
|
|
const MESSAGE_REQUIRED = 'Hodnota musí být vyplněna!'; |
|
21
|
|
|
const MESSAGE_MAX_LENGTH = '%label nesmí mít více jak %d znaků!'; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var Closure |
|
25
|
|
|
*/ |
|
26
|
|
|
public $onVisitorSave; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var Closure |
|
30
|
|
|
*/ |
|
31
|
|
|
public $onVisitorReset; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var ProvinceModel |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $provinceModel; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var ProgramRepository |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $programRepository; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var BlockModel |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $blockModel; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @var MeetingModel |
|
50
|
|
|
*/ |
|
51
|
|
|
protected $meetingModel; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @var array |
|
55
|
|
|
*/ |
|
56
|
|
|
protected $mealFields = []; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @var array |
|
60
|
|
|
*/ |
|
61
|
|
|
protected $programFields = []; |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* VisitorForm constructor. |
|
65
|
|
|
* @param ProvinceModel $province |
|
66
|
|
|
* @param ProgramRepository $program |
|
67
|
|
|
* @param BlockModel $block |
|
68
|
|
|
* @param MeetingModel $meeting |
|
69
|
|
|
*/ |
|
70
|
|
View Code Duplication |
public function __construct( |
|
|
|
|
|
|
71
|
|
|
ProvinceModel $province, |
|
72
|
|
|
ProgramRepository $program, |
|
73
|
|
|
BlockModel $block, |
|
74
|
|
|
MeetingModel $meeting |
|
75
|
|
|
) { |
|
76
|
|
|
$this->setProvinceModel($province); |
|
77
|
|
|
$this->setProgramRepository($program); |
|
78
|
|
|
$this->setBlockModel($block); |
|
79
|
|
|
$this->setMeetingModel($meeting); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @return void |
|
84
|
|
|
*/ |
|
85
|
|
|
public function render() |
|
86
|
|
|
{ |
|
87
|
|
|
$this->setMealFields(); |
|
88
|
|
|
$this->setProgramFields(); |
|
89
|
|
|
|
|
90
|
|
|
$template = $this->getTemplate(); |
|
91
|
|
|
$template->setFile($this->buildTemplatePath()); |
|
92
|
|
|
$template->meals = $this->getMealFields(); |
|
|
|
|
|
|
93
|
|
|
$template->programs = $this->getProgramFields(); |
|
|
|
|
|
|
94
|
|
|
$template->render(); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @param array|ArrayHash $defaults |
|
99
|
|
|
* @return self |
|
100
|
|
|
*/ |
|
101
|
|
|
public function setDefaults($defaults): BaseForm |
|
102
|
|
|
{ |
|
103
|
|
|
$this['visitorForm']->setDefaults($defaults); |
|
104
|
|
|
|
|
105
|
|
|
return $this; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @return Form |
|
110
|
|
|
*/ |
|
111
|
|
|
public function createComponentVisitorForm(): Form |
|
112
|
|
|
{ |
|
113
|
|
|
$provinces = $this->getProvinceModel()->all(); |
|
114
|
|
|
|
|
115
|
|
|
$form = new Form; |
|
116
|
|
|
|
|
117
|
|
|
$form->addText('name', 'Jméno:', 30) |
|
118
|
|
|
->setRequired(static::MESSAGE_REQUIRED) |
|
|
|
|
|
|
119
|
|
|
->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 20) |
|
120
|
|
|
->getLabelPrototype()->setAttribute('class', 'required'); |
|
121
|
|
|
$form->addText('surname', 'Příjmení:', 30) |
|
122
|
|
|
->setRequired(static::MESSAGE_REQUIRED) |
|
|
|
|
|
|
123
|
|
|
->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 30) |
|
124
|
|
|
->getLabelPrototype()->setAttribute('class', 'required'); |
|
125
|
|
|
$form->addText('nick', 'Přezdívka:', 30) |
|
126
|
|
|
->setRequired(static::MESSAGE_REQUIRED) |
|
|
|
|
|
|
127
|
|
|
->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 20) |
|
128
|
|
|
->getLabelPrototype()->setAttribute('class', 'required'); |
|
129
|
|
|
$form->addEmail('email', 'E-mail:') |
|
130
|
|
|
->setRequired(static::MESSAGE_REQUIRED) |
|
|
|
|
|
|
131
|
|
|
->setAttribute('size', 30) |
|
|
|
|
|
|
132
|
|
|
->getLabelPrototype()->setAttribute('class', 'required'); |
|
133
|
|
|
$form->addTbDatePicker('birthday', 'Datum narození:', null, 16) |
|
134
|
|
|
->setRequired(static::MESSAGE_REQUIRED) |
|
135
|
|
|
->setFormat('d.m.Y') |
|
136
|
|
|
->setAttribute('placeholder', 'dd. mm. rrrr') |
|
137
|
|
|
->setAttribute('id', 'birthday') |
|
138
|
|
|
->setAttribute('class', 'datePicker') |
|
139
|
|
|
->getLabelPrototype()->setAttribute('class', 'required'); |
|
140
|
|
|
$form->addText('street', 'Ulice:', 30) |
|
141
|
|
|
->setRequired(static::MESSAGE_REQUIRED) |
|
|
|
|
|
|
142
|
|
|
->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 30) |
|
143
|
|
|
->getLabelPrototype()->setAttribute('class', 'required'); |
|
144
|
|
|
$form->addText('city', 'Město:', 30) |
|
145
|
|
|
->setRequired(static::MESSAGE_REQUIRED) |
|
|
|
|
|
|
146
|
|
|
->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 64) |
|
147
|
|
|
->getLabelPrototype()->setAttribute('class', 'required'); |
|
148
|
|
|
$form->addText('postal_code', 'PSČ:', 30) |
|
149
|
|
|
->setRequired(static::MESSAGE_REQUIRED) |
|
|
|
|
|
|
150
|
|
|
->addRule(Form::PATTERN, 'Číslo musí být ve formátu nnnnn!', '[1-9]{1}[0-9]{4}') |
|
151
|
|
|
->setAttribute('placeholder', '12345') |
|
|
|
|
|
|
152
|
|
|
->getLabelPrototype()->setAttribute('class', 'required'); |
|
153
|
|
|
$form->addText('group_num', 'Číslo středika/přístavu:', 30) |
|
154
|
|
|
->setRequired(static::MESSAGE_REQUIRED) |
|
|
|
|
|
|
155
|
|
|
->addRule(Form::PATTERN, 'Číslo musí být ve formátu nnn.nn!', '[1-9]{1}[0-9a-zA-Z]{2}\.[0-9a-zA-Z]{1}[0-9a-zA-Z]{1}') |
|
156
|
|
|
->setAttribute('placeholder', '214.02') |
|
|
|
|
|
|
157
|
|
|
->getLabelPrototype()->setAttribute('class', 'required'); |
|
158
|
|
|
$form->addText('group_name', 'Název střediska/přístavu:', 30) |
|
159
|
|
|
->setRequired(static::MESSAGE_REQUIRED) |
|
|
|
|
|
|
160
|
|
|
->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 50) |
|
161
|
|
|
->setAttribute('placeholder', '2. přístav Poutníci Kolín') |
|
|
|
|
|
|
162
|
|
|
->getLabelPrototype()->setAttribute('class', 'required'); |
|
163
|
|
|
$form->addText('troop_name', 'Název oddílu:', 30) |
|
164
|
|
|
->setAttribute('placeholder', '22. oddíl Galeje') |
|
|
|
|
|
|
165
|
|
|
->addCondition(Form::FILLED, true) |
|
166
|
|
|
->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 50); |
|
167
|
|
|
|
|
168
|
|
|
$form->addSelect('province', 'Kraj:', $provinces) |
|
169
|
|
|
->setPrompt('zvolte kraj'); |
|
170
|
|
|
|
|
171
|
|
|
$form = $this->buildMealSwitcher($form); |
|
172
|
|
|
|
|
173
|
|
|
$form->addTextArea('arrival', 'Informace o příjezdu:', 50, 3) |
|
174
|
|
|
->setAttribute('placeholder', 'Napište, prosím, stručně jakým dopravním prostředkem a v kolik hodin (přibližně) přijedete na místo srazu.'); |
|
|
|
|
|
|
175
|
|
|
$form->addTextArea('departure', 'Informace o odjezdu:', 50, 3) |
|
176
|
|
|
->setAttribute('placeholder', 'Napište, prosím, stručně jakým dopravním prostředkem a v kolik hodin (přibližně) sraz opustíte.'); |
|
|
|
|
|
|
177
|
|
|
$form->addTextArea('comment', 'Dotazy, přání, připomínky, stížnosti:', 50, 8); |
|
178
|
|
|
$form->addTextArea('question', 'Vaše nabídka:', 50, 8) |
|
179
|
|
|
->setAttribute('placeholder', 'Vaše nabídka na sdílení dobré praxe (co u vás umíte dobře a jste ochotni se o to podělit)'); |
|
|
|
|
|
|
180
|
|
|
$form->addTextArea('question2', 'Počet a typy lodí:', 50, 8) |
|
181
|
|
|
->setAttribute('placeholder', 'Počet a typy lodí, které sebou přivezete (vyplňte pokud ano)'); |
|
|
|
|
|
|
182
|
|
|
$form->addText('bill', 'Zaplaceno:', 30) |
|
183
|
|
|
->setDefaultValue(0); |
|
184
|
|
|
$form->addText('cost', 'Poplatek:', 30) |
|
185
|
|
|
->setDefaultValue($this->getMeetingModel()->getPrice('cost')); |
|
186
|
|
|
|
|
187
|
|
|
$form = $this->buildProgramSwitcher($form); |
|
188
|
|
|
|
|
189
|
|
|
$form->addHidden('mid', $this->getMeetingId()); |
|
190
|
|
|
$form->addHidden('meeting', $this->getMeetingId()); |
|
191
|
|
|
$form->addHidden('backlink'); |
|
192
|
|
|
|
|
193
|
|
|
$form->addSubmit('save', 'Uložit') |
|
194
|
|
|
->setAttribute('class', 'btn-primary') |
|
|
|
|
|
|
195
|
|
|
->onClick[] = [$this, 'processSave']; |
|
196
|
|
|
$form->addSubmit('reset', 'Storno') |
|
197
|
|
|
->setAttribute('class', 'btn-reset') |
|
|
|
|
|
|
198
|
|
|
->onClick[] = [$this, 'processReset']; |
|
199
|
|
|
|
|
200
|
|
|
|
|
201
|
|
|
$form = $this->setupRendering($form); |
|
202
|
|
|
|
|
203
|
|
|
$form->onSuccess[] = [$this, 'processForm']; |
|
204
|
|
|
|
|
205
|
|
|
return $form; |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
/** |
|
209
|
|
|
* @param SubmitButton $button |
|
210
|
|
|
* @return void |
|
211
|
|
|
*/ |
|
212
|
|
|
public function processSave(SubmitButton $button) |
|
213
|
|
|
{ |
|
214
|
|
|
$visitor = $button->getForm()->getValues(); |
|
|
|
|
|
|
215
|
|
|
|
|
216
|
|
|
$this->onVisitorSave($this, $visitor); |
|
|
|
|
|
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
/** |
|
220
|
|
|
* @param SubmitButton $button |
|
221
|
|
|
* @return void |
|
222
|
|
|
*/ |
|
223
|
|
|
public function processReset(SubmitButton $button) |
|
224
|
|
|
{ |
|
225
|
|
|
$visitor = $button->getForm()->getValues(); |
|
|
|
|
|
|
226
|
|
|
|
|
227
|
|
|
$this->onVisitorReset($this, $visitor); |
|
|
|
|
|
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
/** |
|
231
|
|
|
* @param Form $form |
|
232
|
|
|
* @return Form |
|
233
|
|
|
*/ |
|
234
|
|
|
protected function buildProgramSwitcher(Form $form): Form |
|
235
|
|
|
{ |
|
236
|
|
|
$programBlocks = $this->fetchProgramBlocks(); |
|
237
|
|
|
|
|
238
|
|
|
foreach ($programBlocks as $block) { |
|
239
|
|
|
|
|
240
|
|
|
$programsInBlock = $this->getProgramRepository()->findByBlockId($block->id); |
|
241
|
|
|
|
|
242
|
|
|
$programs = [ |
|
243
|
|
|
0 => 'Nebudu přítomen' |
|
244
|
|
|
]; |
|
245
|
|
|
|
|
246
|
|
|
foreach ($programsInBlock as $program) { |
|
247
|
|
|
$programs[$program->id] = $program->name; |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
$form->addRadioList( |
|
251
|
|
|
'blck_' . $block->id, |
|
252
|
|
|
$block->day . ', ' . $block->from .' - ' . $block->to .' : ' . $block->name, |
|
253
|
|
|
$programs |
|
254
|
|
|
)->setDefaultValue(0) |
|
255
|
|
|
->setDisabled($this->filterFilledCapacity($programs)); |
|
|
|
|
|
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
return $form; |
|
259
|
|
|
} |
|
260
|
|
|
|
|
261
|
|
|
/** |
|
262
|
|
|
* @param Form $form |
|
263
|
|
|
* @return Form |
|
264
|
|
|
*/ |
|
265
|
|
|
protected function buildMealSwitcher(Form $form): Form |
|
266
|
|
|
{ |
|
267
|
|
|
$yesNoArray = [ |
|
268
|
|
|
'ne' => 'ne', |
|
269
|
|
|
'ano' => 'ano', |
|
270
|
|
|
]; |
|
271
|
|
|
|
|
272
|
|
|
foreach ($this->fetchMeals() as $name => $label) { |
|
273
|
|
|
$this->setMealField($name); |
|
274
|
|
|
$form->addSelect($name, $label . ':', $yesNoArray); |
|
275
|
|
|
} |
|
276
|
|
|
|
|
277
|
|
|
return $form; |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
|
|
/** |
|
281
|
|
|
* @return ProvinceModel |
|
282
|
|
|
*/ |
|
283
|
|
|
protected function getProvinceModel(): ProvinceModel |
|
284
|
|
|
{ |
|
285
|
|
|
return $this->provinceModel; |
|
286
|
|
|
} |
|
287
|
|
|
|
|
288
|
|
|
/** |
|
289
|
|
|
* @param ProvinceModel $model |
|
290
|
|
|
* @return self |
|
291
|
|
|
*/ |
|
292
|
|
|
protected function setProvinceModel(ProvinceModel $model): self |
|
293
|
|
|
{ |
|
294
|
|
|
$this->provinceModel = $model; |
|
295
|
|
|
|
|
296
|
|
|
return $this; |
|
297
|
|
|
} |
|
298
|
|
|
|
|
299
|
|
|
/** |
|
300
|
|
|
* @return ProgramRepository |
|
301
|
|
|
*/ |
|
302
|
|
|
protected function getProgramRepository(): ProgramRepository |
|
303
|
|
|
{ |
|
304
|
|
|
return $this->programRepository; |
|
305
|
|
|
} |
|
306
|
|
|
|
|
307
|
|
|
/** |
|
308
|
|
|
* @param ProgramRepository $repository |
|
309
|
|
|
* @return self |
|
310
|
|
|
*/ |
|
311
|
|
|
protected function setProgramRepository(ProgramRepository $repository): self |
|
312
|
|
|
{ |
|
313
|
|
|
$this->programRepository = $repository; |
|
314
|
|
|
|
|
315
|
|
|
return $this; |
|
316
|
|
|
} |
|
317
|
|
|
|
|
318
|
|
|
/** |
|
319
|
|
|
* @return BlockModel |
|
320
|
|
|
*/ |
|
321
|
|
|
protected function getBlockModel(): BlockModel |
|
322
|
|
|
{ |
|
323
|
|
|
return $this->blockModel; |
|
324
|
|
|
} |
|
325
|
|
|
|
|
326
|
|
|
/** |
|
327
|
|
|
* @param BlockModel $model |
|
328
|
|
|
* @return self |
|
329
|
|
|
*/ |
|
330
|
|
|
protected function setBlockModel(BlockModel $model): self |
|
331
|
|
|
{ |
|
332
|
|
|
$this->blockModel = $model; |
|
333
|
|
|
|
|
334
|
|
|
return $this; |
|
335
|
|
|
} |
|
336
|
|
|
|
|
337
|
|
|
/** |
|
338
|
|
|
* @return MeetingModel |
|
339
|
|
|
*/ |
|
340
|
|
|
protected function getMeetingModel(): MeetingModel |
|
341
|
|
|
{ |
|
342
|
|
|
return $this->meetingModel; |
|
343
|
|
|
} |
|
344
|
|
|
|
|
345
|
|
|
/** |
|
346
|
|
|
* @param MeetingModel $model |
|
347
|
|
|
* @return VisitorForm |
|
348
|
|
|
*/ |
|
349
|
|
|
protected function setMeetingModel(MeetingModel $model): VisitorForm |
|
350
|
|
|
{ |
|
351
|
|
|
$this->meetingModel = $model; |
|
352
|
|
|
|
|
353
|
|
|
return $this; |
|
354
|
|
|
} |
|
355
|
|
|
|
|
356
|
|
|
/** |
|
357
|
|
|
* @return array |
|
358
|
|
|
*/ |
|
359
|
|
|
protected function getMealFields(): array |
|
360
|
|
|
{ |
|
361
|
|
|
return $this->mealFields; |
|
362
|
|
|
} |
|
363
|
|
|
|
|
364
|
|
|
/** |
|
365
|
|
|
* @param string $meal |
|
366
|
|
|
* @return self |
|
367
|
|
|
*/ |
|
368
|
|
|
protected function setMealField(string $meal): self |
|
369
|
|
|
{ |
|
370
|
|
|
if(!in_array($meal, $this->mealFields)) { |
|
371
|
|
|
$this->mealFields[] = $meal; |
|
372
|
|
|
} |
|
373
|
|
|
|
|
374
|
|
|
return $this; |
|
375
|
|
|
} |
|
376
|
|
|
|
|
377
|
|
|
/** |
|
378
|
|
|
* @return array |
|
379
|
|
|
*/ |
|
380
|
|
|
protected function getProgramFields(): array |
|
381
|
|
|
{ |
|
382
|
|
|
return $this->programFields; |
|
383
|
|
|
} |
|
384
|
|
|
|
|
385
|
|
|
/** |
|
386
|
|
|
* @param string $program |
|
387
|
|
|
* @return self |
|
388
|
|
|
*/ |
|
389
|
|
|
protected function setProgramField(string $program): self |
|
390
|
|
|
{ |
|
391
|
|
|
$this->programFields[] = $program; |
|
392
|
|
|
|
|
393
|
|
|
return $this; |
|
394
|
|
|
} |
|
395
|
|
|
|
|
396
|
|
|
/** |
|
397
|
|
|
* @return self |
|
398
|
|
|
*/ |
|
399
|
|
|
protected function setProgramFields(): self |
|
400
|
|
|
{ |
|
401
|
|
|
$programBlocks = $this->fetchProgramBlocks(); |
|
402
|
|
|
|
|
403
|
|
|
foreach ($programBlocks as $block) { |
|
404
|
|
|
$programFieldName = 'blck_' . $block->id; |
|
405
|
|
|
$this->setProgramField($programFieldName); |
|
406
|
|
|
} |
|
407
|
|
|
|
|
408
|
|
|
return $this; |
|
409
|
|
|
} |
|
410
|
|
|
|
|
411
|
|
|
/** |
|
412
|
|
|
* @return self |
|
413
|
|
|
*/ |
|
414
|
|
|
protected function setMealFields(): self |
|
415
|
|
|
{ |
|
416
|
|
|
$meals = $this->fetchMeals(); |
|
417
|
|
|
|
|
418
|
|
|
foreach ($meals as $name => $label) { |
|
419
|
|
|
$this->setMealField($name); |
|
420
|
|
|
} |
|
421
|
|
|
|
|
422
|
|
|
return $this; |
|
423
|
|
|
} |
|
424
|
|
|
|
|
425
|
|
|
/** |
|
426
|
|
|
* @return Row |
|
427
|
|
|
*/ |
|
428
|
|
|
protected function fetchProgramBlocks() |
|
429
|
|
|
{ |
|
430
|
|
|
return $this->getBlockModel()->getProgramBlocks($this->getMeetingId()); |
|
431
|
|
|
} |
|
432
|
|
|
|
|
433
|
|
|
/** |
|
434
|
|
|
* @return array |
|
435
|
|
|
*/ |
|
436
|
|
|
protected function fetchMeals() |
|
437
|
|
|
{ |
|
438
|
|
|
return MealModel::$meals; |
|
439
|
|
|
} |
|
440
|
|
|
|
|
441
|
|
|
/** |
|
442
|
|
|
* @return UserService |
|
443
|
|
|
*/ |
|
444
|
|
|
protected function getUserService() |
|
445
|
|
|
{ |
|
446
|
|
|
return $this->userService; |
|
|
|
|
|
|
447
|
|
|
} |
|
448
|
|
|
|
|
449
|
|
|
/** |
|
450
|
|
|
* @param UserService $service |
|
451
|
|
|
* @return $this |
|
452
|
|
|
*/ |
|
453
|
|
|
protected function setUserService(UserService $service) |
|
454
|
|
|
{ |
|
455
|
|
|
$this->userService = $service; |
|
|
|
|
|
|
456
|
|
|
|
|
457
|
|
|
return $this; |
|
458
|
|
|
} |
|
459
|
|
|
|
|
460
|
|
|
/** |
|
461
|
|
|
* @param array $programs |
|
462
|
|
|
* @return array |
|
463
|
|
|
*/ |
|
464
|
|
|
protected function filterFilledCapacity(array $programs = []): array |
|
465
|
|
|
{ |
|
466
|
|
|
return array_keys( |
|
467
|
|
|
array_filter($programs, function($name, $id) { |
|
468
|
|
|
if ($id) { |
|
469
|
|
|
$visitorsOnProgram = $this->getProgramRepository()->countVisitors($id); |
|
470
|
|
|
$programCapacity = $this->getProgramRepository()->find($id)->capacity; |
|
471
|
|
|
|
|
472
|
|
|
return $visitorsOnProgram >= $programCapacity; |
|
473
|
|
|
} |
|
474
|
|
|
}, ARRAY_FILTER_USE_BOTH) |
|
475
|
|
|
); |
|
476
|
|
|
} |
|
477
|
|
|
|
|
478
|
|
|
} |
|
479
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.