diff --git a/app/ActionModule/Presenters/ActionBasePresenter.php b/app/ActionModule/Presenters/ActionBasePresenter.php new file mode 100644 index 000000000..b52d48501 --- /dev/null +++ b/app/ActionModule/Presenters/ActionBasePresenter.php @@ -0,0 +1,14 @@ +queryBus->handle(new SettingDateValueQuery(Settings::BANK_DOWNLOAD_FROM)); + $this->bankService->downloadTransactions($from); + + $response = new TextResponse(null); + $this->sendResponse($response); + } +} diff --git a/app/ActionModule/Presenters/MailingPresenter.php b/app/ActionModule/Presenters/MailingPresenter.php new file mode 100644 index 000000000..b91673a2c --- /dev/null +++ b/app/ActionModule/Presenters/MailingPresenter.php @@ -0,0 +1,55 @@ +queryBus->handle(new SettingStringValueQuery(Settings::SEMINAR_EMAIL_VERIFICATION_CODE))) { + $newEmail = $this->queryBus->handle(new SettingStringValueQuery(Settings::SEMINAR_EMAIL_UNVERIFIED)); + $this->commandBus->handle(new SetSettingStringValue(Settings::SEMINAR_EMAIL, $newEmail)); + + $this->commandBus->handle(new SetSettingStringValue(Settings::SEMINAR_EMAIL_UNVERIFIED, null)); + $this->commandBus->handle(new SetSettingStringValue(Settings::SEMINAR_EMAIL_VERIFICATION_CODE, null)); + + $this->flashMessage('admin.configuration.mailing_email_verification_successful', 'success'); + } else { + $this->flashMessage('admin.configuration.mailing_email_verification_error', 'danger'); + } + + if ($this->user->isAllowed(SrsResource::CONFIGURATION, Permission::MANAGE)) { + $this->redirect(':Admin:Configuration:Mailing:default'); + } else { + $this->redirect(':Web:Page:default'); + } + } +} diff --git a/app/ActionModule/Presenters/MaturityPresenter.php b/app/ActionModule/Presenters/MaturityPresenter.php new file mode 100644 index 000000000..bd432220b --- /dev/null +++ b/app/ActionModule/Presenters/MaturityPresenter.php @@ -0,0 +1,134 @@ +queryBus->handle(new SettingIntValueQuery(Settings::CANCEL_REGISTRATION_AFTER_MATURITY)); + if ($cancelRegistration !== null) { + $cancelRegistrationDate = (new DateTimeImmutable())->setTime(0, 0)->modify('-' . $cancelRegistration . ' days'); + } else { + return; + } + + foreach ($this->userRepository->findAllWithWaitingForPaymentApplication() as $user) { + $this->em->wrapInTransaction(function () use ($user, $cancelRegistrationDate): void { + // odhlášení účastníků s nezaplacnou přihláškou rolí + foreach ($user->getWaitingForPaymentRolesApplications() as $application) { + $maturityDate = $application->getMaturityDate(); + + if ($maturityDate !== null && $cancelRegistrationDate > $maturityDate) { + $this->applicationService->cancelRegistration($user, ApplicationState::CANCELED_NOT_PAID, null); + + return; + } + } + + // zrušení nezaplacených přihlášek podakcí + $subeventsApplicationCanceled = false; + foreach ($user->getWaitingForPaymentSubeventsApplications() as $application) { + $maturityDate = $application->getMaturityDate(); + + if ($maturityDate !== null && $cancelRegistrationDate > $maturityDate) { + $this->applicationService->cancelSubeventsApplication($application, ApplicationState::CANCELED_NOT_PAID, null); + $subeventsApplicationCanceled = true; + } + } + + // pokud účastníkovi nezbyde žádná podakce, je třeba odebrat i roli s cenou podle podakcí, případně jej odhlásit + if ($subeventsApplicationCanceled && $user->getSubevents()->isEmpty()) { + $newRoles = $user->getRoles()->filter(static fn (Role $role) => $role->getFee() !== null); + if ($newRoles->isEmpty()) { + $this->applicationService->cancelRegistration($user, ApplicationState::CANCELED_NOT_PAID, null); + } else { + $this->applicationService->updateRoles($user, $newRoles, null); + } + } + }); + } + + $response = new TextResponse(null); + $this->sendResponse($response); + } + + /** + * Rozešle přípomínky splatnosti. + * + * @throws Throwable + */ + public function actionSendReminders(): void + { + $maturityReminder = $this->queryBus->handle(new SettingIntValueQuery(Settings::MATURITY_REMINDER)); + if ($maturityReminder !== null) { + $maturityReminderDate = (new DateTimeImmutable())->setTime(0, 0)->modify('+' . $maturityReminder . ' days'); + } else { + return; + } + + foreach ($this->userRepository->findAllWithWaitingForPaymentApplication() as $user) { + foreach ($user->getWaitingForPaymentApplications() as $application) { + $maturityDate = $application->getMaturityDate(); + + if ($maturityReminderDate == $maturityDate) { + $this->mailService->sendMailFromTemplate(new ArrayCollection([$application->getUser()]), null, Template::MATURITY_REMINDER, [ + TemplateVariable::SEMINAR_NAME => $this->queryBus->handle(new SettingStringValueQuery(Settings::SEMINAR_NAME)), + TemplateVariable::APPLICATION_MATURITY => $maturityDate->format(Helpers::DATE_FORMAT), + ]); + } + } + } + + $response = new TextResponse(null); + $this->sendResponse($response); + } +} diff --git a/app/AdminModule/CmsModule/Components/DocumentTagsGridControl.php b/app/AdminModule/CmsModule/Components/DocumentTagsGridControl.php index 65379ff11..4aa9b1d8d 100644 --- a/app/AdminModule/CmsModule/Components/DocumentTagsGridControl.php +++ b/app/AdminModule/CmsModule/Components/DocumentTagsGridControl.php @@ -28,10 +28,10 @@ class DocumentTagsGridControl extends Control { public function __construct( - private readonly Translator $translator, - private readonly RoleRepository $roleRepository, - private readonly AclService $aclService, - private readonly TagRepository $tagRepository, + private Translator $translator, + private RoleRepository $roleRepository, + private AclService $aclService, + private TagRepository $tagRepository, ) { } diff --git a/app/AdminModule/CmsModule/Components/DocumentsGridControl.php b/app/AdminModule/CmsModule/Components/DocumentsGridControl.php index 893ff80af..48dda95b4 100644 --- a/app/AdminModule/CmsModule/Components/DocumentsGridControl.php +++ b/app/AdminModule/CmsModule/Components/DocumentsGridControl.php @@ -32,10 +32,10 @@ class DocumentsGridControl extends Control { public function __construct( - private readonly Translator $translator, - private readonly DocumentRepository $documentRepository, - private readonly TagRepository $tagRepository, - private readonly FilesService $filesService, + private Translator $translator, + private DocumentRepository $documentRepository, + private TagRepository $tagRepository, + private FilesService $filesService, ) { } diff --git a/app/AdminModule/CmsModule/Components/FaqGridControl.php b/app/AdminModule/CmsModule/Components/FaqGridControl.php index 9d66c4e1f..1a210a3ca 100644 --- a/app/AdminModule/CmsModule/Components/FaqGridControl.php +++ b/app/AdminModule/CmsModule/Components/FaqGridControl.php @@ -6,7 +6,7 @@ use App\Model\Cms\Repositories\FaqRepository; use Doctrine\ORM\NonUniqueResultException; -use Doctrine\ORM\NoResultException; +use Doctrine\ORM\ORMException; use Nette\Application\AbortException; use Nette\Application\UI\Control; use Nette\Localization\Translator; @@ -19,7 +19,7 @@ */ class FaqGridControl extends Control { - public function __construct(private readonly Translator $translator, private readonly FaqRepository $faqRepository) + public function __construct(private Translator $translator, private FaqRepository $faqRepository) { } @@ -102,6 +102,7 @@ public function handleDelete(int $id): void /** * Přesuene otázku $item_id mezi $prev_id a $next_id. * + * @throws ORMException * @throws AbortException */ public function handleSort(string|null $item_id, string|null $prev_id, string|null $next_id): void @@ -123,8 +124,8 @@ public function handleSort(string|null $item_id, string|null $prev_id, string|nu * Změní viditelnost otázky. * * @throws NonUniqueResultException + * @throws ORMException * @throws AbortException - * @throws NoResultException */ public function changeStatus(string $id, string $public): void { diff --git a/app/AdminModule/CmsModule/Components/NewsGridControl.php b/app/AdminModule/CmsModule/Components/NewsGridControl.php index b5b10c9c1..692f4d94f 100644 --- a/app/AdminModule/CmsModule/Components/NewsGridControl.php +++ b/app/AdminModule/CmsModule/Components/NewsGridControl.php @@ -6,6 +6,7 @@ use App\Model\Cms\Repositories\NewsRepository; use App\Utils\Helpers; +use Doctrine\ORM\ORMException; use Nette\Application\AbortException; use Nette\Application\UI\Control; use Nette\Localization\Translator; @@ -18,7 +19,7 @@ */ class NewsGridControl extends Control { - public function __construct(private readonly Translator $translator, private readonly NewsRepository $newsRepository) + public function __construct(private Translator $translator, private NewsRepository $newsRepository) { } @@ -97,6 +98,7 @@ public function handleDelete(int $id): void /** * Změní připíchnutí aktuality. * + * @throws ORMException * @throws AbortException */ public function changePinned(string $id, string $pinned): void diff --git a/app/AdminModule/CmsModule/Components/PagesGridControl.php b/app/AdminModule/CmsModule/Components/PagesGridControl.php index 94db1840a..1157c003a 100644 --- a/app/AdminModule/CmsModule/Components/PagesGridControl.php +++ b/app/AdminModule/CmsModule/Components/PagesGridControl.php @@ -11,8 +11,8 @@ use App\Services\AclService; use App\Services\CmsService; use Doctrine\ORM\NonUniqueResultException; -use Doctrine\ORM\NoResultException; use Doctrine\ORM\OptimisticLockException; +use Doctrine\ORM\ORMException; use Nette\Application\AbortException; use Nette\Application\UI\Control; use Nette\Application\UI\Form; @@ -34,11 +34,11 @@ class PagesGridControl extends Control { public function __construct( - private readonly Translator $translator, - private readonly CmsService $cmsService, - private readonly PageRepository $pageRepository, - private readonly RoleRepository $roleRepository, - private readonly AclService $aclService, + private Translator $translator, + private CmsService $cmsService, + private PageRepository $pageRepository, + private RoleRepository $roleRepository, + private AclService $aclService, ) { } @@ -159,7 +159,8 @@ public function createComponentPagesGrid(string $name): DataGrid * Zpracuje přidání stránky. * * @throws NonUniqueResultException - * @throws NoResultException + * @throws ORMException + * @throws OptimisticLockException */ public function add(stdClass $values): void { @@ -179,7 +180,8 @@ public function add(stdClass $values): void * Zpracuje upravení stránky. * * @throws NonUniqueResultException - * @throws NoResultException + * @throws ORMException + * @throws OptimisticLockException */ public function edit(string $id, stdClass $values): void { @@ -217,6 +219,7 @@ public function handleDelete(int $id): void * Přesune stránku s $item_id mezi $prev_id a $next_id. * * @throws AbortException + * @throws ORMException * @throws OptimisticLockException */ public function handleSort(string|null $item_id, string|null $prev_id, string|null $next_id): void @@ -239,8 +242,8 @@ public function handleSort(string|null $item_id, string|null $prev_id, string|nu * * @throws AbortException * @throws NonUniqueResultException + * @throws ORMException * @throws OptimisticLockException - * @throws NoResultException */ public function changeStatus(string $id, string $public): void { diff --git a/app/AdminModule/CmsModule/Forms/FaqFormFactory.php b/app/AdminModule/CmsModule/Forms/FaqFormFactory.php index 7cd27a033..f6b41f65b 100644 --- a/app/AdminModule/CmsModule/Forms/FaqFormFactory.php +++ b/app/AdminModule/CmsModule/Forms/FaqFormFactory.php @@ -7,9 +7,10 @@ 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; +use Doctrine\ORM\ORMException; use Nette; use Nette\Application\UI\Form; use stdClass; @@ -29,21 +30,22 @@ class FaqFormFactory /** * Přihlášený uživatel. */ - private User $user; + private User|null $user = null; public function __construct( - private readonly BaseFormFactory $baseFormFactory, - private readonly FaqRepository $faqRepository, + private BaseFormFactory $baseFormFactory, + private FaqRepository $faqRepository, + private UserRepository $userRepository, ) { } /** * Vytvoří formulář. */ - public function create(int|null $id, User $user): Form + public function create(int|null $id, int $userId): Form { $this->faq = $id === null ? null : $this->faqRepository->findById($id); - $this->user = $user; + $this->user = $this->userRepository->findById($userId); $form = $this->baseFormFactory->create(); @@ -86,11 +88,11 @@ public function create(int|null $id, User $user): Form * Zpracuje formulář. * * @throws NonUniqueResultException - * @throws NoResultException + * @throws ORMException */ public function processForm(Form $form, stdClass $values): void { - if ($form->isSubmitted() == $form['cancel']) { + if ($form->isSubmitted() === $form['cancel']) { return; } diff --git a/app/AdminModule/CmsModule/Forms/NewsFormFactory.php b/app/AdminModule/CmsModule/Forms/NewsFormFactory.php index 5a3b5d458..0005b2241 100644 --- a/app/AdminModule/CmsModule/Forms/NewsFormFactory.php +++ b/app/AdminModule/CmsModule/Forms/NewsFormFactory.php @@ -25,7 +25,7 @@ class NewsFormFactory */ private News|null $news = null; - public function __construct(private readonly BaseFormFactory $baseFormFactory, private readonly NewsRepository $newsRepository) + public function __construct(private BaseFormFactory $baseFormFactory, private NewsRepository $newsRepository) { } @@ -82,7 +82,7 @@ public function create(int|null $id): Form */ public function processForm(Form $form, stdClass $values): void { - if ($form->isSubmitted() == $form['cancel']) { + if ($form->isSubmitted() === $form['cancel']) { return; } diff --git a/app/AdminModule/CmsModule/Forms/PageForm.php b/app/AdminModule/CmsModule/Forms/PageForm.php index 4ca4110d4..5b6aa9542 100644 --- a/app/AdminModule/CmsModule/Forms/PageForm.php +++ b/app/AdminModule/CmsModule/Forms/PageForm.php @@ -20,6 +20,7 @@ use App\Services\CmsService; use App\Services\FilesService; use Doctrine\ORM\OptimisticLockException; +use Doctrine\ORM\ORMException; use Nette\Application\UI; use Nette\Application\UI\Form; use stdClass; @@ -58,13 +59,13 @@ class PageForm extends UI\Control public function __construct( public int $id, public string $area, - private readonly BaseFormFactory $baseFormFactory, - private readonly PageRepository $pageRepository, - private readonly AclService $aclService, - private readonly CmsService $cmsService, - private readonly RoleRepository $roleRepository, - private readonly TagRepository $tagRepository, - private readonly FilesService $filesService, + private BaseFormFactory $baseFormFactory, + private PageRepository $pageRepository, + private AclService $aclService, + private CmsService $cmsService, + private RoleRepository $roleRepository, + private TagRepository $tagRepository, + private FilesService $filesService, ) { $this->page = $this->pageRepository->findById($id); } @@ -152,6 +153,7 @@ public function createComponentForm(): Form * Zpracuje formulář. * * @throws PageException + * @throws ORMException * @throws OptimisticLockException */ public function processForm(Form $form, stdClass $values): void @@ -172,20 +174,20 @@ public function processForm(Form $form, stdClass $values): void } } - if ($form->isSubmitted() == $form['submitAdd']) { + if ($form->isSubmitted() === $form['submitAdd']) { $contentClass = '\\App\\Model\\Cms\\' . str_replace('_', '', ucwords($type, '_')) . 'Content'; $content = new $contentClass($page, $area); $content->setHeading($form->getTranslator()->translate('common.content.default_heading.' . $type)); $this->cmsService->saveContent($content); } - if ($form->isSubmitted() == $form['submitAdd']) { + if ($form->isSubmitted() === $form['submitAdd']) { $submitName = 'submitAdd'; - } elseif ($form->isSubmitted() == $form['submitMain']) { + } elseif ($form->isSubmitted() === $form['submitMain']) { $submitName = 'submitMain'; - } elseif ($form->isSubmitted() == $form['submitSidebar']) { + } elseif ($form->isSubmitted() === $form['submitSidebar']) { $submitName = 'submitSidebar'; - } elseif ($form->isSubmitted() == $form['submitAndContinue']) { + } elseif ($form->isSubmitted() === $form['submitAndContinue']) { $submitName = 'submitAndContinue'; } else { $submitName = 'submit'; diff --git a/app/AdminModule/CmsModule/Forms/templates/page_form.latte b/app/AdminModule/CmsModule/Forms/templates/page_form.latte index f87617c9e..8f68991cb 100644 --- a/app/AdminModule/CmsModule/Forms/templates/page_form.latte +++ b/app/AdminModule/CmsModule/Forms/templates/page_form.latte @@ -32,7 +32,7 @@