diff --git a/app/AccountancyModule/CampModule/presenters/ParticipantPresenter.php b/app/AccountancyModule/CampModule/presenters/ParticipantPresenter.php index 32481eb99..f729b18b5 100644 --- a/app/AccountancyModule/CampModule/presenters/ParticipantPresenter.php +++ b/app/AccountancyModule/CampModule/presenters/ParticipantPresenter.php @@ -141,6 +141,7 @@ protected function createComponentParticipantList(): ParticipantList true, $this->isAllowParticipantUpdate, $this->isAllowParticipantDelete, + $this->event->isOnlineLogin(), ); $control->onUpdate[] = function (array $updates): void { diff --git a/app/AccountancyModule/Components/Participants/EditParticipantDialog.php b/app/AccountancyModule/Components/Participants/EditParticipantDialog.php index 5a92d7155..127e62217 100644 --- a/app/AccountancyModule/Components/Participants/EditParticipantDialog.php +++ b/app/AccountancyModule/Components/Participants/EditParticipantDialog.php @@ -22,7 +22,7 @@ final class EditParticipantDialog extends Dialog public array $onUpdate = []; /** @param array $participants */ - public function __construct(private array $participants, private bool $isAllowedDaysUpdate, private bool $isAccountAllowed, private bool $isRepaymentAllowed) + public function __construct(private array $participants, private bool $isAllowedDaysUpdate, private bool $isAccountAllowed, private bool $isRepaymentAllowed, private bool $isOnlineLogin) { } @@ -48,10 +48,16 @@ protected function createComponentForm(): BaseForm $form = new BaseForm(); if ($this->isAllowedDaysUpdate) { - $form->addInteger('days', 'Počet dní') + $days = $form->addInteger('days', 'Počet dní') ->setRequired('Musíte vyplnit počet dní') ->addRule(BaseForm::MIN, 'Minimální počet dní je %d', 0) ->setDefaultValue($participant->getDays()); + if ($this->isOnlineLogin && ! $participant->isAccepted()) { + $days->setRequired(false) + ->setDisabled() + ->getControlPrototype() + ->setAttribute('title', 'Nelze upravovat dny pro osoby, které nejsou přijaty přes e-přihlášku'); + } } $form->addText('payment', 'Částka') @@ -81,7 +87,7 @@ protected function createComponentForm(): BaseForm $changes[UpdateParticipant::FIELD_PAYMENT] = $values['payment']; } - if ($this->isAllowedDaysUpdate && $values['days'] !== $participant->getDays()) { + if ($this->isAllowedDaysUpdate && isset($values['days']) && $values['days'] !== $participant->getDays()) { $changes[UpdateParticipant::FIELD_DAYS] = $values['days']; } @@ -93,7 +99,7 @@ protected function createComponentForm(): BaseForm $changes[UpdateParticipant::FIELD_IS_ACCOUNT] = $values['isAccount']; } - $this->onUpdate($this->participantId, $changes); + $this->onUpdate($this->participantId, $changes, $participant->isAccepted()); $this->hide(); }; diff --git a/app/AccountancyModule/Components/Participants/ParticipantList.php b/app/AccountancyModule/Components/Participants/ParticipantList.php index 9c66fedfa..1e9d9e065 100644 --- a/app/AccountancyModule/Components/Participants/ParticipantList.php +++ b/app/AccountancyModule/Components/Participants/ParticipantList.php @@ -8,6 +8,7 @@ use App\Forms\BaseForm; use Model\DTO\Participant\Participant; use Model\DTO\Participant\UpdateParticipant; +use Model\Participant\ParticipantNotFound; use Nette\Application\BadRequestException; use Nette\Forms\Controls\SubmitButton; use Nette\Http\IResponse; @@ -60,6 +61,7 @@ public function __construct( protected bool $isAllowIsAccount, protected bool $isAllowParticipantUpdate, protected bool $isAllowParticipantDelete, + protected bool $isOnlineLogin, ) { } @@ -162,13 +164,13 @@ public function handleEdit(int $participantId): void protected function createComponentEditDialog(): EditParticipantDialog { - $dialog = new EditParticipantDialog($this->participantsById(), $this->isAllowDaysUpdate, $this->isAllowIsAccount, $this->isAllowRepayment); + $dialog = new EditParticipantDialog($this->participantsById(), $this->isAllowDaysUpdate, $this->isAllowIsAccount, $this->isAllowRepayment, $this->isOnlineLogin); - $dialog->onUpdate[] = function (int $participantId, array $fields): void { + $dialog->onUpdate[] = function (int $participantId, array $fields, bool $isAccepted): void { $changes = []; foreach ($fields as $field => $value) { - $changes[] = new UpdateParticipant($this->aid, $participantId, $field, (string) $value); + $changes[] = new UpdateParticipant($this->aid, $participantId, $field, (string) $value, $isAccepted); } $this->onUpdate($changes); @@ -224,25 +226,36 @@ private function massEditSubmitted(SubmitButton $button): void $values = $button->getForm()->getValues()['edit']; - $changes = []; + $changes = []; + $currentParticipants = []; + foreach ($this->currentParticipants as $key => $p) { + $currentParticipants[$p->id] = $p; + } + foreach ($button->getForm()->getValues()->participantIds as $participantId) { + $participant = $currentParticipants[$participantId] ?? throw new ParticipantNotFound('Cannot find participant from the given data'); + if ($values['days'] !== null) { - $changes[] = new UpdateParticipant($this->aid, $participantId, UpdateParticipant::FIELD_DAYS, $values['days']); + if ($this->isOnlineLogin && ! $participant->isAccepted()) { + $this->flashMessage(sprintf('Nelze upravit hodnotu dny na táboře. Účastník %s není na tábor přihlášen.', $participant->displayName), 'warning'); + } else { + $changes[] = new UpdateParticipant($this->aid, $participantId, UpdateParticipant::FIELD_DAYS, $values['days'], $participant->isAccepted()); + } } if ($values['payment'] !== null) { - $changes[] = new UpdateParticipant($this->aid, $participantId, UpdateParticipant::FIELD_PAYMENT, $values['payment']); + $changes[] = new UpdateParticipant($this->aid, $participantId, UpdateParticipant::FIELD_PAYMENT, $values['payment'], $participant->isAccepted()); } if ($values['repayment'] !== null) { - $changes[] = new UpdateParticipant($this->aid, $participantId, UpdateParticipant::FIELD_REPAYMENT, $values['repayment']); + $changes[] = new UpdateParticipant($this->aid, $participantId, UpdateParticipant::FIELD_REPAYMENT, $values['repayment'], $participant->isAccepted()); } if (in_array($values['isAccount'], [self::NO_ACTION, null])) { continue; } - $changes[] = new UpdateParticipant($this->aid, $participantId, UpdateParticipant::FIELD_IS_ACCOUNT, $values['isAccount']); + $changes[] = new UpdateParticipant($this->aid, $participantId, UpdateParticipant::FIELD_IS_ACCOUNT, $values['isAccount'], $participant->isAccepted()); } $this->onUpdate($changes); diff --git a/app/AccountancyModule/EducationModule/presenters/ParticipantPresenter.php b/app/AccountancyModule/EducationModule/presenters/ParticipantPresenter.php index d32f07c9d..411fe10a9 100644 --- a/app/AccountancyModule/EducationModule/presenters/ParticipantPresenter.php +++ b/app/AccountancyModule/EducationModule/presenters/ParticipantPresenter.php @@ -104,6 +104,7 @@ protected function createComponentParticipantList(): ParticipantList true, $this->isAllowParticipantUpdate, false, + false, ); $control->onUpdate[] = function (array $updates): void { diff --git a/app/AccountancyModule/EventModule/presenters/ParticipantPresenter.php b/app/AccountancyModule/EventModule/presenters/ParticipantPresenter.php index 45a41984c..e14ebf2ea 100644 --- a/app/AccountancyModule/EventModule/presenters/ParticipantPresenter.php +++ b/app/AccountancyModule/EventModule/presenters/ParticipantPresenter.php @@ -131,6 +131,7 @@ protected function createComponentParticipantList(): ParticipantList false, $this->isAllowParticipantUpdate, $this->isAllowParticipantDelete, + false, ); $control->onUpdate[] = function (array $updates): void { diff --git a/app/AccountancyModule/Factories/Participants/IParticipantListFactory.php b/app/AccountancyModule/Factories/Participants/IParticipantListFactory.php index c594964e2..96ad3665f 100644 --- a/app/AccountancyModule/Factories/Participants/IParticipantListFactory.php +++ b/app/AccountancyModule/Factories/Participants/IParticipantListFactory.php @@ -18,5 +18,6 @@ public function create( bool $isAllowIsAccount, bool $isAllowParticipantUpdate, bool $isAllowParticipantDelete, + bool $isOnlineLogin, ): ParticipantList; } diff --git a/app/model/Participant/Exception/ParticipantNotFound.php b/app/model/Participant/Exception/ParticipantNotFound.php new file mode 100644 index 000000000..bc4aa1f17 --- /dev/null +++ b/app/model/Participant/Exception/ParticipantNotFound.php @@ -0,0 +1,11 @@ +