Skip to content

Commit

Permalink
Opravy chyb vlastních polí + výška kalendáře (#740)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jan-stanek authored May 29, 2020
1 parent 609db07 commit 484ce8d
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 58 deletions.
18 changes: 7 additions & 11 deletions app/AdminModule/Forms/EditUserSeminarFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
use Nextras\FormComponents\Controls\DateTimeControl;
use stdClass;
use Throwable;
use function array_key_exists;
use const UPLOAD_ERR_OK;

/**
Expand Down Expand Up @@ -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());
}

Expand Down Expand Up @@ -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);
Expand All @@ -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);
}

Expand Down
8 changes: 4 additions & 4 deletions app/Model/User/CustomInputValue/CustomCheckboxValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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 : '';
}
}
4 changes: 2 additions & 2 deletions app/Model/User/CustomInputValue/CustomDateTimeValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) : '';
}
}
4 changes: 2 additions & 2 deletions app/Model/User/CustomInputValue/CustomDateValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) : '';
}
}
4 changes: 2 additions & 2 deletions app/Model/User/CustomInputValue/CustomFileValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public function setValue(?string $value) : void
$this->value = $value;
}

public function getValueText() : ?string
public function getValueText() : string
{
return null;
return '';
}
}
2 changes: 1 addition & 1 deletion app/Model/User/CustomInputValue/CustomInputValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,5 @@ public function setUser(User $user) : void
$this->user = $user;
}

abstract public function getValueText() : ?string;
abstract public function getValueText() : string;
}
4 changes: 2 additions & 2 deletions app/Model/User/CustomInputValue/CustomMultiSelectValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions app/Model/User/CustomInputValue/CustomSelectValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ public function getValue() : ?int
return $this->value;
}

public function setValue(?int $value) : void
public function setValue(int $value) : void
{
$this->value = $value;
}

/**
* 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] : '';
}
}
8 changes: 4 additions & 4 deletions app/Model/User/CustomInputValue/CustomTextValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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 ?: '';
}
}
33 changes: 15 additions & 18 deletions app/WebModule/Forms/AdditionalInformationForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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:
Expand All @@ -210,7 +213,7 @@ public function createComponentForm() : Form
$custom->setDefaultValue($customInputValue->getValue());
}

$form->addComponent($custom, 'custom' . $customInput->getId());
$form->addComponent($custom, $customInputId);
break;

default:
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}

Expand Down
Loading

0 comments on commit 484ce8d

Please sign in to comment.