Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-stanek committed Nov 9, 2024
1 parent f88809d commit 11db171
Show file tree
Hide file tree
Showing 11 changed files with 210 additions and 171 deletions.
2 changes: 1 addition & 1 deletion app/AdminModule/Components/UsersGridControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function createComponentUsersGrid(string $name): DataGrid
->andWhere('uA.validTo IS NULL')
->andWhere('uA.state IN (:states)')
->setParameter('sids', (array) $values)
->setParameter('states', [ApplicationState::PAID, ApplicationState::PAID_FREE, ApplicationState::WAITING_FOR_PAYMENT]);
->setParameter('states', [ApplicationState::PAID, ApplicationState::PAID_FREE, ApplicationState::PAID_TRANSFERED, ApplicationState::WAITING_FOR_PAYMENT]);
});

$columnApproved = $grid->addColumnStatus('approved', 'admin.users.users_approved');
Expand Down
64 changes: 3 additions & 61 deletions app/AdminModule/Forms/EditUserTransferFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ public function create(int $id): Form

$form->addSelect('targetUser', 'admin.users.users_target_user', $this->userRepository->getUsersOptions(true))
->addRule(Form::NOT_EQUAL, 'admin.users.users_target_user_empty', 0)
->addRule(Form::NOT_EQUAL, 'admin.users.users_target_user_same', $this->user->getId())
->setHtmlAttribute('data-live-search', 'true');

$form->addSubmit('submit', 'admin.users.users_transfer')
->setDisabled(! $this->user->isRegistered())
->setHtmlAttribute('class', 'btn btn-danger')
->setHtmlAttribute('data-toggle', 'confirmation')
->setHtmlAttribute('data-content', $this->translator->translate('admin.users.users_transfer_confirm'));
Expand All @@ -67,68 +69,8 @@ public function create(int $id): Form
public function processForm(Form $form, stdClass $values): void
{
$targetUser = $this->userRepository->findById($values->targetUser);

$userRoles = $this->user->getRoles();
$targetUserRoles = $targetUser->getRoles();

$targetRoles = new ArrayCollection();
foreach ($userRoles as $role) {
if (!$targetRoles->contains($role)) {
$targetRoles->add($role);
}
}
foreach ($targetUserRoles as $role) {
if (!$targetRoles->contains($role) && $role->getSystemName() !== Role::NONREGISTERED) {
$targetRoles->add($role);
}
}

$userSubevents = $this->user->getSubevents();
$targetUserSubevents = $this->user->getSubevents();

$targetSubevents = new ArrayCollection();
foreach ($userSubevents as $subevent) {
if (!$targetSubevents->contains($subevent)) {
$targetSubevents->add($subevent);
}
}
foreach ($targetUserSubevents as $subevent) {
if (!$targetSubevents->contains($subevent)) {
$targetSubevents->add($subevent);
}
}

$loggedUser = $form->getPresenter()->getDbUser();

$this->applicationService->cancelRegistration($this->user, ApplicationState::CANCELED_TRANSFERED, $loggedUser);
$this->applicationService->updateRoles($targetUser, $targetRoles, $form->getPresenter()->getDbUser(), $loggedUser);
$this->applicationService->addSubeventsApplication($targetUser, $targetSubevents, $loggedUser);

// todo: pridani platby za vsechny role a podakce (i ty ktere uz mel)

// $this->user->setFirstName($values->firstName);
// $this->user->setLastName($values->lastName);
// $this->user->setNickName($values->nickName);
// $this->user->setDegreePre($values->degreePre);
// $this->user->setDegreePost($values->degreePost);
// $this->user->setEmail($values->email);
// $this->user->setPhone($values->phone);
// $this->user->setBirthdate($values->birthdate);
// $this->user->setStreet($values->street);
// $this->user->setCity($values->city);
// $this->user->setPostcode($values->postcode);
//
// $photo = $values->photo;
// if ($photo->getError() === UPLOAD_ERR_OK) {
// $photoExtension = image_type_to_extension(getimagesizefromstring($photo->getContents())[2]);
// $photoName = 'ext_' . $this->user->getId() . $photoExtension;
//
// $path = $this->filesService->save($photo, User::PHOTO_PATH, false, $photoName);
// $this->filesService->resizeAndCropImage($path, 135, 180);
//
// $this->user->setPhoto($path);
// }
//
// $this->userRepository->save($this->user);
$this->applicationService->transferRegistration($this->user, $targetUser, $loggedUser);
}
}
13 changes: 1 addition & 12 deletions app/AdminModule/Presenters/UsersPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,19 +227,8 @@ protected function createComponentEditUserTransferForm(): Form
{
$form = $this->editUserTransferFormFactory->create((int) $this->getParameter('id'));

// $form->onError[] = function (Form $form): void {
// foreach ($form->errors as $error) {
// $this->flashMessage($error, 'danger');
// }
//
// $this->redirect('this');
// };

$form->onSuccess[] = function (Form $form, stdClass $values): void {
if ($form->isSubmitted() != $form['cancel']) {
$this->flashMessage('admin.users.users_saved', 'success');
}

$this->flashMessage('admin.users.users_transfered', 'success');
$this->redirect('this');
};

Expand Down
3 changes: 2 additions & 1 deletion app/Model/Structure/Subevent.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,8 @@ public function countUsers(): int
return $this->applications->filter(static fn (Application $application) => $application->getValidTo() === null && (
$application->getState() === ApplicationState::WAITING_FOR_PAYMENT ||
$application->getState() === ApplicationState::PAID_FREE ||
$application->getState() === ApplicationState::PAID))->count();
$application->getState() === ApplicationState::PAID ||
$application->getState() === ApplicationState::PAID_TRANSFERED))->count();
}

