Skip to content

Commit 74c252a

Browse files
authored
Komponenta vstupenky (#1088)
* lang refactoring, ticket content * db migration, components * cs fix * dbuser * phpstan fix * phpstan fix * fixes * fixes * fixes * presenter getters * optimizations * fixes * phpstan fix * fixes * revert mail, fix * mandatory user * component finished * cs fix * mail fix * revert guestrole change * fix * fixes * is allowed optimization
1 parent cb26335 commit 74c252a

File tree

88 files changed

+795
-465
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+795
-465
lines changed

app/AdminModule/CmsModule/Forms/FaqFormFactory.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use App\AdminModule\Forms\BaseFormFactory;
88
use App\Model\Cms\Faq;
99
use App\Model\Cms\Repositories\FaqRepository;
10-
use App\Model\User\Repositories\UserRepository;
1110
use App\Model\User\User;
1211
use Doctrine\ORM\NonUniqueResultException;
1312
use Doctrine\ORM\NoResultException;
@@ -30,22 +29,21 @@ class FaqFormFactory
3029
/**
3130
* Přihlášený uživatel.
3231
*/
33-
private User|null $user = null;
32+
private User $user;
3433

3534
public function __construct(
3635
private readonly BaseFormFactory $baseFormFactory,
3736
private readonly FaqRepository $faqRepository,
38-
private readonly UserRepository $userRepository,
3937
) {
4038
}
4139

4240
/**
4341
* Vytvoří formulář.
4442
*/
45-
public function create(int|null $id, int $userId): Form
43+
public function create(int|null $id, User $user): Form
4644
{
4745
$this->faq = $id === null ? null : $this->faqRepository->findById($id);
48-
$this->user = $this->userRepository->findById($userId);
46+
$this->user = $user;
4947

5048
$form = $this->baseFormFactory->create();
5149

app/AdminModule/CmsModule/Presenters/FaqPresenter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected function createComponentFaqGrid(): FaqGridControl
3737

3838
protected function createComponentFaqForm(): Form
3939
{
40-
$form = $this->faqFormFactory->create((int) $this->getParameter('id'), $this->user->id);
40+
$form = $this->faqFormFactory->create((int) $this->getParameter('id'), $this->dbUser);
4141

4242
$form->onSuccess[] = function (Form $form, stdClass $values): void {
4343
if ($form->isSubmitted() == $form['cancel']) {

app/AdminModule/Components/ApplicationsGridControl.php

+9-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace App\AdminModule\Components;
66

7+
use App\AdminModule\Presenters\AdminBasePresenter;
78
use App\Model\Application\Application;
89
use App\Model\Application\Repositories\ApplicationRepository;
910
use App\Model\Application\RolesApplication;
@@ -32,6 +33,8 @@
3233
use Ublaboo\DataGrid\DataGrid;
3334
use Ublaboo\DataGrid\Exception\DataGridException;
3435

36+
use function assert;
37+
3538
/**
3639
* Komponenta pro správu přihlášek.
3740
*/
@@ -211,6 +214,7 @@ public function add(stdClass $values): void
211214
$selectedSubevents = $this->subeventRepository->findSubeventsByIds($values->subevents);
212215

213216
$p = $this->getPresenter();
217+
assert($p instanceof AdminBasePresenter);
214218

215219
if (! $this->validators->validateSubeventsCapacities($selectedSubevents, $this->user)) {
216220
$p->flashMessage('admin.users.users_applications_subevents_occupied', 'danger');
@@ -226,9 +230,7 @@ public function add(stdClass $values): void
226230
return;
227231
}
228232

229-
$loggedUser = $this->userRepository->findById($this->getPresenter()->user->id);
230-
231-
$this->applicationService->addSubeventsApplication($this->user, $selectedSubevents, $loggedUser);
233+
$this->applicationService->addSubeventsApplication($this->user, $selectedSubevents, $p->getDbUser());
232234

233235
$p->flashMessage('admin.users.users_applications_saved', 'success');
234236
$p->redrawControl('flashes');
@@ -246,6 +248,7 @@ public function edit(string $id, stdClass $values): void
246248
$selectedSubevents = $this->subeventRepository->findSubeventsByIds($values->subevents);
247249

248250
$p = $this->getPresenter();
251+
assert($p instanceof AdminBasePresenter);
249252

250253
if ($application instanceof RolesApplication) {
251254
if (! $selectedSubevents->isEmpty()) {
@@ -277,7 +280,7 @@ public function edit(string $id, stdClass $values): void
277280
return;
278281
}
279282

280-
$loggedUser = $this->userRepository->findById($this->getPresenter()->user->id);
283+
$loggedUser = $p->getDbUser();
281284

282285
$this->em->wrapInTransaction(function () use ($application, $selectedSubevents, $values, $loggedUser): void {
283286
if ($application instanceof SubeventsApplication) {
@@ -328,10 +331,10 @@ public function handleCancelApplication(int $id): void
328331
$application = $this->applicationRepository->findById($id);
329332

330333
$p = $this->getPresenter();
334+
assert($p instanceof AdminBasePresenter);
331335

332336
if ($application instanceof SubeventsApplication && ! $application->isCanceled()) {
333-
$loggedUser = $this->userRepository->findById($this->getPresenter()->user->id);
334-
$this->applicationService->cancelSubeventsApplication($application, ApplicationState::CANCELED, $loggedUser);
337+
$this->applicationService->cancelSubeventsApplication($application, ApplicationState::CANCELED, $p->getDbUser());
335338
$p->flashMessage('admin.users.users_applications_application_canceled', 'success');
336339
}
337340

app/AdminModule/Components/UsersGridControl.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace App\AdminModule\Components;
66

7+
use App\AdminModule\Presenters\AdminBasePresenter;
78
use App\Model\Acl\Repositories\RoleRepository;
89
use App\Model\Acl\Role;
910
use App\Model\CustomInput\CustomCheckbox;
@@ -50,6 +51,7 @@
5051
use Ublaboo\DataGrid\Exception\DataGridColumnStatusException;
5152
use Ublaboo\DataGrid\Exception\DataGridException;
5253

54+
use function assert;
5355
use function basename;
5456

5557
/**
@@ -526,6 +528,7 @@ public function groupChangeRoles(array $ids, array $value): void
526528
$selectedRoles = $this->roleRepository->findRolesByIds($value);
527529

528530
$p = $this->getPresenter();
531+
assert($p instanceof AdminBasePresenter);
529532

530533
// neni vybrana zadna role
531534
if ($selectedRoles->isEmpty()) {
@@ -563,7 +566,7 @@ public function groupChangeRoles(array $ids, array $value): void
563566
return;
564567
}
565568

566-
$loggedUser = $this->userRepository->findById($p->getUser()->id);
569+
$loggedUser = $p->getDbUser();
567570

568571
$this->em->wrapInTransaction(function () use ($selectedRoles, $users, $loggedUser): void {
569572
foreach ($users as $user) {
@@ -610,8 +613,9 @@ public function groupMarkPaidToday(array $ids, string $paymentMethod): void
610613
$users = $this->userRepository->findUsersByIds($ids);
611614

612615
$p = $this->getPresenter();
616+
assert($p instanceof AdminBasePresenter);
613617

614-
$loggedUser = $this->userRepository->findById($p->getUser()->id);
618+
$loggedUser = $p->getDbUser();
615619

616620
$this->em->wrapInTransaction(function () use ($users, $paymentMethod, $loggedUser): void {
617621
foreach ($users as $user) {

app/AdminModule/ConfigurationModule/Forms/CustomInputFormFactory.php

-3
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ public function create(int $id): Form
5454

5555
$form = $this->baseFormFactory->create();
5656

57-
$form->addHidden('id');
58-
5957
$form->addText('name', 'admin.configuration.custom_inputs_name')
6058
->addRule(Form::FILLED, 'admin.configuration.custom_inputs_name_empty');
6159

@@ -83,7 +81,6 @@ public function create(int $id): Form
8381
$optionsText->setDisabled();
8482

8583
$form->setDefaults([
86-
'id' => $id,
8784
'name' => $this->customInput->getName(),
8885
'roles' => Helpers::getIds($this->customInput->getRoles()),
8986
'type' => $this->customInput->getType(),

app/AdminModule/ConfigurationModule/Forms/SubeventFormFactory.php

-3
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ public function create(int $id): Form
4949

5050
$form = $this->baseFormFactory->create();
5151

52-
$form->addHidden('id');
53-
5452
$nameText = $form->addText('name', 'admin.configuration.subevents_name')
5553
->addRule(Form::FILLED, 'admin.configuration.subevents_name_empty');
5654

@@ -123,7 +121,6 @@ public function create(int $id): Form
123121

124122
if ($this->subevent) {
125123
$form->setDefaults([
126-
'id' => $id,
127124
'name' => $this->subevent->getName(),
128125
'registerableFrom' => $this->subevent->getRegisterableFrom(),
129126
'registerableTo' => $this->subevent->getRegisterableTo(),

app/AdminModule/Forms/EditUserPersonalDetailsFormFactory.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,13 @@ public function create(int $id): Form
5252

5353
$form = $this->baseFormFactory->create();
5454

55-
$form->addHidden('id');
56-
5755
$photoUpload = $form->addUpload('photo', 'admin.users.users_photo');
5856
$photoUpload->setHtmlAttribute('accept', 'image/*')
5957
->setHtmlAttribute('data-show-preview', 'true')
6058
->addCondition(Form::FILLED)
6159
->addRule(Form::IMAGE, 'admin.users.users_photo_format');
6260

63-
if ($this->user->getPhoto() !== null) {
61+
if ($this->user->hasPhoto()) {
6462
$photoUpload->setHtmlAttribute('data-delete-url', '?do=removePhoto')
6563
->setHtmlAttribute('data-initial-preview', json_encode([$this->user->getPhoto()], JSON_THROW_ON_ERROR))
6664
->setHtmlAttribute('data-initial-preview-show-delete', 'true')
@@ -107,7 +105,6 @@ public function create(int $id): Form
107105
->setHtmlAttribute('class', 'btn btn-warning');
108106

109107
$form->setDefaults([
110-
'id' => $id,
111108
'firstName' => $this->user->getFirstName(),
112109
'lastName' => $this->user->getLastName(),
113110
'nickName' => $this->user->getNickName(),

app/AdminModule/Forms/EditUserSeminarFormFactory.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace App\AdminModule\Forms;
66

7+
use App\AdminModule\Presenters\AdminBasePresenter;
78
use App\Model\Acl\Repositories\RoleRepository;
89
use App\Model\Acl\Role;
910
use App\Model\CustomInput\CustomCheckbox;
@@ -98,8 +99,6 @@ public function create(int $id): Form
9899

99100
$form = $this->baseFormFactory->create();
100101

101-
$form->addHidden('id');
102-
103102
if (! $this->user->isExternalLector()) {
104103
$rolesSelect = $form->addMultiSelect(
105104
'roles',
@@ -234,7 +233,6 @@ public function create(int $id): Form
234233
->setHtmlAttribute('class', 'btn btn-warning');
235234

236235
$form->setDefaults([
237-
'id' => $id,
238236
'roles' => $this->roleRepository->findRolesIds($this->user->getRoles()),
239237
'approved' => $this->user->isApproved(),
240238
'attended' => $this->user->isAttended(),
@@ -258,7 +256,10 @@ public function processForm(Form $form, stdClass $values): void
258256
return;
259257
}
260258

261-
$loggedUser = $this->userRepository->findById($form->getPresenter()->user->id);
259+
$presenter = $form->getPresenter();
260+
assert($presenter instanceof AdminBasePresenter);
261+
262+
$loggedUser = $presenter->getDbUser();
262263

263264
$this->em->wrapInTransaction(function () use ($values, $loggedUser): void {
264265
$customInputValueChanged = false;

app/AdminModule/MailingModule/Forms/EditTemplateFormFactory.php

-3
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ public function create(int $id): Form
3636

3737
$form = $this->baseFormFactory->create();
3838

39-
$form->addHidden('id');
40-
4139
$form->addCheckbox('active', 'admin.mailing.templates.active_form');
4240

4341
$form->addText('subject', 'admin.mailing.templates.subject')
@@ -54,7 +52,6 @@ public function create(int $id): Form
5452
->setHtmlAttribute('class', 'btn btn-warning');
5553

5654
$form->setDefaults([
57-
'id' => $id,
5855
'active' => $this->template->isActive(),
5956
'subject' => $this->template->getSubject(),
6057
'text' => $this->template->getText(),

app/AdminModule/MailingModule/Forms/SendFormFactory.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ public function processForm(Form $form, stdClass $values): void
107107
$recipientsUsers = $this->userRepository->findUsersByIds($values->recipientUsers);
108108
$recipientsRoles = $this->roleRepository->findRolesByIds($values->recipientRoles);
109109
$recipientsSubevents = $this->subeventRepository->findSubeventsByIds($values->recipientSubevents);
110-
$recipientsEmails = new ArrayCollection();
110+
$recipientsEmails = null;
111111

112112
if (! empty($values->copy)) {
113-
$recipientsEmails->add($values->copy);
113+
$recipientsEmails = new ArrayCollection([$values->copy]);
114114
}
115115

116116
$this->commandBus->handle(new CreateMail($recipientsUsers, $recipientsRoles, $recipientsSubevents, $recipientsEmails, $values->subject, $values->text));

app/AdminModule/PaymentsModule/Components/PaymentsGridControl.php

+11-9
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
namespace App\AdminModule\PaymentsModule\Components;
66

7+
use App\AdminModule\Presenters\AdminBasePresenter;
78
use App\Model\Enums\PaymentState;
89
use App\Model\Payment\Payment;
910
use App\Model\Payment\Repositories\PaymentRepository;
1011
use App\Model\Settings\Exceptions\SettingsItemNotFoundException;
1112
use App\Model\Settings\Queries\SettingDateValueQuery;
1213
use App\Model\Settings\Queries\SettingStringValueQuery;
1314
use App\Model\Settings\Settings;
14-
use App\Model\User\Repositories\UserRepository;
1515
use App\Services\ApplicationService;
1616
use App\Services\BankService;
1717
use App\Services\QueryBus;
@@ -29,6 +29,8 @@
2929
use Ublaboo\DataGrid\DataGrid;
3030
use Ublaboo\DataGrid\Exception\DataGridException;
3131

32+
use function assert;
33+
3234
/**
3335
* Komponenta pro správu plateb.
3436
*/
@@ -38,7 +40,6 @@ public function __construct(
3840
private readonly QueryBus $queryBus,
3941
private readonly Translator $translator,
4042
private readonly PaymentRepository $paymentRepository,
41-
private readonly UserRepository $userRepository,
4243
private readonly ApplicationService $applicationService,
4344
private readonly BankService $bankService,
4445
private readonly Session $session,
@@ -140,12 +141,13 @@ public function createComponentPaymentsGrid(string $name): void
140141
*/
141142
public function add(stdClass $values): void
142143
{
143-
$loggedUser = $this->userRepository->findById($this->getPresenter()->user->id);
144+
$p = $this->getPresenter();
145+
assert($p instanceof AdminBasePresenter);
144146

145-
$this->applicationService->createPaymentManual($values->date, $values->amount, $values->variableSymbol, $loggedUser);
147+
$this->applicationService->createPaymentManual($values->date, $values->amount, $values->variableSymbol, $p->getDbUser());
146148

147-
$this->getPresenter()->flashMessage('admin.payments.payments.saved', 'success');
148-
$this->getPresenter()->redrawControl('flashes');
149+
$p->flashMessage('admin.payments.payments.saved', 'success');
150+
$p->redrawControl('flashes');
149151
}
150152

151153
/**
@@ -157,11 +159,11 @@ public function handleDelete(int $id): void
157159
{
158160
$payment = $this->paymentRepository->findById($id);
159161

160-
$loggedUser = $this->userRepository->findById($this->getPresenter()->user->id);
162+
$p = $this->getPresenter();
163+
assert($p instanceof AdminBasePresenter);
161164

162-
$this->applicationService->removePayment($payment, $loggedUser);
165+
$this->applicationService->removePayment($payment, $p->getDbUser());
163166

164-
$p = $this->getPresenter();
165167
$p->flashMessage('admin.payments.payments.deleted', 'success');
166168
$p->redirect('this');
167169
}

0 commit comments

Comments
 (0)