Skip to content

Commit

Permalink
admin groups created (#1116)
Browse files Browse the repository at this point in the history
Co-authored-by: Jan Havelka <[email protected]>
  • Loading branch information
GitHubJanHave and Jan Havelka authored Nov 22, 2023
1 parent d3e96af commit f122fcf
Show file tree
Hide file tree
Showing 412 changed files with 3,949 additions and 1,536 deletions.
14 changes: 14 additions & 0 deletions app/ActionModule/Presenters/ActionBasePresenter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace App\ActionModule\Presenters;

use App\Presenters\BasePresenter;

/**
* BasePresenter pro ActionModule.
*/
abstract class ActionBasePresenter extends BasePresenter
{
}
41 changes: 41 additions & 0 deletions app/ActionModule/Presenters/BankPresenter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace App\ActionModule\Presenters;

use App\Model\Settings\Exceptions\SettingsItemNotFoundException;
use App\Model\Settings\Queries\SettingDateValueQuery;
use App\Model\Settings\Settings;
use App\Services\BankService;
use App\Services\QueryBus;
use Nette\Application\Responses\TextResponse;
use Nette\DI\Attributes\Inject;
use Throwable;

/**
* Presenter obsluhující načítání plateb z API banky.
*/
class BankPresenter extends ActionBasePresenter
{
#[Inject]
public QueryBus $queryBus;

#[Inject]
public BankService $bankService;

/**
* Zkontroluje splatnost přihlášek.
*
* @throws SettingsItemNotFoundException
* @throws Throwable
*/
public function actionCheck(): void
{
$from = $this->queryBus->handle(new SettingDateValueQuery(Settings::BANK_DOWNLOAD_FROM));
$this->bankService->downloadTransactions($from);

$response = new TextResponse(null);
$this->sendResponse($response);
}
}
55 changes: 55 additions & 0 deletions app/ActionModule/Presenters/MailingPresenter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

declare(strict_types=1);

namespace App\ActionModule\Presenters;

use App\Model\Acl\Permission;
use App\Model\Acl\SrsResource;
use App\Model\Settings\Commands\SetSettingStringValue;
use App\Model\Settings\Queries\SettingStringValueQuery;
use App\Model\Settings\Settings;
use App\Services\CommandBus;
use App\Services\QueryBus;
use Nette\Application\AbortException;
use Nette\DI\Attributes\Inject;
use Throwable;

/**
* Presenter obsluhující potvrzení změny e-mailu.
*/
class MailingPresenter extends ActionBasePresenter
{
#[Inject]
public CommandBus $commandBus;

#[Inject]
public QueryBus $queryBus;

/**
* Ověří e-mail semináře.
*
* @throws AbortException
* @throws Throwable
*/
public function actionVerify(string $code): void
{
if ($code === $this->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');
}
}
}
134 changes: 134 additions & 0 deletions app/ActionModule/Presenters/MaturityPresenter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?php

declare(strict_types=1);

namespace App\ActionModule\Presenters;

use App\Model\Acl\Repositories\RoleRepository;
use App\Model\Acl\Role;
use App\Model\Enums\ApplicationState;
use App\Model\Mailing\Template;
use App\Model\Mailing\TemplateVariable;
use App\Model\Settings\Queries\SettingIntValueQuery;
use App\Model\Settings\Queries\SettingStringValueQuery;
use App\Model\Settings\Settings;
use App\Model\User\Repositories\UserRepository;
use App\Services\ApplicationService;
use App\Services\IMailService;
use App\Services\QueryBus;
use App\Utils\Helpers;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\EntityManagerInterface;
use Nette\Application\Responses\TextResponse;
use Nette\DI\Attributes\Inject;
use Throwable;

/**
* Presenter obsluhující kontrolu splatnosti přihlášek.
*/
class MaturityPresenter extends ActionBasePresenter
{
#[Inject]
public QueryBus $queryBus;

#[Inject]
public EntityManagerInterface $em;

#[Inject]
public UserRepository $userRepository;

#[Inject]
public RoleRepository $roleRepository;

#[Inject]
public IMailService $mailService;

#[Inject]
public ApplicationService $applicationService;

/**
* Zruší přihlášky po splatnosti.
*
* @throws Throwable
*/
public function actionCancelApplications(): void
{
$cancelRegistration = $this->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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}

Expand Down
8 changes: 4 additions & 4 deletions app/AdminModule/CmsModule/Components/DocumentsGridControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}

Expand Down
7 changes: 4 additions & 3 deletions app/AdminModule/CmsModule/Components/FaqGridControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
{
}

Expand Down Expand Up @@ -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
Expand All @@ -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
{
Expand Down
4 changes: 3 additions & 1 deletion app/AdminModule/CmsModule/Components/NewsGridControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
{
}

Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit f122fcf

Please sign in to comment.