Skip to content

Commit

Permalink
upravy registrace
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-stanek committed Dec 27, 2017
1 parent cd7b168 commit a13a0b5
Show file tree
Hide file tree
Showing 25 changed files with 711 additions and 760 deletions.
105 changes: 71 additions & 34 deletions app/ActionModule/presenters/MaturityPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@
use App\Model\Program\ProgramRepository;
use App\Model\Settings\Settings;
use App\Model\Settings\SettingsRepository;
use App\Model\User\Application;
use App\Model\User\ApplicationRepository;
use App\Model\User\RolesApplication;
use App\Model\User\RolesApplicationRepository;
use App\Model\User\SubeventsApplicationRepository;
use App\Model\User\UserRepository;
use App\Services\ApplicationService;
use App\Services\MailService;
use App\Services\ProgramService;
use Doctrine\Common\Collections\ArrayCollection;
Expand Down Expand Up @@ -66,9 +71,31 @@ class MaturityPresenter extends ActionBasePresenter
*/
public $programService;

/**
* @var ApplicationService
* @inject
*/
public $applicationService;

/**
* @var RolesApplicationRepository
* @inject
*/
public $rolesApplicationRepository;

/**
* @var SubeventsApplicationRepository
* @inject
*/
public $subeventsApplicationRepository;


/**
* Zkontroluje splatnost přihlášek.
* @throws \App\Model\Settings\SettingsException
* @throws \Throwable
* @throws \Ublaboo\Mailing\Exception\MailingException
* @throws \Ublaboo\Mailing\Exception\MailingMailCreationException
*/
public function actionCheck()
{
Expand All @@ -80,44 +107,54 @@ public function actionCheck()
if ($maturityReminder !== NULL)
$maturityReminderDate = (new \DateTime())->setTime(0, 0)->modify('+' . $maturityReminder . ' days');

foreach ($this->applicationRepository->findWaitingForPaymentApplications() as $application) {
$maturityDate = $application->getMaturityDate();
if ($maturityDate === NULL)
continue;

//zrušení registrace
if ($cancelRegistration !== NULL && $cancelRegistrationDate > $maturityDate) {
$this->userRepository->getEntityManager()->transactional(function ($em) use ($application) {
if ($application->isFirst()) {
$user = $application->getUser();

$user->setRoles(new ArrayCollection([$this->roleRepository->findBySystemName(Role::NONREGISTERED)]));
$user->setApproved(TRUE);
foreach ($user->getApplications() as $application) {
$this->applicationRepository->remove($application);
foreach ($this->userRepository->findAllWithWaitingForPaymentApplication() as $user) {
$this->applicationRepository->getEntityManager()->transactional(function ($em) use ($user, $cancelRegistration, $cancelRegistrationDate, $maturityReminder, $maturityReminderDate) {
foreach ($user->getWaitingForPaymentRolesApplications() as $application) {
if ($application->getType() == Application::ROLES) {
$maturityDate = $application->getMaturityDate();
if ($maturityDate === NULL)
continue;

if ($cancelRegistration !== NULL && $cancelRegistrationDate > $maturityDate) {
$rolesWithoutFee = $user->getRoles()->filter(function (Role $role) {
return $role->getFee() == 0;
});

if ($rolesWithoutFee->isEmpty()) {
$this->applicationService->cancelRegistration($user, ApplicationState::CANCELED_NOT_PAID, NULL);
return;
} else {
$this->applicationService->updateRoles($user, $rolesWithoutFee, NULL);
}
}
$this->userRepository->save($user);
}
}

$this->mailService->sendMailFromTemplate($user, '', Template::REGISTRATION_CANCELED, [
TemplateVariable::SEMINAR_NAME => $this->settingsRepository->getValue(Settings::SEMINAR_NAME)
]);
} else {
$application->setState(ApplicationState::CANCELED_NOT_PAID);
$this->applicationRepository->save($application);
foreach ($user->getWaitingForPaymentSubeventsApplications() as $application) {
if ($application->getType() == Application::SUBEVENTS) {
$maturityDate = $application->getMaturityDate();
if ($maturityDate === NULL)
continue;

if ($cancelRegistration !== NULL && $cancelRegistrationDate > $maturityDate) {
$this->applicationService->cancelSubeventsApplication($application, ApplicationState::CANCELED_NOT_PAID, NULL);
}
}
}

foreach ($user->getWaitingForPaymentApplications() as $application) {
$maturityDate = $application->getMaturityDate();
if ($maturityDate === NULL)
continue;

$this->programService->updateUserPrograms($application->getUser());
});
continue;
}

//připomenutí splatnosti
if ($maturityReminder !== NULL && $maturityReminderDate == $maturityDate) {
$this->mailService->sendMailFromTemplate($application->getUser(), '', Template::MATURITY_REMINDER, [
TemplateVariable::SEMINAR_NAME => $this->settingsRepository->getValue(Settings::SEMINAR_NAME),
TemplateVariable::APPLICATION_MATURITY => $maturityDate->format('j. n. Y')
]);
}
if ($maturityReminder !== NULL && $maturityReminderDate == $maturityDate) {
$this->mailService->sendMailFromTemplate($application->getUser(), '', Template::MATURITY_REMINDER, [
TemplateVariable::SEMINAR_NAME => $this->settingsRepository->getValue(Settings::SEMINAR_NAME),
TemplateVariable::APPLICATION_MATURITY => $maturityDate->format('j. n. Y')
]);
}
}
});
}
}
}
2 changes: 1 addition & 1 deletion app/AdminModule/MailingModule/forms/SendForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function create()
$form = $this->baseFormFactory->create();

$recipientRolesMultiSelect = $form->addMultiSelect('recipientRoles', 'admin.mailing.send_recipient_roles',
$this->roleRepository->getRolesWithoutRolesOptionsWithUsersCount([Role::GUEST, Role::UNAPPROVED, Role::NONREGISTERED]));
$this->roleRepository->getRolesWithoutRolesOptionsWithApprovedUsersCount([Role::GUEST, Role::UNAPPROVED, Role::NONREGISTERED]));

$recipientUsersMultiSelect = $form->addMultiSelect('recipientUsers', 'admin.mailing.send_recipient_users',
$this->userRepository->getUsersOptions())
Expand Down
Loading

0 comments on commit a13a0b5

Please sign in to comment.