Skip to content

Commit

Permalink
Merge pull request #703 from jan-stanek/elixir
Browse files Browse the repository at this point in the history
opravy chyb pro elixir
  • Loading branch information
jan-stanek authored Feb 22, 2020
2 parents 2322ba3 + a7d20ec commit a2bcd7f
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 186 deletions.
35 changes: 0 additions & 35 deletions app/ActionModule/Presenters/MaturityPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,11 @@
use App\Model\Enums\ApplicationState;
use App\Model\Mailing\Template;
use App\Model\Mailing\TemplateVariable;
use App\Model\Program\ProgramRepository;
use App\Model\Settings\Settings;
use App\Model\Settings\SettingsException;
use App\Model\User\ApplicationRepository;
use App\Model\User\RolesApplicationRepository;
use App\Model\User\SubeventsApplicationRepository;
use App\Model\User\UserRepository;
use App\Services\ApplicationService;
use App\Services\MailService;
use App\Services\ProgramService;
use App\Services\SettingsService;
use App\Utils\Helpers;
use DateTimeImmutable;
Expand All @@ -41,18 +36,6 @@ class MaturityPresenter extends ActionBasePresenter
*/
public $em;

/**
* @var ApplicationRepository
* @inject
*/
public $applicationRepository;

/**
* @var ProgramRepository
* @inject
*/
public $programRepository;

/**
* @var UserRepository
* @inject
Expand All @@ -71,36 +54,18 @@ class MaturityPresenter extends ActionBasePresenter
*/
public $mailService;

/**
* @var ProgramService
* @inject
*/
public $programService;

/**
* @var ApplicationService
* @inject
*/
public $applicationService;

/**
* @var RolesApplicationRepository
* @inject
*/
public $rolesApplicationRepository;

/**
* @var SettingsService
* @inject
*/
public $settingsService;

/**
* @var SubeventsApplicationRepository
* @inject
*/
public $subeventsApplicationRepository;

/**
* Zruší přihlášky po splatnosti.
*
Expand Down
192 changes: 98 additions & 94 deletions app/AdminModule/Forms/EditUserSeminarFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,50 +133,52 @@ public function create(int $id) : Form

$form->addHidden('id');

$form->addMultiSelect(
'roles',
'admin.users.users_roles',
$this->aclService->getRolesWithoutRolesOptionsWithCapacity([Role::GUEST, Role::UNAPPROVED])
)
->addRule(Form::FILLED, 'admin.users.users_edit_roles_empty')
->addRule([$this, 'validateRolesNonregistered'], 'admin.users.users_edit_roles_nonregistered')
->addRule([$this, 'validateRolesCapacities'], 'admin.users.users_edit_roles_occupied');

$form->addCheckbox('approved', 'admin.users.users_approved_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');
}
if (! $this->user->isExternalLector()) {
$form->addMultiSelect(
'roles',
'admin.users.users_roles',
$this->aclService->getRolesWithoutRolesOptionsWithCapacity([Role::GUEST, Role::UNAPPROVED])
)
->addRule(Form::FILLED, 'admin.users.users_edit_roles_empty')
->addRule([$this, 'validateRolesNonregistered'], 'admin.users.users_edit_roles_nonregistered')
->addRule([$this, 'validateRolesCapacities'], 'admin.users.users_edit_roles_occupied');

$form->addCheckbox('approved', 'admin.users.users_approved_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->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());
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());
}
} elseif ($customInput instanceof CustomFile) {
$form->addUpload('custom' . $customInput->getId(), $customInput->getName());
}
}

Expand Down Expand Up @@ -220,66 +222,68 @@ public function processForm(Form $form, stdClass $values) : void
$loggedUser = $this->userRepository->findById($form->getPresenter()->user->id);

$this->em->transactional(function () use ($values, $loggedUser) : void {
$selectedRoles = $this->roleRepository->findRolesByIds($values->roles);
$this->applicationService->updateRoles($this->user, $selectedRoles, $loggedUser);

$this->user->setApproved($values->approved);
$this->user->setAttended($values->attended);

$customInputValueChanged = false;

foreach ($this->customInputRepository->findAllOrderedByPosition() as $customInput) {
$customInputValue = $this->user->getCustomInputValue($customInput);
$customInputName = 'custom' . $customInput->getId();
$oldValue = null;
$newValue = null;

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 CustomFile) {
/** @var CustomFileValue $customInputValue */
$customInputValue = $customInputValue ?: new CustomFileValue();
$oldValue = $customInputValue->getValue();
/** @var FileUpload $newValue */
$newValue = $values->$customInputName;
if ($newValue->getError() == UPLOAD_ERR_OK) {
$path = $this->generatePath($newValue);
$this->filesService->save($newValue, $path);
$customInputValue->setValue($path);
if (! $this->user->isExternalLector()) {
$selectedRoles = $this->roleRepository->findRolesByIds($values->roles);
$this->applicationService->updateRoles($this->user, $selectedRoles, $loggedUser);

$this->user->setApproved($values->approved);
$this->user->setAttended($values->attended);

foreach ($this->customInputRepository->findAllOrderedByPosition() as $customInput) {
$customInputValue = $this->user->getCustomInputValue($customInput);
$customInputName = 'custom' . $customInput->getId();
$oldValue = null;
$newValue = null;

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 CustomFile) {
/** @var CustomFileValue $customInputValue */
$customInputValue = $customInputValue ?: new CustomFileValue();
$oldValue = $customInputValue->getValue();
/** @var FileUpload $newValue */
$newValue = $values->$customInputName;
if ($newValue->getError() == UPLOAD_ERR_OK) {
$path = $this->generatePath($newValue);
$this->filesService->save($newValue, $path);
$customInputValue->setValue($path);
}
}
}

$customInputValue->setUser($this->user);
$customInputValue->setInput($customInput);
$this->customInputValueRepository->save($customInputValue);
$customInputValue->setUser($this->user);
$customInputValue->setInput($customInput);
$this->customInputValueRepository->save($customInputValue);

if ($oldValue !== $newValue) {
$customInputValueChanged = true;
if ($oldValue !== $newValue) {
$customInputValueChanged = true;
}
}
}

if (property_exists($values, 'arrival')) {
$this->user->setArrival($values->arrival);
}
if (property_exists($values, 'arrival')) {
$this->user->setArrival($values->arrival);
}

if (property_exists($values, 'departure')) {
$this->user->setDeparture($values->departure);
if (property_exists($values, 'departure')) {
$this->user->setDeparture($values->departure);
}
}

$this->user->setAbout($values->about);
Expand Down
2 changes: 1 addition & 1 deletion app/AdminModule/Presenters/UsersPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function renderDetail(int $id) : void
$this->template->paymentMethodCash = PaymentType::CASH;
$this->template->paymentMethodBank = PaymentType::BANK;

$this->template->registered = ! $user->isInRole($this->roleRepository->findBySystemName(Role::NONREGISTERED));
$this->template->registered = ! $user->isInRole($this->roleRepository->findBySystemName(Role::NONREGISTERED)) && ! $user->isExternalLector();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/AdminModule/Presenters/templates/@layout.latte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="cs">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">

<title>{_admin.common.title, [seminar_name => $seminarName]}</title>
Expand Down
Loading

0 comments on commit a2bcd7f

Please sign in to comment.