diff --git a/app/AdminModule/Components/UsersGridControl.php b/app/AdminModule/Components/UsersGridControl.php index 702a4fd60..cdb1a8ccf 100644 --- a/app/AdminModule/Components/UsersGridControl.php +++ b/app/AdminModule/Components/UsersGridControl.php @@ -10,14 +10,16 @@ use App\Model\Enums\PaymentType; use App\Model\Enums\SkautIsEventType; use App\Model\Settings\CustomInput\CustomCheckbox; +use App\Model\Settings\CustomInput\CustomDate; +use App\Model\Settings\CustomInput\CustomDateTime; use App\Model\Settings\CustomInput\CustomInputRepository; +use App\Model\Settings\CustomInput\CustomMultiSelect; use App\Model\Settings\CustomInput\CustomSelect; use App\Model\Settings\CustomInput\CustomText; use App\Model\Settings\Settings; use App\Model\Settings\SettingsException; use App\Model\User\CustomInputValue\CustomCheckboxValue; use App\Model\User\CustomInputValue\CustomFileValue; -use App\Model\User\CustomInputValue\CustomSelectValue; use App\Model\User\CustomInputValue\CustomTextValue; use App\Model\User\User; use App\Model\User\UserRepository; @@ -48,7 +50,6 @@ use Ublaboo\DataGrid\DataGrid; use Ublaboo\DataGrid\Exception\DataGridColumnStatusException; use Ublaboo\DataGrid\Exception\DataGridException; -use function array_merge; use function array_slice; use function array_values; use function explode; @@ -351,8 +352,6 @@ public function createComponentUsersGrid(string $name) : void return $customInputValue->getValue() ? $this->translator->translate('admin.common.yes') : $this->translator->translate('admin.common.no'); - case $customInputValue instanceof CustomSelectValue: - return $customInputValue->getValueOption(); case $customInputValue instanceof CustomFileValue: return $customInputValue->getValue() ? Html::el('a') @@ -365,6 +364,8 @@ public function createComponentUsersGrid(string $name) : void Html::el('span')->setAttribute('class', 'fa fa-download') ) : ''; + default: + return $customInputValue->getValueText(); } } @@ -405,22 +406,56 @@ public function createComponentUsersGrid(string $name) : void break; case $customInput instanceof CustomSelect: - $columnCustomInput->setFilterSelect(array_merge(['' => 'admin.common.all'], $customInput->getSelectOptions())) - ->setCondition(static function (QueryBuilder $qb, string $value) use ($customInput) : void { - if ($value === '') { - return; - } else { - $qb->leftJoin('u.customInputValues', 'uCIV3') - ->leftJoin('uCIV3.input', 'uCIVI3') - ->leftJoin('App\Model\User\CustomInputValue\CustomSelectValue', 'uCSV', 'WITH', 'uCIV3.id = uCSV.id') - ->andWhere('uCIVI3.id = :iid3 OR uCIVI3.id IS NULL') - ->andWhere('uCSV.value = :ivalue3') - ->setParameter('iid3', $customInput->getId()) - ->setParameter('ivalue3', $value); - } + $columnCustomInput->setFilterMultiSelect($customInput->getFilterOptions()) + ->setCondition(static function (QueryBuilder $qb, ArrayHash $values) use ($customInput) : void { + $qb->leftJoin('u.customInputValues', 'uCIV3') + ->leftJoin('uCIV3.input', 'uCIVI3') + ->leftJoin('App\Model\User\CustomInputValue\CustomSelectValue', 'uCSV', 'WITH', 'uCIV3.id = uCSV.id') + ->andWhere('uCIVI3.id = :iid3 OR uCIVI3.id IS NULL') + ->andWhere('uCSV.value in (:ivalues3)') + ->setParameter('iid3', $customInput->getId()) + ->setParameter('ivalues3', (array) $values); }) ->setTranslateOptions(); break; + + case $customInput instanceof CustomMultiSelect: + $columnCustomInput->setFilterMultiSelect($customInput->getSelectOptions()) + ->setCondition(static function (QueryBuilder $qb, ArrayHash $values) use ($customInput) : void { + $qb->leftJoin('u.customInputValues', 'uCIV4') + ->leftJoin('uCIV4.input', 'uCIVI4') + ->leftJoin('App\Model\User\CustomInputValue\CustomMultiSelectValue', 'uCMSV', 'WITH', 'uCIV4.id = uCMSV.id') + ->andWhere('uCIVI4.id = :iid4 OR uCIVI4.id IS NULL') + ->andWhere('uCMSV.value in (:ivalues4)') + ->setParameter('iid4', $customInput->getId()) + ->setParameter('ivalues4', (array) $values); + }) + ->setTranslateOptions(); + break; + + case $customInput instanceof CustomDate: + $columnCustomInput->setSortable() + ->setSortableCallback(static function (QueryBuilder $qb, array $sort) use ($customInput, $columnCustomInputName) : void { + $qb->leftJoin('u.customInputValues', 'uCIV5') + ->leftJoin('uCIV5.input', 'uCIVI5') + ->leftJoin('App\Model\User\CustomInputValue\CustomDateValue', 'uCDV', 'WITH', 'uCIV5.id = uCDV.id') + ->andWhere('uCIVI5.id = :iid5 OR uCIVI5.id IS NULL') + ->setParameter('iid5', $customInput->getId()) + ->orderBy('uCDV.value', $sort[$columnCustomInputName]); + }); + break; + + case $customInput instanceof CustomDateTime: + $columnCustomInput->setSortable() + ->setSortableCallback(static function (QueryBuilder $qb, array $sort) use ($customInput, $columnCustomInputName) : void { + $qb->leftJoin('u.customInputValues', 'uCIV6') + ->leftJoin('uCIV6.input', 'uCIVI6') + ->leftJoin('App\Model\User\CustomInputValue\CustomDateTimeValue', 'uCDTV', 'WITH', 'uCIV6.id = uCDTV.id') + ->andWhere('uCIVI6.id = :iid6 OR uCIVI6.id IS NULL') + ->setParameter('iid6', $customInput->getId()) + ->orderBy('uCDTV.value', $sort[$columnCustomInputName]); + }); + break; } } diff --git a/app/AdminModule/ConfigurationModule/Components/CustomInputsGridControl.php b/app/AdminModule/ConfigurationModule/Components/CustomInputsGridControl.php index e7252d24d..227c4c8e2 100644 --- a/app/AdminModule/ConfigurationModule/Components/CustomInputsGridControl.php +++ b/app/AdminModule/ConfigurationModule/Components/CustomInputsGridControl.php @@ -4,9 +4,12 @@ namespace App\AdminModule\ConfigurationModule\Components; +use App\Model\Acl\Role; use App\Model\Settings\CustomInput\CustomInput; use App\Model\Settings\CustomInput\CustomInputRepository; +use App\Model\Settings\CustomInput\CustomMultiSelect; use App\Model\Settings\CustomInput\CustomSelect; +use App\Services\AclService; use Doctrine\ORM\NonUniqueResultException; use Doctrine\ORM\ORMException; use Nette\Application\AbortException; @@ -15,6 +18,7 @@ use Ublaboo\DataGrid\DataGrid; use Ublaboo\DataGrid\Exception\DataGridColumnStatusException; use Ublaboo\DataGrid\Exception\DataGridException; +use function count; /** * Komponenta pro správu vlastních polí přihlášky. @@ -27,10 +31,16 @@ class CustomInputsGridControl extends Control private CustomInputRepository $customInputRepository; - public function __construct(ITranslator $translator, CustomInputRepository $customInputRepository) - { + private AclService $aclService; + + public function __construct( + ITranslator $translator, + CustomInputRepository $customInputRepository, + AclService $aclService + ) { $this->translator = $translator; $this->customInputRepository = $customInputRepository; + $this->aclService = $aclService; } /** @@ -59,6 +69,13 @@ public function createComponentCustomInputsGrid(string $name) : void $grid->addColumnText('name', 'admin.configuration.custom_inputs_name'); + $grid->addColumnText('roles', 'admin.configuration.custom_inputs_roles', 'rolesText') + ->setRendererOnCondition(function () { + return $this->translator->translate('admin.configuration.custom_inputs_roles_all'); + }, function (CustomInput $input) { + return count($this->aclService->getRolesWithoutRolesOptions([Role::GUEST, Role::UNAPPROVED, Role::NONREGISTERED])) === $input->getRoles()->count(); + }); + $grid->addColumnText('type', 'admin.configuration.custom_inputs_type') ->setRenderer(function (CustomInput $input) { return $this->translator->translate('admin.common.custom_' . $input->getType()); @@ -76,7 +93,7 @@ public function createComponentCustomInputsGrid(string $name) : void $grid->addColumnText('options', 'admin.configuration.custom_inputs_options') ->setRenderer(static function (CustomInput $input) { - return $input instanceof CustomSelect ? $input->getOptions() : null; + return $input instanceof CustomSelect || $input instanceof CustomMultiSelect ? $input->getOptionsText() : null; }); $grid->addToolbarButton('Application:add') diff --git a/app/AdminModule/ConfigurationModule/Forms/CustomInputFormFactory.php b/app/AdminModule/ConfigurationModule/Forms/CustomInputFormFactory.php index b9e84d098..b4f2c2fb6 100644 --- a/app/AdminModule/ConfigurationModule/Forms/CustomInputFormFactory.php +++ b/app/AdminModule/ConfigurationModule/Forms/CustomInputFormFactory.php @@ -5,19 +5,27 @@ namespace App\AdminModule\ConfigurationModule\Forms; use App\AdminModule\Forms\BaseFormFactory; +use App\Model\Acl\Role; +use App\Model\Acl\RoleRepository; use App\Model\Settings\CustomInput\CustomCheckbox; +use App\Model\Settings\CustomInput\CustomDate; +use App\Model\Settings\CustomInput\CustomDateTime; use App\Model\Settings\CustomInput\CustomFile; use App\Model\Settings\CustomInput\CustomInput; use App\Model\Settings\CustomInput\CustomInputRepository; +use App\Model\Settings\CustomInput\CustomMultiSelect; use App\Model\Settings\CustomInput\CustomSelect; use App\Model\Settings\CustomInput\CustomText; +use App\Services\AclService; +use App\Utils\Helpers; use Doctrine\ORM\NonUniqueResultException; use Doctrine\ORM\ORMException; use Nette; use Nette\Application\UI\Form; use stdClass; +use function array_keys; +use function array_map; use function explode; -use function implode; use function trim; /** @@ -38,10 +46,20 @@ class CustomInputFormFactory private CustomInputRepository $customInputRepository; - public function __construct(BaseFormFactory $baseFormFactory, CustomInputRepository $customInputRepository) - { + private AclService $aclService; + + private RoleRepository $roleRepository; + + public function __construct( + BaseFormFactory $baseFormFactory, + CustomInputRepository $customInputRepository, + AclService $aclService, + RoleRepository $roleRepository + ) { $this->baseFormFactory = $baseFormFactory; $this->customInputRepository = $customInputRepository; + $this->aclService = $aclService; + $this->roleRepository = $roleRepository; } /** @@ -58,8 +76,13 @@ public function create(int $id) : Form $form->addText('name', 'admin.configuration.custom_inputs_name') ->addRule(Form::FILLED, 'admin.configuration.custom_inputs_name_empty'); + $rolesOptions = $this->aclService->getRolesWithoutRolesOptions([Role::GUEST, Role::UNAPPROVED, Role::NONREGISTERED]); + $rolesSelect = $form->addMultiSelect('roles', 'admin.configuration.custom_inputs_roles', $rolesOptions) + ->addRule(Form::FILLED, 'admin.configuration.custom_inputs_roles_empty'); + $typeSelect = $form->addSelect('type', 'admin.configuration.custom_inputs_type', $this->prepareCustomInputTypesOptions()); $typeSelect->addCondition($form::EQUAL, CustomInput::SELECT)->toggle('custom-input-select'); + $typeSelect->addCondition($form::EQUAL, CustomInput::MULTISELECT)->toggle('custom-input-select'); $form->addCheckbox('mandatory', 'admin.configuration.custom_inputs_edit_mandatory'); @@ -79,14 +102,17 @@ public function create(int $id) : Form $form->setDefaults([ 'id' => $id, 'name' => $this->customInput->getName(), + 'roles' => Helpers::getIds($this->customInput->getRoles()), 'type' => $this->customInput->getType(), 'mandatory' => $this->customInput->isMandatory(), ]); - if ($this->customInput instanceof CustomSelect) { + if ($this->customInput instanceof CustomSelect || $this->customInput instanceof CustomMultiSelect) { $customInput = $this->customInput; - $optionsText->setDefaultValue($customInput->getOptions()); + $optionsText->setDefaultValue($customInput->getOptionsText()); } + } else { + $rolesSelect->setDefaultValue(array_keys($rolesOptions)); } $form->onSuccess[] = [$this, 'processForm']; @@ -118,24 +144,42 @@ public function processForm(Form $form, stdClass $values) : void case CustomInput::SELECT: $this->customInput = new CustomSelect(); + $options = array_map( + static function (string $o) { + return trim($o); + }, + explode(',', $values->options) + ); + $this->customInput->setOptions($options); + break; - $options = explode(',', $values->options); - $optionsTrimmed = []; - foreach ($options as $option) { - $optionsTrimmed[] = trim($option); - } - - $this->customInput->setOptions(implode(', ', $optionsTrimmed)); - + case CustomInput::MULTISELECT: + $this->customInput = new CustomMultiSelect(); + $options = array_map( + static function (string $o) { + return trim($o); + }, + explode(',', $values->options) + ); + $this->customInput->setOptions($options); break; case CustomInput::FILE: $this->customInput = new CustomFile(); break; + + case CustomInput::DATE: + $this->customInput = new CustomDate(); + break; + + case CustomInput::DATETIME: + $this->customInput = new CustomDateTime(); + break; } } $this->customInput->setName($values->name); + $this->customInput->setRoles($this->roleRepository->findRolesByIds($values->roles)); $this->customInput->setMandatory($values->mandatory); $this->customInputRepository->save($this->customInput); diff --git a/app/AdminModule/Forms/AddRoleFormFactory.php b/app/AdminModule/Forms/AddRoleFormFactory.php index 2ce45797f..42e6552ef 100644 --- a/app/AdminModule/Forms/AddRoleFormFactory.php +++ b/app/AdminModule/Forms/AddRoleFormFactory.php @@ -113,7 +113,6 @@ public function processForm(Form $form, stdClass $values) : void $role->setRegisterable($parent->isRegisterable()); $role->setRegisterableFrom($parent->getRegisterableFrom()); $role->setRegisterableTo($parent->getRegisterableTo()); - $role->setDisplayArrivalDeparture($parent->isDisplayArrivalDeparture()); } else { $nonregistered = $this->roleRepository->findBySystemName(Role::NONREGISTERED); foreach ($nonregistered->getPages() as $page) { diff --git a/app/AdminModule/Forms/EditRoleFormFactory.php b/app/AdminModule/Forms/EditRoleFormFactory.php index 63b8454bb..0874767fc 100644 --- a/app/AdminModule/Forms/EditRoleFormFactory.php +++ b/app/AdminModule/Forms/EditRoleFormFactory.php @@ -120,8 +120,6 @@ public function create(int $id) : Form // $form->addCheckbox('syncedWithSkautIs', 'admin.acl.roles_synced_with_skaut_is'); - $form->addCheckbox('displayArrivalDeparture', 'admin.acl.roles_display_arrival_departure'); - $form->addCheckbox('feeFromSubevents', 'admin.acl.roles_fee_from_subevents_checkbox') ->addCondition(Form::EQUAL, false) ->toggle('fee'); @@ -189,7 +187,6 @@ public function create(int $id) : Form 'capacity' => $this->role->getCapacity(), 'approvedAfterRegistration' => $this->role->isApprovedAfterRegistration(), // 'syncedWithSkautIs' => $this->role->isSyncedWithSkautIS(), - 'displayArrivalDeparture' => $this->role->isDisplayArrivalDeparture(), 'feeFromSubevents' => $this->role->getFee() === null, 'fee' => $this->role->getFee(), 'minimumAge' => $this->role->getMinimumAge(), @@ -226,7 +223,6 @@ public function processForm(Form $form, stdClass $values) : void $this->role->setCapacity($capacity); $this->role->setApprovedAfterRegistration($values->approvedAfterRegistration); // $this->role->setSyncedWithSkautIS($values->syncedWithSkautIs); - $this->role->setDisplayArrivalDeparture($values->displayArrivalDeparture); $this->role->setMinimumAge($values->minimumAge); $this->role->setPermissions($this->permissionRepository->findPermissionsByIds($values->permissions)); $this->role->setPages($this->pageRepository->findPagesBySlugs($values->pages)); diff --git a/app/AdminModule/Forms/EditUserSeminarFormFactory.php b/app/AdminModule/Forms/EditUserSeminarFormFactory.php index 3023272ae..498cd68b7 100644 --- a/app/AdminModule/Forms/EditUserSeminarFormFactory.php +++ b/app/AdminModule/Forms/EditUserSeminarFormFactory.php @@ -9,14 +9,20 @@ use App\Model\Mailing\Template; use App\Model\Mailing\TemplateVariable; use App\Model\Settings\CustomInput\CustomCheckbox; +use App\Model\Settings\CustomInput\CustomDate; +use App\Model\Settings\CustomInput\CustomDateTime; use App\Model\Settings\CustomInput\CustomFile; use App\Model\Settings\CustomInput\CustomInputRepository; +use App\Model\Settings\CustomInput\CustomMultiSelect; use App\Model\Settings\CustomInput\CustomSelect; use App\Model\Settings\CustomInput\CustomText; use App\Model\Settings\Settings; use App\Model\User\CustomInputValue\CustomCheckboxValue; +use App\Model\User\CustomInputValue\CustomDateTimeValue; +use App\Model\User\CustomInputValue\CustomDateValue; use App\Model\User\CustomInputValue\CustomFileValue; use App\Model\User\CustomInputValue\CustomInputValueRepository; +use App\Model\User\CustomInputValue\CustomMultiSelectValue; use App\Model\User\CustomInputValue\CustomSelectValue; use App\Model\User\CustomInputValue\CustomTextValue; use App\Model\User\User; @@ -26,7 +32,9 @@ use App\Services\FilesService; use App\Services\MailService; use App\Services\SettingsService; +use App\Utils\Helpers; use App\Utils\Validators; +use InvalidArgumentException; use Nette; use Nette\Application\UI\Form; use Nette\Forms\Controls\MultiSelectBox; @@ -34,10 +42,10 @@ use Nette\Utils\Random; use Nette\Utils\Strings; use Nettrine\ORM\EntityManagerDecorator; +use Nextras\FormComponents\Controls\DateControl; use Nextras\FormComponents\Controls\DateTimeControl; use stdClass; use Throwable; -use function property_exists; use const UPLOAD_ERR_OK; /** @@ -120,7 +128,7 @@ public function create(int $id) : Form $form->addHidden('id'); if (! $this->user->isExternalLector()) { - $form->addMultiSelect( + $rolesSelect = $form->addMultiSelect( 'roles', 'admin.users.users_roles', $this->aclService->getRolesWithoutRolesOptionsWithCapacity([Role::GUEST, Role::UNAPPROVED]) @@ -133,38 +141,84 @@ public function create(int $id) : Form $form->addCheckbox('attended', 'admin.users.users_attended_form'); - if ($this->user->hasDisplayArrivalDepartureRole()) { - $arrivalDateTime = new DateTimeControl('admin.users.users_arrival'); - $form->addComponent($arrivalDateTime, 'arrival'); - $departureDateTime = new DateTimeControl('admin.users.users_departure'); - $form->addComponent($departureDateTime, 'departure'); - } + foreach ($this->customInputRepository->findAll() as $customInput) { + $customInputId = 'custom' . $customInput->getId(); - foreach ($this->customInputRepository->findAllOrderedByPosition() as $customInput) { - if ($customInput instanceof CustomText) { - $custom = $form->addText('custom' . $customInput->getId(), $customInput->getName()); - /** @var ?CustomTextValue $customInputValue */ - $customInputValue = $this->user->getCustomInputValue($customInput); - if ($customInputValue) { - $custom->setDefaultValue($customInputValue->getValue()); - } - } elseif ($customInput instanceof CustomCheckbox) { - $custom = $form->addCheckbox('custom' . $customInput->getId(), $customInput->getName()); - /** @var ?CustomCheckboxValue $customInputValue */ - $customInputValue = $this->user->getCustomInputValue($customInput); - if ($customInputValue) { - $custom->setDefaultValue($customInputValue->getValue()); - } - } elseif ($customInput instanceof CustomSelect) { - $custom = $form->addSelect('custom' . $customInput->getId(), $customInput->getName(), $customInput->getSelectOptions()); - /** @var ?CustomSelectValue $customInputValue */ - $customInputValue = $this->user->getCustomInputValue($customInput); - if ($customInputValue) { - $custom->setDefaultValue($customInputValue->getValue()); - } - } elseif ($customInput instanceof CustomFile) { - $form->addUpload('custom' . $customInput->getId(), $customInput->getName()); + switch (true) { + case $customInput instanceof CustomText: + $custom = $form->addText($customInputId, $customInput->getName()); + /** @var ?CustomTextValue $customInputValue */ + $customInputValue = $this->user->getCustomInputValue($customInput); + if ($customInputValue) { + $custom->setDefaultValue($customInputValue->getValue()); + } + + break; + + case $customInput instanceof CustomCheckbox: + $custom = $form->addCheckbox($customInputId, $customInput->getName()); + /** @var ?CustomCheckboxValue $customInputValue */ + $customInputValue = $this->user->getCustomInputValue($customInput); + if ($customInputValue) { + $custom->setDefaultValue($customInputValue->getValue()); + } + + break; + + case $customInput instanceof CustomSelect: + $custom = $form->addSelect($customInputId, $customInput->getName(), $customInput->getSelectOptions()); + /** @var ?CustomSelectValue $customInputValue */ + $customInputValue = $this->user->getCustomInputValue($customInput); + if ($customInputValue) { + $custom->setDefaultValue($customInputValue->getValue()); + } + + break; + + case $customInput instanceof CustomMultiSelect: + $custom = $form->addMultiSelect($customInputId, $customInput->getName(), $customInput->getSelectOptions()); + /** @var ?CustomMultiSelectValue $customInputValue */ + $customInputValue = $this->user->getCustomInputValue($customInput); + if ($customInputValue) { + $custom->setDefaultValue($customInputValue->getValue()); + } + + break; + + case $customInput instanceof CustomFile: + $custom = $form->addUpload($customInputId, $customInput->getName()); + break; + + case $customInput instanceof CustomDate: + $custom = new DateControl($customInput->getName()); + /** @var ?CustomDateValue $customInputValue */ + $customInputValue = $this->user->getCustomInputValue($customInput); + if ($customInputValue) { + $custom->setDefaultValue($customInputValue->getValue()); + } + + $form->addComponent($custom, $customInputId); + break; + + case $customInput instanceof CustomDateTime: + $custom = new DateTimeControl($customInput->getName()); + /** @var ?CustomDateTimeValue $customInputValue */ + $customInputValue = $this->user->getCustomInputValue($customInput); + if ($customInputValue) { + $custom->setDefaultValue($customInputValue->getValue()); + } + + $form->addComponent($custom, $customInputId); + break; + + default: + throw new InvalidArgumentException(); } + + $custom->setOption('id', 'form-group-' . $customInputId); + + $rolesSelect->addCondition(self::class . '::toggleCustomInputVisibility', Helpers::getIds($customInput->getRoles())) + ->toggle('form-group-' . $customInputId); } } @@ -183,8 +237,6 @@ public function create(int $id) : Form 'roles' => $this->roleRepository->findRolesIds($this->user->getRoles()), 'approved' => $this->user->isApproved(), 'attended' => $this->user->isAttended(), - 'arrival' => $this->user->getArrival(), - 'departure' => $this->user->getDeparture(), 'about' => $this->user->getAbout(), 'privateNote' => $this->user->getNote(), ]); @@ -217,7 +269,7 @@ public function processForm(Form $form, stdClass $values) : void $this->user->setApproved($values->approved); $this->user->setAttended($values->attended); - foreach ($this->customInputRepository->findAllOrderedByPosition() as $customInput) { + foreach ($this->customInputRepository->findByRolesOrderedByPosition($this->user->getRoles()) as $customInput) { $customInputValue = $this->user->getCustomInputValue($customInput); $customInputName = 'custom' . $customInput->getId(); $oldValue = null; @@ -241,6 +293,12 @@ public function processForm(Form $form, stdClass $values) : void $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(); @@ -252,6 +310,18 @@ public function processForm(Form $form, stdClass $values) : void $this->filesService->save($newValue, $path); $customInputValue->setValue($path); } + } elseif ($customInput instanceof CustomDate) { + /** @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); } $customInputValue->setUser($this->user); @@ -262,14 +332,6 @@ public function processForm(Form $form, stdClass $values) : void $customInputValueChanged = true; } } - - if (property_exists($values, 'arrival')) { - $this->user->setArrival($values->arrival); - } - - if (property_exists($values, 'departure')) { - $this->user->setDeparture($values->departure); - } } $this->user->setAbout($values->about); @@ -307,6 +369,17 @@ public function validateRolesCapacities(MultiSelectBox $field) : bool return $this->validators->validateRolesCapacities($selectedRoles, $this->user); } + /** + * Přepíná zobrazení vlastních polí podle kombinace rolí. + * Je nutná, na výsledku nezáleží (používá se javascript funkce). + * + * @param int[] $customInputRoles + */ + public static function toggleCustomInputVisibility(MultiSelectBox $field, array $customInputRoles) : bool + { + return false; + } + /** * Vygeneruje cestu souboru. */ diff --git a/app/AdminModule/Presenters/UsersPresenter.php b/app/AdminModule/Presenters/UsersPresenter.php index 3a96ed9bf..e181e597e 100644 --- a/app/AdminModule/Presenters/UsersPresenter.php +++ b/app/AdminModule/Presenters/UsersPresenter.php @@ -80,10 +80,8 @@ public function renderDetail(int $id) : void $this->template->detailUser = $user; - $this->template->customInputs = $this->customInputRepository->findAllOrderedByPosition(); - $this->template->customInputTypeText = CustomInput::TEXT; + $this->template->customInputs = $this->customInputRepository->findByRolesOrderedByPosition($user->getRoles()); $this->template->customInputTypeCheckbox = CustomInput::CHECKBOX; - $this->template->customInputTypeSelect = CustomInput::SELECT; $this->template->customInputTypeFile = CustomInput::FILE; $this->template->roleAdminName = $this->roleRepository->findBySystemName(Role::ADMIN)->getName(); diff --git a/app/AdminModule/Presenters/templates/Users/detail.latte b/app/AdminModule/Presenters/templates/Users/detail.latte index 1ea46d3ef..b73656666 100644 --- a/app/AdminModule/Presenters/templates/Users/detail.latte +++ b/app/AdminModule/Presenters/templates/Users/detail.latte @@ -106,38 +106,24 @@ - {if $detailUser->hasDisplayArrivalDepartureRole()} -