Skip to content

Commit 484ce8d

Browse files
authored
Opravy chyb vlastních polí + výška kalendáře (#740)
* odstraneni prijezdu a odjezdu * úprava modelu - customdate, customdatetime * migrate * multiselect * vlastni pole typu multiselect, date, datetime * oprava coding standard * nastaveni roli pro vlastni pole * zobrazeni poli podle roli * oprava CS * prepinani zobrazovani poli * prepinani viditelnosti a povinnosti poli * filtrovani podle select a multiselect * coding standard fix * coding standard fix * build fix * opravy vlastnich poli, vyska kalendare * opravy vlastnich poli, vyska kalendare * cs oprava * cs oprava * cs oprava * cs oprava
1 parent 609db07 commit 484ce8d

12 files changed

+51
-58
lines changed

app/AdminModule/Forms/EditUserSeminarFormFactory.php

+7-11
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
use Nextras\FormComponents\Controls\DateTimeControl;
4747
use stdClass;
4848
use Throwable;
49+
use function array_key_exists;
4950
use const UPLOAD_ERR_OK;
5051

5152
/**
@@ -166,10 +167,11 @@ public function create(int $id) : Form
166167
break;
167168

168169
case $customInput instanceof CustomSelect:
169-
$custom = $form->addSelect($customInputId, $customInput->getName(), $customInput->getSelectOptions());
170+
$selectOptions = $customInput->getSelectOptions();
171+
$custom = $form->addSelect($customInputId, $customInput->getName(), $selectOptions);
170172
/** @var ?CustomSelectValue $customInputValue */
171173
$customInputValue = $this->user->getCustomInputValue($customInput);
172-
if ($customInputValue) {
174+
if ($customInputValue && array_key_exists($customInputValue->getValue(), $selectOptions)) {
173175
$custom->setDefaultValue($customInputValue->getValue());
174176
}
175177

@@ -270,41 +272,37 @@ public function processForm(Form $form, stdClass $values) : void
270272
$this->user->setAttended($values->attended);
271273

272274
foreach ($this->customInputRepository->findByRolesOrderedByPosition($this->user->getRoles()) as $customInput) {
275+
$customInputId = 'custom' . $customInput->getId();
273276
$customInputValue = $this->user->getCustomInputValue($customInput);
274-
$customInputName = 'custom' . $customInput->getId();
275277
$oldValue = null;
276-
$newValue = null;
278+
$newValue = $values->$customInputId;
277279

278280
if ($customInput instanceof CustomText) {
279281
/** @var CustomTextValue $customInputValue */
280282
$customInputValue = $customInputValue ?: new CustomTextValue();
281283
$oldValue = $customInputValue->getValue();
282-
$newValue = $values->$customInputName;
283284
$customInputValue->setValue($newValue);
284285
} elseif ($customInput instanceof CustomCheckbox) {
285286
/** @var CustomCheckboxValue $customInputValue */
286287
$customInputValue = $customInputValue ?: new CustomCheckboxValue();
287288
$oldValue = $customInputValue->getValue();
288-
$newValue = $values->$customInputName;
289289
$customInputValue->setValue($newValue);
290290
} elseif ($customInput instanceof CustomSelect) {
291291
/** @var CustomSelectValue $customInputValue */
292292
$customInputValue = $customInputValue ?: new CustomSelectValue();
293293
$oldValue = $customInputValue->getValue();
294-
$newValue = $values->$customInputName;
295294
$customInputValue->setValue($newValue);
296295
} elseif ($customInput instanceof CustomMultiSelect) {
297296
/** @var CustomMultiSelectValue $customInputValue */
298297
$customInputValue = $customInputValue ?: new CustomMultiSelectValue();
299298
$oldValue = $customInputValue->getValue();
300-
$newValue = $values->$customInputName;
301299
$customInputValue->setValue($newValue);
302300
} elseif ($customInput instanceof CustomFile) {
303301
/** @var CustomFileValue $customInputValue */
304302
$customInputValue = $customInputValue ?: new CustomFileValue();
305303
$oldValue = $customInputValue->getValue();
306304
/** @var FileUpload $newValue */
307-
$newValue = $values->$customInputName;
305+
$newValue = $values->$customInputId;
308306
if ($newValue->getError() == UPLOAD_ERR_OK) {
309307
$path = $this->generatePath($newValue);
310308
$this->filesService->save($newValue, $path);
@@ -314,13 +312,11 @@ public function processForm(Form $form, stdClass $values) : void
314312
/** @var CustomDateValue $customInputValue */
315313
$customInputValue = $customInputValue ?: new CustomDateValue();
316314
$oldValue = $customInputValue->getValue();
317-
$newValue = $values->$customInputName;
318315
$customInputValue->setValue($newValue);
319316
} elseif ($customInput instanceof CustomDateTime) {
320317
/** @var CustomDateTimeValue $customInputValue */
321318
$customInputValue = $customInputValue ?: new CustomDateTimeValue();
322319
$oldValue = $customInputValue->getValue();
323-
$newValue = $values->$customInputName;
324320
$customInputValue->setValue($newValue);
325321
}
326322

app/Model/User/CustomInputValue/CustomCheckboxValue.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ class CustomCheckboxValue extends CustomInputValue
2121
*
2222
* @ORM\Column(type="boolean")
2323
*/
24-
protected bool $value = false;
24+
protected ?bool $value = null;
2525

26-
public function getValue() : bool
26+
public function getValue() : ?bool
2727
{
2828
return $this->value;
2929
}
@@ -33,8 +33,8 @@ public function setValue(bool $value) : void
3333
$this->value = $value;
3434
}
3535

36-
public function getValueText() : ?string
36+
public function getValueText() : string
3737
{
38-
return (string) $this->value;
38+
return $this->value ? (string) $this->value : '';
3939
}
4040
}

app/Model/User/CustomInputValue/CustomDateTimeValue.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public function setValue(?DateTimeImmutable $value) : void
3535
$this->value = $value;
3636
}
3737

38-
public function getValueText() : ?string
38+
public function getValueText() : string
3939
{
40-
return $this->value ? $this->value->format(Helpers::DATETIME_FORMAT) : null;
40+
return $this->value ? $this->value->format(Helpers::DATETIME_FORMAT) : '';
4141
}
4242
}

