Skip to content

Commit

Permalink
added tying troop participants together in admin
Browse files Browse the repository at this point in the history
  • Loading branch information
Lung committed Dec 8, 2023
1 parent baeb110 commit d9f9d30
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 6 deletions.
9 changes: 7 additions & 2 deletions src/Application/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,12 @@ public function addRoutesInto(App $app): App
->setName('admin-generate-more-payments');
});

$app->get('/troopManagement', AdminController::class . '::showTroopManagement')
->setName('admin-troop-management');
$app->group('/troopManagement', function (RouteCollectorProxy $app) {
$app->get('', AdminController::class . '::showTroopManagement')
->setName('admin-troop-management');
$app->post('/tieTogether', AdminController::class . '::tieTogether')
->setName('admin-troop-tie-together');
});

$app->group('/export', function (RouteCollectorProxy $app) {
$app->get('/health', ExportController::class . '::exportHealthData')
Expand All @@ -274,6 +278,7 @@ public function addRoutesInto(App $app): App
$app->group($app->getBasePath() . '/v3', function (RouteCollectorProxy $app) {
$app->post('/entry/{entryCode}', EntryController::class . '::entry')
->setName('entry');

$app->group('/event/{eventSlug}', function (RouteCollectorProxy $app) {
$app->group('/admin', function (RouteCollectorProxy $app) {
$app->group('/{participantId}', function (RouteCollectorProxy $app) {
Expand Down
18 changes: 18 additions & 0 deletions src/Participant/Admin/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -551,4 +551,22 @@ public function showTroopManagement(Request $request, Response $response, Event
'caTp' => $event->getEventType()->getContentArbiterTroopParticipant(),
]);
}

public function tieTogether(Request $request, Response $response, Event $event): Response
{
$troopLeaderCode = $this->getParameterFromBody($request, 'tieCodeLeader');
$troopParticipantCode = $this->getParameterFromBody($request, 'tieCodeParticipant');

$this->troopService->tryTieTogetherWithMessages(
$troopLeaderCode,
$troopParticipantCode,
$event,
);

return $this->redirect(
$request,
$response,
'admin-troop-management',
);
}
}
2 changes: 1 addition & 1 deletion src/Participant/Participant.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function getFullName(): string
{
return ($this->firstName ?? '') . ' ' . ($this->lastName ?? '') . ($this->nickname ? ' - ' . $this->nickname : '');
}

public function isFullNameNotEmpty(): bool
{
return $this->getFullName() !== ' ';
Expand Down
43 changes: 43 additions & 0 deletions src/Participant/Troop/TroopService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
class TroopService
{
public function __construct(
private readonly TroopLeaderRepository $troopLeaderRepository,
private readonly TroopParticipantRepository $troopParticipantRepository,
private readonly ParticipantRepository $participantRepository,
private readonly FlashMessagesInterface $flashMessages,
Expand Down Expand Up @@ -87,4 +88,46 @@ public function untieTroopParticipant(int $participantId): TroopParticipant

return $troopParticipant;
}

public function tryTieTogetherWithMessages(
string $troopLeaderCode,
string $troopParticipantCode,
Event $event,
): bool {
$valid = true;
$tl = $this->troopLeaderRepository->findTroopLeaderFromTieCode($troopLeaderCode, $event);
if ($tl === null) {
$this->flashMessages->warning($this->translator->trans('flash.warning.troopLeaderNotFoundTieNotPossible'));
$valid = false;
}

if ($tl !== null && $tl->getUserButNotNull()->status === UserStatus::Paid) {
$this->flashMessages->warning($this->translator->trans('flash.warning.troopLeaderPaidTieNotPossible'));
$valid = false;
}

$tp = $this->troopParticipantRepository->findTroopParticipantFromTieCode($troopParticipantCode, $event);
if ($tp === null) {
$this->flashMessages->warning($this->translator->trans('flash.warning.troopParticipantNotFoundTieNotPossible'));
$valid = false;
}

if ($tp !== null && $tp->getUserButNotNull()->status === UserStatus::Paid) {
$this->flashMessages->warning($this->translator->trans('flash.warning.troopParticipantPaidTieNotPossible'));
$valid = false;
}

if ($tp !== null && $tp->troopLeader !== null) {
$this->flashMessages->warning($this->translator->trans('flash.warning.troopParticipantHasTroopTieNotPossible'));
$valid = false;
}

if ($valid && $tp !== null && $tl !== null) {
$tp->troopLeader = $tl;
$this->troopParticipantRepository->persist($tp);
$this->flashMessages->success($this->translator->trans('flash.success.troopTied'));
}

return $valid;
}
}
6 changes: 6 additions & 0 deletions src/Templates/cs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ flash:
adminPairedPayments: "Spárováno bankovních transakcí: "
transfer: "Platba úspěšně přesunuta!"
troopParticipantTiedToTroopLeader: "Účastník úspěšně připojen do skupiny!"
troopTied: "Účastník úspěšně připojen do skupiny!"
warning:
noLock: "Registraci nelze uzamknout - nějaké informace jsou špatně vyplněné nebo chybí (pravděpodobně nějaké datum)"
plWrongData: "Nemůžeme uzamknout registraci - prosím oprav svoje údaje (nejspíš email nebo nějaké datum)"
Expand Down Expand Up @@ -473,6 +474,11 @@ flash:
troopLeaderNotOpen: "Vedoucí skupiny není odemčený, proto nelze připojit účastníka ke skupině"
troopParticipantAlreadyTied: "Účastník již byl do skupiny přidán"
alreadyTied: "Nemůžeš se přidat do skupiny, protože již ve skupině jsi. Jestli chceš k jiné skupině, popros vedoucího o odepnutí"
troopLeaderNotFoundTieNotPossible: "Vedoucí skupiny nebyl nalezen, připojení do skupiny není možné"
troopLeaderPaidTieNotPossible: "Vedoucí skupiny má zaplacenou registraci, připojení do skupiny není možné"
troopParticipantNotFoundTieNotPossible: "Účastník nebyl nalezen, připojení do skupiny není možné"
troopParticipantPaidTieNotPossible: "Účastník má zaplacenou registraci, připojení do skupiny není možné"
troopParticipantHasTroopTieNotPossible: "Účastník již skupinu má, připojení do skupiny není možné"
error:
adminOnly: "Sorry bro, pouze pro administrátory"
plOnly: "Pardon, nejsi přihlášený jako vedoucí patroly"
Expand Down
6 changes: 6 additions & 0 deletions src/Templates/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ flash:
adminPairedPayments: "Paired bank transactions: "
transfer: "Payment transfer was successful!"
troopParticipantTiedToTroopLeader: "Troop participant is successfully tied to troop leader"
troopTied: "Participant successfully added to the group!"
warning:
noLock: "Cannot lock the registration - some details are wrong or missing (probably email or date)"
plWrongData: "Cannot lock the registration - some details are wrong or missing (probably email or date)"
Expand Down Expand Up @@ -473,6 +474,11 @@ flash:
troopLeaderNotOpen: "Troop leader is not open yet, please wait for it to open"
troopParticipantAlreadyTied: "Troop participant is already tied to another group"
alreadyTied: "You cannot join the group because you are already in it. If you want to join a different group, please ask the leader to remove you."
troopLeaderNotFoundTieNotPossible: "Troop leader not found, tie is not possible"
troopLeaderPaidTieNotPossible: "Troop leader has paid registration, tie is not possible"
troopParticipantNotFoundTieNotPossible: "Troop participant not found, tie is not possible"
troopParticipantPaidTieNotPossible: "Troop participant has paid registration, tie is not possible"
troopParticipantHasTroopTieNotPossible: "Troop participant is already tied to a group, tie is not possible"
error:
adminOnly: "Sorry bro, admins only"
plOnly: "Sorry, you are not logged as Patrol Leader"
Expand Down
10 changes: 8 additions & 2 deletions src/Templates/sk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,9 @@ flash:
approved: "Účastník akce schválen, platební údaje vygenerovány a e-mail odeslán"
guestApproved: "Host schválen a e-mail odeslán (bez platby)"
tpApproved: "Účastník akce schválen a e-mail odeslán (bez platby)"
adminPairedPayments: "Paired bank transactions: "
transfer: "Payment transfer was successful!"
adminPairedPayments: "Párované bankovní transakce: "
transfer: "Přesun platby proběhl úspěšně!"
troopTied: "Účastník úspešne pridaný do skupiny!"
warning:
noLock: "Nie je možné uzamknúť registráciu - nejaký z údajov je nesprávny alebo chýbajúci (možno nejaký dátum)"
plWrongData: "Nie je možné uzamknúť registráciu - prosím oprav svoje údaje (nejspíš email nebo nějaké datum)"
Expand All @@ -431,6 +432,11 @@ flash:
nonexistentEvent: "Tato akce nejspíš neexistuje. Asi špatný odkaz?"
testingSite: "Tato stránka je určena pouze pro testovací účely - nezadávej žádné reálné osobní či citlivé údaje!"
multiplePaymentsNotAllowed: "Pardon, ale generování více plateb pro účastníka není pro tuto akci povoleno."
troopLeaderNotFoundTieNotPossible: "Vedúci skupiny nebol nájdený, pridanie do skupiny nie je možné"
troopLeaderPaidTieNotPossible: "Vedúci skupiny má zaplatenú registráciu, pridanie do skupiny nie je možné"
troopParticipantNotFoundTieNotPossible: "Účastník nebol nájdený, pridanie do skupiny nie je možné"
troopParticipantPaidTieNotPossible: "Účastník má zaplatenú registráciu, pridanie do skupiny nie je možné"
troopParticipantHasTroopTieNotPossible: "Účastník už skupinu má, pridanie do skupiny nie je možné"
error:
adminOnly: "Sorry bro, sem môžu len admini"
plOnly: "Prepáč, ale nie si prihlásený/á ako Patrol líder"
Expand Down
2 changes: 1 addition & 1 deletion src/Templates/translatable/admin/troopManagement.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<h2>{% trans %}troopManagement-admin.tieTogether{% endtrans %}</h2>
<form
method="POST"
action="{{ url_for('tie-tp-by-tp', {'eventSlug': event.slug}) }}"{# TODO use new correct address #}
action="{{ url_for('admin-troop-tie-together', {'eventSlug': event.slug}) }}"
class="form-group form-group-middle"
>
<label for="tieCodeLeader">{% trans %}dashboard.codeForTieToTroop{% endtrans %}:</label>
Expand Down

0 comments on commit d9f9d30

Please sign in to comment.