|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Components\Forms; |
|
4
|
|
|
|
|
5
|
|
|
use App\Models\ProvinceModel; |
|
6
|
|
|
use App\Repositories\ProgramRepository; |
|
7
|
|
|
use App\Models\BlockModel; |
|
8
|
|
|
use App\Models\MeetingModel; |
|
9
|
|
|
use Nette\Application\UI\Form; |
|
10
|
|
|
use App\Services\SkautIS\UserService; |
|
11
|
|
|
|
|
12
|
|
|
class RegistrationForm extends VisitorForm |
|
13
|
|
|
{ |
|
14
|
|
|
|
|
15
|
|
|
const TEMPLATE_NAME = 'RegistrationForm'; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var Closure |
|
19
|
|
|
*/ |
|
20
|
|
|
public $onRegistrationSave; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var UserService |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $userService; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param ProvinceModel $model |
|
|
|
|
|
|
29
|
|
|
*/ |
|
30
|
|
View Code Duplication |
public function __construct( |
|
|
|
|
|
|
31
|
|
|
ProvinceModel $province, |
|
32
|
|
|
ProgramRepository $program, |
|
33
|
|
|
BlockModel $block, |
|
34
|
|
|
MeetingModel $meeting, |
|
35
|
|
|
UserService $user |
|
36
|
|
|
) { |
|
37
|
|
|
$this->setProvinceModel($province); |
|
38
|
|
|
$this->setProgramRepository($program); |
|
39
|
|
|
$this->setBlockModel($block); |
|
40
|
|
|
$this->setMeetingModel($meeting); |
|
41
|
|
|
$this->setUserService($user); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param array $defaults |
|
46
|
|
|
* @return self |
|
47
|
|
|
*/ |
|
48
|
|
|
public function setDefaults($defaults): BaseForm |
|
49
|
|
|
{ |
|
50
|
|
|
$this['registrationForm']->setDefaults($defaults); |
|
51
|
|
|
|
|
52
|
|
|
return $this; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @return Form |
|
57
|
|
|
*/ |
|
58
|
|
|
public function createComponentRegistrationForm(): Form |
|
59
|
|
|
{ |
|
60
|
|
|
$provinces = $this->getProvinceModel()->all(); |
|
61
|
|
|
|
|
62
|
|
|
$form = new Form; |
|
63
|
|
|
|
|
64
|
|
|
$form->addText('name', 'Jméno:') |
|
65
|
|
|
->setRequired(static::MESSAGE_REQUIRED) |
|
|
|
|
|
|
66
|
|
|
->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 20) |
|
67
|
|
|
->getLabelPrototype()->setAttribute('class', 'required'); |
|
68
|
|
|
$form->addText('surname', 'Příjmení:') |
|
69
|
|
|
->setRequired(static::MESSAGE_REQUIRED) |
|
|
|
|
|
|
70
|
|
|
->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 30) |
|
71
|
|
|
->getLabelPrototype()->setAttribute('class', 'required'); |
|
72
|
|
|
$form->addText('nick', 'Přezdívka:') |
|
73
|
|
|
->setRequired(static::MESSAGE_REQUIRED) |
|
|
|
|
|
|
74
|
|
|
->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 20) |
|
75
|
|
|
->getLabelPrototype()->setAttribute('class', 'required'); |
|
76
|
|
|
$form->addEmail('email', 'E-mail:') |
|
77
|
|
|
->setRequired(static::MESSAGE_REQUIRED) |
|
|
|
|
|
|
78
|
|
|
->getLabelPrototype()->setAttribute('class', 'required'); |
|
79
|
|
|
$form->addTbDatePicker('birthday', 'Datum narození:', null, 16) |
|
80
|
|
|
->setRequired(static::MESSAGE_REQUIRED) |
|
81
|
|
|
->setFormat('d. m. Y') |
|
82
|
|
|
->setAttribute('placeholder', 'dd. mm. rrrr') |
|
83
|
|
|
->getLabelPrototype()->setAttribute('class', 'required'); |
|
84
|
|
|
$form->addText('street', 'Ulice:') |
|
85
|
|
|
->setRequired(static::MESSAGE_REQUIRED) |
|
|
|
|
|
|
86
|
|
|
->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 30) |
|
87
|
|
|
->getLabelPrototype()->setAttribute('class', 'required'); |
|
88
|
|
|
$form->addText('city', 'Město:') |
|
89
|
|
|
->setRequired(static::MESSAGE_REQUIRED) |
|
|
|
|
|
|
90
|
|
|
->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 64) |
|
91
|
|
|
->getLabelPrototype()->setAttribute('class', 'required'); |
|
92
|
|
|
$form->addText('postal_code', 'PSČ:') |
|
93
|
|
|
->setRequired(static::MESSAGE_REQUIRED) |
|
|
|
|
|
|
94
|
|
|
->addRule(Form::PATTERN, 'Číslo musí být ve formátu nnnnn!', '[1-9]{1}[0-9]{4}') |
|
95
|
|
|
->setAttribute('placeholder', '12345') |
|
|
|
|
|
|
96
|
|
|
->getLabelPrototype()->setAttribute('class', 'required'); |
|
97
|
|
|
$form->addText('group_num', 'Číslo středika/přístavu:') |
|
98
|
|
|
->setRequired(static::MESSAGE_REQUIRED) |
|
|
|
|
|
|
99
|
|
|
->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}') |
|
100
|
|
|
->setAttribute('placeholder', '214.02') |
|
|
|
|
|
|
101
|
|
|
->getLabelPrototype()->setAttribute('class', 'required'); |
|
102
|
|
|
$form->addText('group_name', 'Název střediska/přístavu:') |
|
103
|
|
|
->setRequired(static::MESSAGE_REQUIRED) |
|
|
|
|
|
|
104
|
|
|
->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 50) |
|
105
|
|
|
->setAttribute('placeholder', '2. přístav Poutníci Kolín') |
|
|
|
|
|
|
106
|
|
|
->getLabelPrototype()->setAttribute('class', 'required'); |
|
107
|
|
|
$form->addText('troop_name', 'Název oddílu:') |
|
108
|
|
|
->setAttribute('placeholder', '22. oddíl Galeje') |
|
|
|
|
|
|
109
|
|
|
->addCondition(Form::FILLED, true) |
|
110
|
|
|
->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 50); |
|
111
|
|
|
|
|
112
|
|
|
$form->addSelect('province', 'Kraj:', $provinces) |
|
113
|
|
|
->setPrompt('zvolte kraj'); |
|
114
|
|
|
|
|
115
|
|
|
$form = $this->buildMealSwitcher($form); |
|
116
|
|
|
|
|
117
|
|
|
$form->addTextArea('arrival', 'Informace o příjezdu:') |
|
118
|
|
|
->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.'); |
|
|
|
|
|
|
119
|
|
|
$form->addTextArea('departure', 'Informace o odjezdu:') |
|
120
|
|
|
->setAttribute('placeholder', 'Napište, prosím, stručně jakým dopravním prostředkem a v kolik hodin (přibližně) sraz opustíte.'); |
|
|
|
|
|
|
121
|
|
|
$form->addTextArea('comment', 'Dotazy, přání, připomínky, stížnosti:'); |
|
122
|
|
|
$form->addTextArea('question', 'Vaše nabídka:') |
|
123
|
|
|
->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)'); |
|
|
|
|
|
|
124
|
|
|
$form->addTextArea('question2', 'Počet a typy lodí:') |
|
125
|
|
|
->setAttribute('placeholder', 'Počet a typy lodí, které sebou přivezete (vyplňte pokud ano)'); |
|
|
|
|
|
|
126
|
|
|
|
|
127
|
|
|
$form = $this->buildProgramSwitcher($form); |
|
128
|
|
|
|
|
129
|
|
|
$form->addHidden('mid', $this->getMeetingId()); |
|
130
|
|
|
$form->addHidden('bill', 0); |
|
131
|
|
|
$form->addHidden('cost', $this->getMeetingModel()->getPrice('cost')); |
|
132
|
|
|
|
|
133
|
|
|
$form->addSubmit('save', 'Uložit') |
|
134
|
|
|
->setAttribute('class', 'btn-primary'); |
|
|
|
|
|
|
135
|
|
|
$form->addSubmit('reset', 'storno') |
|
136
|
|
|
->setAttribute('class', 'btn-reset'); |
|
|
|
|
|
|
137
|
|
|
|
|
138
|
|
|
$form = $this->setupRendering($form); |
|
139
|
|
|
|
|
140
|
|
|
$form->onSuccess[] = [$this, 'processForm']; |
|
141
|
|
|
|
|
142
|
|
|
return $form; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* @param Form $form |
|
147
|
|
|
* @return void |
|
148
|
|
|
*/ |
|
149
|
|
|
public function processForm(Form $form) |
|
150
|
|
|
{ |
|
151
|
|
|
$registration = $form->getValues(); |
|
152
|
|
|
$registration['meeting'] = $this->getMeetingId(); |
|
153
|
|
|
|
|
154
|
|
|
$this->onRegistrationSave($this, $registration); |
|
|
|
|
|
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* @return UserService |
|
159
|
|
|
*/ |
|
160
|
|
|
protected function getUserService() |
|
161
|
|
|
{ |
|
162
|
|
|
return $this->userService; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* @param UserService $service |
|
167
|
|
|
* @return $this |
|
168
|
|
|
*/ |
|
169
|
|
|
protected function setUserService(UserService $service) |
|
170
|
|
|
{ |
|
171
|
|
|
$this->userService = $service; |
|
172
|
|
|
|
|
173
|
|
|
return $this; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
} |
|
177
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.