app/Model/User/CustomInputValue/CustomDateValue.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public function setValue(?DateTimeImmutable $value) : void
3535
$this->value = $value;
3636
}
3737

38-
public function getValueText() : ?string
38+
public function getValueText() : string
3939
{
40-
return $this->value ? $this->value->format(Helpers::DATE_FORMAT) : null;
40+
return $this->value ? $this->value->format(Helpers::DATE_FORMAT) : '';
4141
}
4242
}

app/Model/User/CustomInputValue/CustomFileValue.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public function setValue(?string $value) : void
3333
$this->value = $value;
3434
}
3535

36-
public function getValueText() : ?string
36+
public function getValueText() : string
3737
{
38-
return null;
38+
return '';
3939
}
4040
}

app/Model/User/CustomInputValue/CustomInputValue.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,5 @@ public function setUser(User $user) : void
7171
$this->user = $user;
7272
}
7373

74-
abstract public function getValueText() : ?string;
74+
abstract public function getValueText() : string;
7575
}

app/Model/User/CustomInputValue/CustomMultiSelectValue.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ public function setValue(array $value) : void
4646
/**
4747
* Vrátí název vybrané možnosti.
4848
*/
49-
public function getValueText() : ?string
49+
public function getValueText() : string
5050
{
5151
/** @var CustomMultiSelect $input */
5252
$input = $this->getInput();
5353

5454
if (empty($this->value)) {
55-
return null;
55+
return '';
5656
} else {
5757
$selectedValues = [];
5858
foreach ($this->value as $value) {

app/Model/User/CustomInputValue/CustomSelectValue.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ public function getValue() : ?int
2929
return $this->value;
3030
}
3131

32-
public function setValue(?int $value) : void
32+
public function setValue(int $value) : void
3333
{
3434
$this->value = $value;
3535
}
3636

3737
/**
3838
* Vrátí název vybrané možnosti.
3939
*/
40-
public function getValueText() : ?string
40+
public function getValueText() : string
4141
{
4242
/** @var CustomSelect $input */
4343
$input = $this->getInput();
4444

45-
return $this->value !== 0 ? $input->getSelectOptions()[$this->value] : null;
45+
return $this->value !== 0 ? $input->getSelectOptions()[$this->value] : '';
4646
}
4747
}

app/Model/User/CustomInputValue/CustomTextValue.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ class CustomTextValue extends CustomInputValue
2121
*
2222
* @ORM\Column(type="string")
2323
*/
24-
protected string $value;
24+
protected ?string $value = null;
2525

26-
public function getValue() : string
26+
public function getValue() : ?string
2727
{
2828
return $this->value;
2929
}
@@ -33,8 +33,8 @@ public function setValue(string $value) : void
3333
$this->value = $value;
3434
}
3535

