Skip to content

Commit

Permalink
Komponenta vstupenky (#1088)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jan-stanek authored Nov 6, 2023
1 parent cb26335 commit 74c252a
Show file tree
Hide file tree
Showing 88 changed files with 795 additions and 465 deletions.
8 changes: 3 additions & 5 deletions app/AdminModule/CmsModule/Forms/FaqFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use App\AdminModule\Forms\BaseFormFactory;
use App\Model\Cms\Faq;
use App\Model\Cms\Repositories\FaqRepository;
use App\Model\User\Repositories\UserRepository;
use App\Model\User\User;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\NoResultException;
Expand All @@ -30,22 +29,21 @@ class FaqFormFactory
/**
* Přihlášený uživatel.
*/
private User|null $user = null;
private User $user;

public function __construct(
private readonly BaseFormFactory $baseFormFactory,
private readonly FaqRepository $faqRepository,
private readonly UserRepository $userRepository,
) {
}

/**
* Vytvoří formulář.
*/
public function create(int|null $id, int $userId): Form
public function create(int|null $id, User $user): Form
{
$this->faq = $id === null ? null : $this->faqRepository->findById($id);
$this->user = $this->userRepository->findById($userId);
$this->user = $user;

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

Expand Down
2 changes: 1 addition & 1 deletion app/AdminModule/CmsModule/Presenters/FaqPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function createComponentFaqGrid(): FaqGridControl

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

$form->onSuccess[] = function (Form $form, stdClass $values): void {
if ($form->isSubmitted() == $form['cancel']) {
Expand Down
15 changes: 9 additions & 6 deletions app/AdminModule/Components/ApplicationsGridControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\AdminModule\Components;

use App\AdminModule\Presenters\AdminBasePresenter;
use App\Model\Application\Application;
use App\Model\Application\Repositories\ApplicationRepository;
use App\Model\Application\RolesApplication;
Expand Down Expand Up @@ -32,6 +33,8 @@
use Ublaboo\DataGrid\DataGrid;
use Ublaboo\DataGrid\Exception\DataGridException;

use function assert;

/**
* Komponenta pro správu přihlášek.
*/
Expand Down Expand Up @@ -211,6 +214,7 @@ public function add(stdClass $values): void
$selectedSubevents = $this->subeventRepository->findSubeventsByIds($values->subevents);

$p = $this->getPresenter();
assert($p instanceof AdminBasePresenter);

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

$loggedUser = $this->userRepository->findById($this->getPresenter()->user->id);

$this->applicationService->addSubeventsApplication($this->user, $selectedSubevents, $loggedUser);
$this->applicationService->addSubeventsApplication($this->user, $selectedSubevents, $p->getDbUser());

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

$p = $this->getPresenter();
assert($p instanceof AdminBasePresenter);

if ($application instanceof RolesApplication) {
if (! $selectedSubevents->isEmpty()) {
Expand Down Expand Up @@ -277,7 +280,7 @@ public function edit(string $id, stdClass $values): void
return;
}

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

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

$p = $this->getPresenter();
assert($p instanceof AdminBasePresenter);

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

Expand Down
8 changes: 6 additions & 2 deletions app/AdminModule/Components/UsersGridControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\AdminModule\Components;

use App\AdminModule\Presenters\AdminBasePresenter;
use App\Model\Acl\Repositories\RoleRepository;
use App\Model\Acl\Role;
use App\Model\CustomInput\CustomCheckbox;
Expand Down Expand Up @@ -50,6 +51,7 @@
use Ublaboo\DataGrid\Exception\DataGridColumnStatusException;
use Ublaboo\DataGrid\Exception\DataGridException;

use function assert;
use function basename;

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

$p = $this->getPresenter();
assert($p instanceof AdminBasePresenter);

// neni vybrana zadna role
if ($selectedRoles->isEmpty()) {
Expand Down Expand Up @@ -563,7 +566,7 @@ public function groupChangeRoles(array $ids, array $value): void
return;
}

$loggedUser = $this->userRepository->findById($p->getUser()->id);
$loggedUser = $p->getDbUser();

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

$p = $this->getPresenter();
assert($p instanceof AdminBasePresenter);

$loggedUser = $this->userRepository->findById($p->getUser()->id);
$loggedUser = $p->getDbUser();

$this->em->wrapInTransaction(function () use ($users, $paymentMethod, $loggedUser): void {
foreach ($users as $user) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ public function create(int $id): Form

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

$form->addHidden('id');

$form->addText('name', 'admin.configuration.custom_inputs_name')
->addRule(Form::FILLED, 'admin.configuration.custom_inputs_name_empty');

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

$form->setDefaults([
'id' => $id,
'name' => $this->customInput->getName(),
'roles' => Helpers::getIds($this->customInput->getRoles()),
'type' => $this->customInput->getType(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ public function create(int $id): Form

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

$form->addHidden('id');

$nameText = $form->addText('name', 'admin.configuration.subevents_name')
->addRule(Form::FILLED, 'admin.configuration.subevents_name_empty');

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

if ($this->subevent) {
$form->setDefaults([
'id' => $id,
'name' => $this->subevent->getName(),
'registerableFrom' => $this->subevent->getRegisterableFrom(),
'registerableTo' => $this->subevent->getRegisterableTo(),
Expand Down
5 changes: 1 addition & 4 deletions app/AdminModule/Forms/EditUserPersonalDetailsFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,13 @@ public function create(int $id): Form

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

$form->addHidden('id');

$photoUpload = $form->addUpload('photo', 'admin.users.users_photo');
$photoUpload->setHtmlAttribute('accept', 'image/*')
->setHtmlAttribute('data-show-preview', 'true')
->addCondition(Form::FILLED)
->addRule(Form::IMAGE, 'admin.users.users_photo_format');

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

$form->setDefaults([
'id' => $id,
'firstName' => $this->user->getFirstName(),
'lastName' => $this->user->getLastName(),
'nickName' => $this->user->getNickName(),
Expand Down
9 changes: 5 additions & 4 deletions app/AdminModule/Forms/EditUserSeminarFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\AdminModule\Forms;

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

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

$form->addHidden('id');

if (! $this->user->isExternalLector()) {
$rolesSelect = $form->addMultiSelect(
'roles',
Expand Down Expand Up @@ -234,7 +233,6 @@ public function create(int $id): Form
->setHtmlAttribute('class', 'btn btn-warning');

$form->setDefaults([
'id' => $id,
'roles' => $this->roleRepository->findRolesIds($this->user->getRoles()),
'approved' => $this->user->isApproved(),
'attended' => $this->user->isAttended(),
Expand All @@ -258,7 +256,10 @@ public function processForm(Form $form, stdClass $values): void
return;
}

$loggedUser = $this->userRepository->findById($form->getPresenter()->user->id);
$presenter = $form->getPresenter();
assert($presenter instanceof AdminBasePresenter);

$loggedUser = $presenter->getDbUser();

$this->em->wrapInTransaction(function () use ($values, $loggedUser): void {
$customInputValueChanged = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public function create(int $id): Form

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

$form->addHidden('id');

$form->addCheckbox('active', 'admin.mailing.templates.active_form');

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

$form->setDefaults([
'id' => $id,
'active' => $this->template->isActive(),
'subject' => $this->template->getSubject(),
'text' => $this->template->getText(),
Expand Down
4 changes: 2 additions & 2 deletions app/AdminModule/MailingModule/Forms/SendFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ public function processForm(Form $form, stdClass $values): void
$recipientsUsers = $this->userRepository->findUsersByIds($values->recipientUsers);
$recipientsRoles = $this->roleRepository->findRolesByIds($values->recipientRoles);
$recipientsSubevents = $this->subeventRepository->findSubeventsByIds($values->recipientSubevents);
$recipientsEmails = new ArrayCollection();
$recipientsEmails = null;

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

$this->commandBus->handle(new CreateMail($recipientsUsers, $recipientsRoles, $recipientsSubevents, $recipientsEmails, $values->subject, $values->text));
Expand Down
20 changes: 11 additions & 9 deletions app/AdminModule/PaymentsModule/Components/PaymentsGridControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

namespace App\AdminModule\PaymentsModule\Components;

use App\AdminModule\Presenters\AdminBasePresenter;
use App\Model\Enums\PaymentState;
use App\Model\Payment\Payment;
use App\Model\Payment\Repositories\PaymentRepository;
use App\Model\Settings\Exceptions\SettingsItemNotFoundException;
use App\Model\Settings\Queries\SettingDateValueQuery;
use App\Model\Settings\Queries\SettingStringValueQuery;
use App\Model\Settings\Settings;
use App\Model\User\Repositories\UserRepository;
use App\Services\ApplicationService;
use App\Services\BankService;
use App\Services\QueryBus;
Expand All @@ -29,6 +29,8 @@
use Ublaboo\DataGrid\DataGrid;
use Ublaboo\DataGrid\Exception\DataGridException;

use function assert;

/**
* Komponenta pro správu plateb.
*/
Expand All @@ -38,7 +40,6 @@ public function __construct(
private readonly QueryBus $queryBus,
private readonly Translator $translator,
private readonly PaymentRepository $paymentRepository,
private readonly UserRepository $userRepository,
private readonly ApplicationService $applicationService,
private readonly BankService $bankService,
private readonly Session $session,
Expand Down Expand Up @@ -140,12 +141,13 @@ public function createComponentPaymentsGrid(string $name): void
*/
public function add(stdClass $values): void
{
$loggedUser = $this->userRepository->findById($this->getPresenter()->user->id);
$p = $this->getPresenter();
assert($p instanceof AdminBasePresenter);

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

$this->getPresenter()->flashMessage('admin.payments.payments.saved', 'success');
$this->getPresenter()->redrawControl('flashes');
$p->flashMessage('admin.payments.payments.saved', 'success');
$p->redrawControl('flashes');
}

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

$loggedUser = $this->userRepository->findById($this->getPresenter()->user->id);
$p = $this->getPresenter();
assert($p instanceof AdminBasePresenter);

$this->applicationService->removePayment($payment, $loggedUser);
$this->applicationService->removePayment($payment, $p->getDbUser());

$p = $this->getPresenter();
$p->flashMessage('admin.payments.payments.deleted', 'success');
$p->redirect('this');
}
Expand Down
Loading

0 comments on commit 74c252a

Please sign in to comment.