diff --git a/app/AccountancyModule/Components/Participants/EditParticipantDialog.php b/app/AccountancyModule/Components/Participants/EditParticipantDialog.php index 127e62217..be6fc9e98 100644 --- a/app/AccountancyModule/Components/Participants/EditParticipantDialog.php +++ b/app/AccountancyModule/Components/Participants/EditParticipantDialog.php @@ -9,6 +9,7 @@ use Assert\Assertion; use Closure; use Model\DTO\Participant\Participant; +use Model\DTO\Participant\ParticipatingPerson; use Model\DTO\Participant\UpdateParticipant; use function assert; @@ -21,7 +22,7 @@ final class EditParticipantDialog extends Dialog /** @var Closure[] */ public array $onUpdate = []; - /** @param array $participants */ + /** @param array $participants */ public function __construct(private array $participants, private bool $isAllowedDaysUpdate, private bool $isAccountAllowed, private bool $isRepaymentAllowed, private bool $isOnlineLogin) { } @@ -43,11 +44,12 @@ protected function createComponentForm(): BaseForm Assertion::keyExists($this->participants, $this->participantId); $participant = $this->participants[$this->participantId]; - assert($participant instanceof Participant); + assert($participant instanceof ParticipatingPerson); $form = new BaseForm(); if ($this->isAllowedDaysUpdate) { + assert($participant instanceof Participant); $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) @@ -87,7 +89,7 @@ protected function createComponentForm(): BaseForm $changes[UpdateParticipant::FIELD_PAYMENT] = $values['payment']; } - if ($this->isAllowedDaysUpdate && isset($values['days']) && $values['days'] !== $participant->getDays()) { + if ($this->isAllowedDaysUpdate && isset($values['days']) && $participant instanceof Participant && $values['days'] !== $participant->getDays()) { $changes[UpdateParticipant::FIELD_DAYS] = $values['days']; } @@ -99,7 +101,7 @@ protected function createComponentForm(): BaseForm $changes[UpdateParticipant::FIELD_IS_ACCOUNT] = $values['isAccount']; } - $this->onUpdate($this->participantId, $changes, $participant->isAccepted()); + $this->onUpdate($this->participantId, $changes, $participant instanceof Participant ? $participant->isAccepted() : null); $this->hide(); }; diff --git a/app/AccountancyModule/Components/Participants/ParticipantList.php b/app/AccountancyModule/Components/Participants/ParticipantList.php index a893fd9e6..6d3f9499e 100644 --- a/app/AccountancyModule/Components/Participants/ParticipantList.php +++ b/app/AccountancyModule/Components/Participants/ParticipantList.php @@ -7,6 +7,7 @@ use App\AccountancyModule\Components\BaseControl; use App\Forms\BaseForm; use Model\DTO\Participant\Participant; +use Model\DTO\Participant\ParticipatingPerson; use Model\DTO\Participant\UpdateParticipant; use Model\Participant\ParticipantNotFound; use Nette\Application\BadRequestException; @@ -53,7 +54,7 @@ final class ParticipantList extends BaseControl /** @persistent */ public string|null $sort = 'displayName'; - /** @param Participant[] $currentParticipants */ + /** @param ParticipatingPerson[] $currentParticipants */ public function __construct( public int $aid, private array $currentParticipants, @@ -63,6 +64,9 @@ public function __construct( protected bool $isAllowParticipantUpdate, protected bool $isAllowParticipantDelete, protected bool $isOnlineLogin, + protected bool $isAllowShowUnits, + protected string $title, + protected string $exportType, ) { } @@ -84,9 +88,11 @@ public function render(): void $this->template->setFile(__DIR__ . '/templates/ParticipantList.latte'); $this->template->setParameters([ 'aid' => $this->aid, + 'title' => $this->title, 'participants' => $this->currentParticipants, 'sort' => $this->sort, 'sortOptions' => $sortOptions, + 'isAllowShowUnits' => $this->isAllowShowUnits, 'showUnits' => $this->showUnits, 'isAllowDaysUpdate' => $this->isAllowDaysUpdate, 'isAllowRepayment' => $this->isAllowRepayment, @@ -94,12 +100,13 @@ public function render(): void 'isAllowParticipantUpdate' => $this->isAllowParticipantUpdate, 'isAllowParticipantDelete' => $this->isAllowParticipantDelete, 'isAllowAnyAction' => $this->isAllowParticipantUpdate || $this->isAllowParticipantDelete, + 'exportType' => $this->exportType, ]); $this->template->render(); } - /** @param Participant[] $participants */ + /** @param ParticipatingPerson[] $participants */ protected function sortParticipants(array &$participants, string $sort): void { if (! isset(self::SORT_OPTIONS[$sort])) { @@ -107,9 +114,9 @@ protected function sortParticipants(array &$participants, string $sort): void } if ($sort === 'displayName') { - $sortFunction = fn (Participant $a, Participant $b) => strcoll($a->{$sort}, $b->{$sort}); + $sortFunction = fn (ParticipatingPerson $a, ParticipatingPerson $b) => strcoll($a->{$sort}, $b->{$sort}); } else { - $sortFunction = fn (Participant $a, Participant $b) => $a->{$sort} <=> $b->{$sort}; + $sortFunction = fn (ParticipatingPerson $a, ParticipatingPerson $b) => $a->{$sort} <=> $b->{$sort}; } usort($participants, $sortFunction); @@ -144,7 +151,7 @@ public function handleRemove(int $participantId): void $this->onRemove([$participantId]); $this->currentParticipants = array_filter( $this->currentParticipants, - function (Participant $p) use ($participantId) { + function (ParticipatingPerson $p) use ($participantId) { return $p->getId() !== $participantId; }, ); @@ -167,7 +174,7 @@ protected function createComponentEditDialog(): EditParticipantDialog { $dialog = new EditParticipantDialog($this->participantsById(), $this->isAllowDaysUpdate, $this->isAllowIsAccount, $this->isAllowRepayment, $this->isOnlineLogin); - $dialog->onUpdate[] = function (int $participantId, array $fields, bool $isAccepted): void { + $dialog->onUpdate[] = function (int $participantId, array $fields, bool|null $isAccepted): void { $changes = []; foreach ($fields as $field => $value) { @@ -237,27 +244,29 @@ private function massEditSubmitted(SubmitButton $button): void foreach ($button->getForm()->getValues()->participantIds as $participantId) { $participant = $currentParticipants[$participantId] ?? throw new ParticipantNotFound('Cannot find participant from the given data'); + $isAccepted = $participant instanceof Participant ? $participant->isAccepted() : null; + if ($values['days'] !== null) { - if ($this->isOnlineLogin && ! $participant->isAccepted()) { + if ($this->isOnlineLogin && ! $isAccepted) { $participantUpdateError[] = $participant->displayName; } else { - $changes[] = new UpdateParticipant($this->aid, $participantId, UpdateParticipant::FIELD_DAYS, $values['days'], $participant->isAccepted()); + $changes[] = new UpdateParticipant($this->aid, $participantId, UpdateParticipant::FIELD_DAYS, $values['days'], $isAccepted); } } if ($values['payment'] !== null) { - $changes[] = new UpdateParticipant($this->aid, $participantId, UpdateParticipant::FIELD_PAYMENT, $values['payment'], $participant->isAccepted()); + $changes[] = new UpdateParticipant($this->aid, $participantId, UpdateParticipant::FIELD_PAYMENT, $values['payment'], $isAccepted); } if ($values['repayment'] !== null) { - $changes[] = new UpdateParticipant($this->aid, $participantId, UpdateParticipant::FIELD_REPAYMENT, $values['repayment'], $participant->isAccepted()); + $changes[] = new UpdateParticipant($this->aid, $participantId, UpdateParticipant::FIELD_REPAYMENT, $values['repayment'], $isAccepted); } if (in_array($values['isAccount'], [self::NO_ACTION, null])) { continue; } - $changes[] = new UpdateParticipant($this->aid, $participantId, UpdateParticipant::FIELD_IS_ACCOUNT, $values['isAccount'], $participant->isAccepted()); + $changes[] = new UpdateParticipant($this->aid, $participantId, UpdateParticipant::FIELD_IS_ACCOUNT, $values['isAccount'], $isAccepted); } if (! empty($participantUpdateError)) { @@ -287,7 +296,7 @@ private function massRemoveSubmitted(SubmitButton $button): void $this->reload('Účastníci byli odebráni'); } - /** @return array Participant's indexed by their ID */ + /** @return array Participant's indexed by their ID */ private function participantsById(): array { $participants = []; diff --git a/app/AccountancyModule/Components/Participants/templates/ParticipantList.latte b/app/AccountancyModule/Components/Participants/templates/ParticipantList.latte index d70410699..6c913e783 100644 --- a/app/AccountancyModule/Components/Participants/templates/ParticipantList.latte +++ b/app/AccountancyModule/Components/Participants/templates/ParticipantList.latte @@ -58,7 +58,7 @@ $showUnits bool - zobrazovat číslo jednotky {var $tabIndex = 1}
-

Seznam účastníků

+

{$title}