diff --git a/app/AdminModule/Forms/EditUserSeminarFormFactory.php b/app/AdminModule/Forms/EditUserSeminarFormFactory.php index 498cd68b7..5f23ffaa8 100644 --- a/app/AdminModule/Forms/EditUserSeminarFormFactory.php +++ b/app/AdminModule/Forms/EditUserSeminarFormFactory.php @@ -46,6 +46,7 @@ use Nextras\FormComponents\Controls\DateTimeControl; use stdClass; use Throwable; +use function array_key_exists; use const UPLOAD_ERR_OK; /** @@ -166,10 +167,11 @@ public function create(int $id) : Form break; case $customInput instanceof CustomSelect: - $custom = $form->addSelect($customInputId, $customInput->getName(), $customInput->getSelectOptions()); + $selectOptions = $customInput->getSelectOptions(); + $custom = $form->addSelect($customInputId, $customInput->getName(), $selectOptions); /** @var ?CustomSelectValue $customInputValue */ $customInputValue = $this->user->getCustomInputValue($customInput); - if ($customInputValue) { + if ($customInputValue && array_key_exists($customInputValue->getValue(), $selectOptions)) { $custom->setDefaultValue($customInputValue->getValue()); } @@ -270,41 +272,37 @@ public function processForm(Form $form, stdClass $values) : void $this->user->setAttended($values->attended); foreach ($this->customInputRepository->findByRolesOrderedByPosition($this->user->getRoles()) as $customInput) { + $customInputId = 'custom' . $customInput->getId(); $customInputValue = $this->user->getCustomInputValue($customInput); - $customInputName = 'custom' . $customInput->getId(); $oldValue = null; - $newValue = null; + $newValue = $values->$customInputId; if ($customInput instanceof CustomText) { /** @var CustomTextValue $customInputValue */ $customInputValue = $customInputValue ?: new CustomTextValue(); $oldValue = $customInputValue->getValue(); - $newValue = $values->$customInputName; $customInputValue->setValue($newValue); } elseif ($customInput instanceof CustomCheckbox) { /** @var CustomCheckboxValue $customInputValue */ $customInputValue = $customInputValue ?: new CustomCheckboxValue(); $oldValue = $customInputValue->getValue(); - $newValue = $values->$customInputName; $customInputValue->setValue($newValue); } elseif ($customInput instanceof CustomSelect) { /** @var CustomSelectValue $customInputValue */ $customInputValue = $customInputValue ?: new CustomSelectValue(); $oldValue = $customInputValue->getValue(); - $newValue = $values->$customInputName; $customInputValue->setValue($newValue); } elseif ($customInput instanceof CustomMultiSelect) { /** @var CustomMultiSelectValue $customInputValue */ $customInputValue = $customInputValue ?: new CustomMultiSelectValue(); $oldValue = $customInputValue->getValue(); - $newValue = $values->$customInputName; $customInputValue->setValue($newValue); } elseif ($customInput instanceof CustomFile) { /** @var CustomFileValue $customInputValue */ $customInputValue = $customInputValue ?: new CustomFileValue(); $oldValue = $customInputValue->getValue(); /** @var FileUpload $newValue */ - $newValue = $values->$customInputName; + $newValue = $values->$customInputId; if ($newValue->getError() == UPLOAD_ERR_OK) { $path = $this->generatePath($newValue); $this->filesService->save($newValue, $path); @@ -314,13 +312,11 @@ public function processForm(Form $form, stdClass $values) : void /** @var CustomDateValue $customInputValue */ $customInputValue = $customInputValue ?: new CustomDateValue(); $oldValue = $customInputValue->getValue(); - $newValue = $values->$customInputName; $customInputValue->setValue($newValue); } elseif ($customInput instanceof CustomDateTime) { /** @var CustomDateTimeValue $customInputValue */ $customInputValue = $customInputValue ?: new CustomDateTimeValue(); $oldValue = $customInputValue->getValue(); - $newValue = $values->$customInputName; $customInputValue->setValue($newValue); } diff --git a/app/Model/User/CustomInputValue/CustomCheckboxValue.php b/app/Model/User/CustomInputValue/CustomCheckboxValue.php index 70bd9dc89..d676f3ff7 100644 --- a/app/Model/User/CustomInputValue/CustomCheckboxValue.php +++ b/app/Model/User/CustomInputValue/CustomCheckboxValue.php @@ -21,9 +21,9 @@ class CustomCheckboxValue extends CustomInputValue * * @ORM\Column(type="boolean") */ - protected bool $value = false; + protected ?bool $value = null; - public function getValue() : bool + public function getValue() : ?bool { return $this->value; } @@ -33,8 +33,8 @@ public function setValue(bool $value) : void $this->value = $value; } - public function getValueText() : ?string + public function getValueText() : string { - return (string) $this->value; + return $this->value ? (string) $this->value : ''; } } diff --git a/app/Model/User/CustomInputValue/CustomDateTimeValue.php b/app/Model/User/CustomInputValue/CustomDateTimeValue.php index 79ca94d42..c8bc68386 100644 --- a/app/Model/User/CustomInputValue/CustomDateTimeValue.php +++ b/app/Model/User/CustomInputValue/CustomDateTimeValue.php @@ -35,8 +35,8 @@ public function setValue(?DateTimeImmutable $value) : void $this->value = $value; } - public function getValueText() : ?string + public function getValueText() : string { - return $this->value ? $this->value->format(Helpers::DATETIME_FORMAT) : null; + return $this->value ? $this->value->format(Helpers::DATETIME_FORMAT) : ''; } } diff --git a/app/Model/User/CustomInputValue/CustomDateValue.php b/app/Model/User/CustomInputValue/CustomDateValue.php index 0c8a109b6..fa2a339ed 100644 --- a/app/Model/User/CustomInputValue/CustomDateValue.php +++ b/app/Model/User/CustomInputValue/CustomDateValue.php @@ -35,8 +35,8 @@ public function setValue(?DateTimeImmutable $value) : void $this->value = $value; } - public function getValueText() : ?string + public function getValueText() : string { - return $this->value ? $this->value->format(Helpers::DATE_FORMAT) : null; + return $this->value ? $this->value->format(Helpers::DATE_FORMAT) : ''; } } diff --git a/app/Model/User/CustomInputValue/CustomFileValue.php b/app/Model/User/CustomInputValue/CustomFileValue.php index b66e7c67d..1a8bf4ccc 100644 --- a/app/Model/User/CustomInputValue/CustomFileValue.php +++ b/app/Model/User/CustomInputValue/CustomFileValue.php @@ -33,8 +33,8 @@ public function setValue(?string $value) : void $this->value = $value; } - public function getValueText() : ?string + public function getValueText() : string { - return null; + return ''; } } diff --git a/app/Model/User/CustomInputValue/CustomInputValue.php b/app/Model/User/CustomInputValue/CustomInputValue.php index e2ee8963c..1704673d1 100644 --- a/app/Model/User/CustomInputValue/CustomInputValue.php +++ b/app/Model/User/CustomInputValue/CustomInputValue.php @@ -71,5 +71,5 @@ public function setUser(User $user) : void $this->user = $user; } - abstract public function getValueText() : ?string; + abstract public function getValueText() : string; } diff --git a/app/Model/User/CustomInputValue/CustomMultiSelectValue.php b/app/Model/User/CustomInputValue/CustomMultiSelectValue.php index b9326bee9..e97f78bac 100644 --- a/app/Model/User/CustomInputValue/CustomMultiSelectValue.php +++ b/app/Model/User/CustomInputValue/CustomMultiSelectValue.php @@ -46,13 +46,13 @@ public function setValue(array $value) : void /** * Vrátí název vybrané možnosti. */ - public function getValueText() : ?string + public function getValueText() : string { /** @var CustomMultiSelect $input */ $input = $this->getInput(); if (empty($this->value)) { - return null; + return ''; } else { $selectedValues = []; foreach ($this->value as $value) { diff --git a/app/Model/User/CustomInputValue/CustomSelectValue.php b/app/Model/User/CustomInputValue/CustomSelectValue.php index eb5e677e3..ab469e990 100644 --- a/app/Model/User/CustomInputValue/CustomSelectValue.php +++ b/app/Model/User/CustomInputValue/CustomSelectValue.php @@ -29,7 +29,7 @@ public function getValue() : ?int return $this->value; } - public function setValue(?int $value) : void + public function setValue(int $value) : void { $this->value = $value; } @@ -37,11 +37,11 @@ public function setValue(?int $value) : void /** * Vrátí název vybrané možnosti. */ - public function getValueText() : ?string + public function getValueText() : string { /** @var CustomSelect $input */ $input = $this->getInput(); - return $this->value !== 0 ? $input->getSelectOptions()[$this->value] : null; + return $this->value !== 0 ? $input->getSelectOptions()[$this->value] : ''; } } diff --git a/app/Model/User/CustomInputValue/CustomTextValue.php b/app/Model/User/CustomInputValue/CustomTextValue.php index 9c52d5952..1a6d69f5e 100644 --- a/app/Model/User/CustomInputValue/CustomTextValue.php +++ b/app/Model/User/CustomInputValue/CustomTextValue.php @@ -21,9 +21,9 @@ class CustomTextValue extends CustomInputValue * * @ORM\Column(type="string") */ - protected string $value; + protected ?string $value = null; - public function getValue() : string + public function getValue() : ?string { return $this->value; } @@ -33,8 +33,8 @@ public function setValue(string $value) : void $this->value = $value; } - public function getValueText() : ?string + public function getValueText() : string { - return $this->value; + return $this->value ?: ''; } } diff --git a/app/WebModule/Forms/AdditionalInformationForm.php b/app/WebModule/Forms/AdditionalInformationForm.php index 154ec6f74..36e28c362 100644 --- a/app/WebModule/Forms/AdditionalInformationForm.php +++ b/app/WebModule/Forms/AdditionalInformationForm.php @@ -41,6 +41,7 @@ use Nextras\FormComponents\Controls\DateTimeControl; use stdClass; use Throwable; +use function array_key_exists; use function array_slice; use function array_values; use function explode; @@ -130,11 +131,12 @@ public function createComponentForm() : Form $form = $this->baseFormFactory->create(); foreach ($this->customInputRepository->findByRolesOrderedByPosition($this->user->getRoles()) as $customInput) { - $custom = null; + $customInputId = 'custom' . $customInput->getId(); + $custom = null; switch (true) { case $customInput instanceof CustomText: - $custom = $form->addText('custom' . $customInput->getId(), $customInput->getName()); + $custom = $form->addText($customInputId, $customInput->getName()); /** @var ?CustomTextValue $customInputValue */ $customInputValue = $this->user->getCustomInputValue($customInput); @@ -145,7 +147,7 @@ public function createComponentForm() : Form break; case $customInput instanceof CustomCheckbox: - $custom = $form->addCheckbox('custom' . $customInput->getId(), $customInput->getName()); + $custom = $form->addCheckbox($customInputId, $customInput->getName()); /** @var ?CustomCheckboxValue $customInputValue */ $customInputValue = $this->user->getCustomInputValue($customInput); @@ -156,18 +158,19 @@ public function createComponentForm() : Form break; case $customInput instanceof CustomSelect: - $custom = $form->addSelect('custom' . $customInput->getId(), $customInput->getName(), $customInput->getSelectOptions()); + $selectOptions = $customInput->getSelectOptions(); + $custom = $form->addSelect($customInputId, $customInput->getName(), $selectOptions); /** @var ?CustomSelectValue $customInputValue */ $customInputValue = $this->user->getCustomInputValue($customInput); - if ($customInputValue) { + if ($customInputValue && array_key_exists($customInputValue->getValue(), $selectOptions)) { $custom->setDefaultValue($customInputValue->getValue()); } break; case $customInput instanceof CustomMultiSelect: - $custom = $form->addMultiSelect('custom' . $customInput->getId(), $customInput->getName(), $customInput->getSelectOptions()); + $custom = $form->addMultiSelect($customInputId, $customInput->getName(), $customInput->getSelectOptions()); /** @var ?CustomMultiSelectValue $customInputValue */ $customInputValue = $this->user->getCustomInputValue($customInput); @@ -178,7 +181,7 @@ public function createComponentForm() : Form break; case $customInput instanceof CustomFile: - $custom = $form->addUpload('custom' . $customInput->getId(), $customInput->getName()); + $custom = $form->addUpload($customInputId, $customInput->getName()); /** @var ?CustomFileValue $customInputValue */ $customInputValue = $this->user->getCustomInputValue($customInput); @@ -198,7 +201,7 @@ public function createComponentForm() : Form $custom->setDefaultValue($customInputValue->getValue()); } - $form->addComponent($custom, 'custom' . $customInput->getId()); + $form->addComponent($custom, $customInputId); break; case $customInput instanceof CustomDateTime: @@ -210,7 +213,7 @@ public function createComponentForm() : Form $custom->setDefaultValue($customInputValue->getValue()); } - $form->addComponent($custom, 'custom' . $customInput->getId()); + $form->addComponent($custom, $customInputId); break; default: @@ -249,41 +252,37 @@ public function processForm(Form $form, stdClass $values) : void if ($this->applicationService->isAllowedEditCustomInputs()) { foreach ($this->customInputRepository->findByRolesOrderedByPosition($this->user->getRoles()) as $customInput) { + $customInputId = 'custom' . $customInput->getId(); $customInputValue = $this->user->getCustomInputValue($customInput); - $customInputName = 'custom' . $customInput->getId(); $oldValue = null; - $newValue = null; + $newValue = $values->$customInputId; if ($customInput instanceof CustomText) { /** @var CustomTextValue $customInputValue */ $customInputValue = $customInputValue ?: new CustomTextValue(); $oldValue = $customInputValue->getValue(); - $newValue = $values->$customInputName; $customInputValue->setValue($newValue); } elseif ($customInput instanceof CustomCheckbox) { /** @var CustomCheckboxValue $customInputValue */ $customInputValue = $customInputValue ?: new CustomCheckboxValue(); $oldValue = $customInputValue->getValue(); - $newValue = $values->$customInputName; $customInputValue->setValue($newValue); } elseif ($customInput instanceof CustomSelect) { /** @var CustomSelectValue $customInputValue */ $customInputValue = $customInputValue ?: new CustomSelectValue(); $oldValue = $customInputValue->getValue(); - $newValue = $values->$customInputName; $customInputValue->setValue($newValue); } elseif ($customInput instanceof CustomMultiSelect) { /** @var CustomMultiSelectValue $customInputValue */ $customInputValue = $customInputValue ?: new CustomMultiSelectValue(); $oldValue = $customInputValue->getValue(); - $newValue = $values->$customInputName; $customInputValue->setValue($newValue); } elseif ($customInput instanceof CustomFile) { /** @var CustomFileValue $customInputValue */ $customInputValue = $customInputValue ?: new CustomFileValue(); $oldValue = $customInputValue->getValue(); /** @var FileUpload $newValue */ - $newValue = $values->$customInputName; + $newValue = $values->$customInputId; if ($newValue->getError() == UPLOAD_ERR_OK) { $path = $this->generatePath($newValue); $this->filesService->save($newValue, $path); @@ -293,13 +292,11 @@ public function processForm(Form $form, stdClass $values) : void /** @var CustomDateValue $customInputValue */ $customInputValue = $customInputValue ?: new CustomDateValue(); $oldValue = $customInputValue->getValue(); - $newValue = $values->$customInputName; $customInputValue->setValue($newValue); } elseif ($customInput instanceof CustomDateTime) { /** @var CustomDateTimeValue $customInputValue */ $customInputValue = $customInputValue ?: new CustomDateTimeValue(); $oldValue = $customInputValue->getValue(); - $newValue = $values->$customInputName; $customInputValue->setValue($newValue); } diff --git a/app/WebModule/Forms/ApplicationFormFactory.php b/app/WebModule/Forms/ApplicationFormFactory.php index 0dc756ac2..9f820942f 100644 --- a/app/WebModule/Forms/ApplicationFormFactory.php +++ b/app/WebModule/Forms/ApplicationFormFactory.php @@ -272,30 +272,30 @@ public function processForm(Form $form, stdClass $values) : void //vlastni pole foreach ($this->customInputRepository->findByRolesOrderedByPosition($roles) as $customInput) { + $customInputId = 'custom' . $customInput->getId(); $customInputValue = $this->user->getCustomInputValue($customInput); - $customInputName = 'custom' . $customInput->getId(); if ($customInput instanceof CustomText) { /** @var CustomTextValue $customInputValue */ $customInputValue = $customInputValue ?: new CustomTextValue(); - $customInputValue->setValue($values->$customInputName); + $customInputValue->setValue($values->$customInputId); } elseif ($customInput instanceof CustomCheckbox) { /** @var CustomCheckboxValue $customInputValue */ $customInputValue = $customInputValue ?: new CustomCheckboxValue(); - $customInputValue->setValue($values->$customInputName); + $customInputValue->setValue($values->$customInputId); } elseif ($customInput instanceof CustomSelect) { /** @var CustomSelectValue $customInputValue */ $customInputValue = $customInputValue ?: new CustomSelectValue(); - $customInputValue->setValue($values->$customInputName); + $customInputValue->setValue($values->$customInputId); } elseif ($customInput instanceof CustomMultiSelect) { /** @var CustomMultiSelectValue $customInputValue */ $customInputValue = $customInputValue ?: new CustomMultiSelectValue(); - $customInputValue->setValue($values->$customInputName); + $customInputValue->setValue($values->$customInputId); } elseif ($customInput instanceof CustomFile) { /** @var CustomFileValue $customInputValue */ $customInputValue = $customInputValue ?: new CustomFileValue(); /** @var FileUpload $file */ - $file = $values->$customInputName; + $file = $values->$customInputId; if ($file->getError() == UPLOAD_ERR_OK) { $path = $this->generatePath($file); $this->filesService->save($file, $path); @@ -304,11 +304,11 @@ public function processForm(Form $form, stdClass $values) : void } elseif ($customInput instanceof CustomDate) { /** @var CustomDateValue $customInputValue */ $customInputValue = $customInputValue ?: new CustomDateValue(); - $customInputValue->setValue($values->$customInputName); + $customInputValue->setValue($values->$customInputId); } elseif ($customInput instanceof CustomDateTime) { /** @var CustomDateTimeValue $customInputValue */ $customInputValue = $customInputValue ?: new CustomDateTimeValue(); - $customInputValue->setValue($values->$customInputName); + $customInputValue->setValue($values->$customInputId); } $customInputValue->setUser($this->user); diff --git a/app/assets/web/schedule/Calendar.vue b/app/assets/web/schedule/Calendar.vue index 234e95eb3..374d5fbdb 100644 --- a/app/assets/web/schedule/Calendar.vue +++ b/app/assets/web/schedule/Calendar.vue @@ -126,7 +126,7 @@ theme-system="bootstrap" locale="cs" timeZone="none" - aspect-ratio="1.85" + aspect-ratio="1.6" header="false" scheduler-license-key="GPL-My-Project-Is-Open-Source" :plugins="calendarPlugins"