public function countUnoccupied(): int|null
Expand Down
2 changes: 1 addition & 1 deletion app/Model/User/Repositories/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function findAllWithSubevents(array $subeventsIds): Collection
->where('a.validTo IS NULL')
->andWhere('a.state IN (:states)')
->andWhere('s.id IN (:ids)')
->setParameter('states', [ApplicationState::PAID, ApplicationState::PAID_FREE, ApplicationState::WAITING_FOR_PAYMENT])
->setParameter('states', [ApplicationState::PAID, ApplicationState::PAID_FREE, ApplicationState::PAID_TRANSFERED, ApplicationState::WAITING_FOR_PAYMENT])
->setParameter('ids', $subeventsIds)
->getQuery()
->getResult();
Expand Down
29 changes: 28 additions & 1 deletion app/Model/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,11 @@ public function isInRoleWithSystemName(string $name): bool
return $this->roles->exists(static fn (int $key, Role $role) => $role->getSystemName() === $name);
}

public function isRegistered(): bool
{
return ! $this->isInRoleWithSystemName(Role::NONREGISTERED);
}

/**
* Vrací, zda má uživatel nějakou roli, která nemá cenu podle podakcí.
*/
Expand Down Expand Up @@ -808,7 +813,9 @@ public function getPaidAndFreeApplications(): Collection
{
return $this->applications->filter(static fn (Application $application) => $application->getValidTo() === null && (
$application->getState() === ApplicationState::PAID_FREE ||
$application->getState() === ApplicationState::PAID));
$application->getState() === ApplicationState::PAID ||
$application->getState() === ApplicationState::PAID_TRANSFERED
));
}

/**
Expand Down Expand Up @@ -1089,6 +1096,26 @@ public function hasSubevent(Subevent $subevent): bool
return $this->getSubevents()->contains($subevent);
}

/**
* Vrací zaplacné podakce uživatele.
*
* @return Collection<int, Subevent>
*/
public function getPaidSubevents(): Collection
{
$subevents = new ArrayCollection();

foreach ($this->getPaidAndFreeApplications() as $application) {
if ($application instanceof SubeventsApplication) {
foreach ($application->getSubevents() as $subevent) {
$subevents->add($subevent);
}
}
}

return $subevents;
}

/**
* Vrácí, zda má uživatel zaplacenou přihlášku s podakcí.
*/
Expand Down
Loading

0 comments on commit 11db171

Please sign in to comment.