36-
public function getValueText() : ?string
36+
public function getValueText() : string
3737
{
38-
return $this->value;
38+
return $this->value ?: '';
3939
}
4040
}

app/WebModule/Forms/AdditionalInformationForm.php

+15-18
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
use Nextras\FormComponents\Controls\DateTimeControl;
4242
use stdClass;
4343
use Throwable;
44+
use function array_key_exists;
4445
use function array_slice;
4546
use function array_values;
4647
use function explode;
@@ -130,11 +131,12 @@ public function createComponentForm() : Form
130131
$form = $this->baseFormFactory->create();
131132

132133
foreach ($this->customInputRepository->findByRolesOrderedByPosition($this->user->getRoles()) as $customInput) {
133-
$custom = null;
134+
$customInputId = 'custom' . $customInput->getId();
135+
$custom = null;
134136

135137
switch (true) {
136138
case $customInput instanceof CustomText:
137-
$custom = $form->addText('custom' . $customInput->getId(), $customInput->getName());
139+
$custom = $form->addText($customInputId, $customInput->getName());
138140

139141
/** @var ?CustomTextValue $customInputValue */
140142
$customInputValue = $this->user->getCustomInputValue($customInput);
@@ -145,7 +147,7 @@ public function createComponentForm() : Form
145147
break;
146148

147149
case $customInput instanceof CustomCheckbox:
148-
$custom = $form->addCheckbox('custom' . $customInput->getId(), $customInput->getName());
150+
$custom = $form->addCheckbox($customInputId, $customInput->getName());
149151

150152
/** @var ?CustomCheckboxValue $customInputValue */
151153
$customInputValue = $this->user->getCustomInputValue($customInput);
@@ -156,18 +158,19 @@ public function createComponentForm() : Form
156158
break;
157159

158160
case $customInput instanceof CustomSelect:
159-
$custom = $form->addSelect('custom' . $customInput->getId(), $customInput->getName(), $customInput->getSelectOptions());
161+
$selectOptions = $customInput->getSelectOptions();
162+
$custom = $form->addSelect($customInputId, $customInput->getName(), $selectOptions);
160163

161164
/** @var ?CustomSelectValue $customInputValue */
162165
$customInputValue = $this->user->getCustomInputValue($customInput);
163-
if ($customInputValue) {
166+
if ($customInputValue && array_key_exists($customInputValue->getValue(), $selectOptions)) {
164167
$custom->setDefaultValue($customInputValue->getValue());
165168
}
166169

167170
break;
168171

169172
case $customInput instanceof CustomMultiSelect:
170-
$custom = $form->addMultiSelect('custom' . $customInput->getId(), $customInput->getName(), $customInput->getSelectOptions());
173+
$custom = $form->addMultiSelect($customInputId, $customInput->getName(), $customInput->getSelectOptions());
171174

172175
/** @var ?CustomMultiSelectValue $customInputValue */
173176
$customInputValue = $this->user->getCustomInputValue($customInput);
@@ -178,7 +181,7 @@ public function createComponentForm() : Form
178181
break;
179182

180183
case $customInput instanceof CustomFile:
181-
$custom = $form->addUpload('custom' . $customInput->getId(), $customInput->getName());
184+
$custom = $form->addUpload($customInputId, $customInput->getName());
182185

183186
/** @var ?CustomFileValue $customInputValue */
184187
$customInputValue = $this->user->getCustomInputValue($customInput);
@@ -198,7 +201,7 @@ public function createComponentForm() : Form
198201
$custom->setDefaultValue($customInputValue->getValue());
199202
}
200203

201-
$form->addComponent($custom, 'custom' . $customInput->getId());
204+
$form->addComponent($custom, $customInputId);
202205
break;
203206

204207
case $customInput instanceof CustomDateTime:
@@ -210,7 +213,7 @@ public function createComponentForm() : Form
210213
$custom->setDefaultValue($customInputValue->getValue());
211214
}
212215

213-
$form->addComponent($custom, 'custom' . $customInput->getId());
216+
$form->addComponent($custom, $customInputId);
214217
break;
215218

216219
default:
@@ -249,41 +252,37 @@ public function processForm(Form $form, stdClass $values) : void
249252

250253
if ($this->applicationService->isAllowedEditCustomInputs()) {
251254
foreach ($this->customInputRepository->findByRolesOrderedByPosition($this->user->getRoles()) as $customInput) {
255+
$customInputId = 'custom' . $customInput->getId();
252256
$customInputValue = $this->user->getCustomInputValue($customInput);
253-
$customInputName = 'custom' . $customInput->getId();
254257
$oldValue = null;
255-
$newValue = null;
258+
$newValue = $values->$customInputId;
256259

257260
if ($customInput instanceof CustomText) {
258261
/** @var CustomTextValue $customInputValue */
259262
$customInputValue = $customInputValue ?: new CustomTextValue();
260263
$oldValue = $customInputValue->getValue();
261-
$newValue = $values->$customInputName;
262264
$customInputValue->setValue($newValue);
263265
} elseif ($customInput instanceof CustomCheckbox) {
264266
/** @var CustomCheckboxValue $customInputValue */
265267
$customInputValue = $customInputValue ?: new CustomCheckboxValue();
266268
$oldValue = $customInputValue->getValue();
267-
$newValue = $values->$customInputName;
268269
$customInputValue->setValue($newValue);
269270
} elseif ($customInput instanceof CustomSelect) {
270271
/** @var CustomSelectValue $customInputValue */
271272
$customInputValue = $customInputValue ?: new CustomSelectValue();
272273
$oldValue = $customInputValue->getValue();
273-
$newValue = $values->$customInputName;
274274
$customInputValue->setValue($newValue);
275275
} elseif ($customInput instanceof CustomMultiSelect) {
276276
/** @var CustomMultiSelectValue $customInputValue */
277277
$customInputValue = $customInputValue ?: new CustomMultiSelectValue();
278278
$oldValue = $customInputValue->getValue();
279-
$newValue = $values->$customInputName;
280279
$customInputValue->setValue($newValue);
281280
} elseif ($customInput instanceof CustomFile) {
282281
/** @var CustomFileValue $customInputValue */
283282
$customInputValue = $customInputValue ?: new CustomFileValue();
284283
$oldValue = $customInputValue->getValue();
285284
/** @var FileUpload $newValue */
286-
$newValue = $values->$customInputName;
285+
$newValue = $values->$customInputId;
287286
if ($newValue->getError() == UPLOAD_ERR_OK) {
288287
$path = $this->generatePath($newValue);
289288
$this->filesService->save($newValue, $path);
@@ -293,13 +292,11 @@ public function processForm(Form $form, stdClass $values) : void
293292
/** @var CustomDateValue $customInputValue */
294293
$customInputValue = $customInputValue ?: new CustomDateValue();
295294
$oldValue = $customInputValue->getValue();
296-
$newValue = $values->$customInputName;
297295
$customInputValue->setValue($newValue);
298296
} elseif ($customInput instanceof CustomDateTime) {
299297
/** @var CustomDateTimeValue $customInputValue */
300298
$customInputValue = $customInputValue ?: new CustomDateTimeValue();
301299
$oldValue = $customInputValue->getValue();
302-
$newValue = $values->$customInputName;
303300
$customInputValue->setValue($newValue);
304301
}
305302

0 commit comments

Comments
 (0)