Compare commits

..

4 Commits

Author SHA1 Message Date
ae4f6b043a
RVRNEXT-39 add endpoint for community delete
Some checks failed
rvr-nextgen/pipeline/pr-master There was a failure building this commit
2023-06-16 21:30:13 +02:00
038f20549d
RVRNEXT-39 add delete button for communities 2023-06-16 21:29:59 +02:00
4ea5ba96d9
RVRNEXT-39 implement community delete 2023-06-16 21:28:59 +02:00
c7641b85e7
RVRNEXT-39 make main currency nullable 2023-06-16 21:28:42 +02:00
4 changed files with 47 additions and 3 deletions

View File

@ -176,6 +176,43 @@ class CommunityController implements IAuthenticationRequired
]);
}
public function deleteCommunity(): IContent
{
if (!$this->checkPermission(\Container::$request->query('communitySlug'), true, $community, $ownCommunityMember)) {
return null;
}
if ($this->transactionRepository->countAllByCommunity($community) > 0) {
return new JsonContent([
'error' => ['errorText' => 'There are transactions for this community!']
]);
}
if ($this->eventRepository->countAllByCommunity($community) > 0) {
return new JsonContent([
'error' => ['errorText' => 'There are events for this community!']
]);
}
foreach ($this->communityMemberRepository->getAllByCommunity($community) as $communityMember) {
\Container::$persistentDataManager->deleteFromDb($communityMember);
}
$community->setMainCurrencyId(null);
\Container::$persistentDataManager->saveToDb($community);
foreach ($this->currencyRepository->getAllByCommunity($community) as $currency) {
foreach ($this->currencyExchangeRatesRepository->getAllByCurrency($currency) as $currencyExchangeRate) {
\Container::$persistentDataManager->deleteFromDb($currencyExchangeRate);
}
\Container::$persistentDataManager->deleteFromDb($currency);
}
\Container::$persistentDataManager->deleteFromDb($community);
return new JsonContent(['success' => true]);
}
public function getMembersEdit(): ?IContent
{
if (!$this->checkPermission(\Container::$request->query('communitySlug'), true, $community, $ownCommunityMember)) {

View File

@ -33,12 +33,12 @@ class Community extends ModelWithSlug
$this->currency = $currency;
}
public function setMainCurrency(Currency $mainCurrency): void
public function setMainCurrency(?Currency $mainCurrency): void
{
$this->mainCurrency = $mainCurrency;
}
public function setMainCurrencyId(int $mainCurrencyId): void
public function setMainCurrencyId(?int $mainCurrencyId): void
{
$this->mainCurrencyId = $mainCurrencyId;
}

View File

@ -25,9 +25,15 @@
<input type="number" class="text big fullWidth" name="main_currency_round_digits" min="0" max="9" required>
<?php endif; ?>
<p id="communityFormError" class="formError justify marginTop"></p>
<div class="right marginTop">
<div class="right marginTop" style="font-size: 0;">
<button type="submit" name="submit_button"><?= isset($community) ? '<i class="fa-regular fa-floppy-disk"></i> Save' : '<i class="fa-regular fa-plus"></i> Create' ?></button>
<?php if (isset($community)): ?>
<button type="submit" form="deleteCommunity" name="submit_button" data-confirmation="Are you sure you want to delete this community?" class="red marginLeft"><i class="fa-regular fa-trash-can"></i> Delete</button>
<?php endif; ?>
</div>
</form>
<?php if (isset($community)): ?>
<form id="deleteCommunity" action="<?= Container::$routeCollection->getRoute('community.delete-action')->generateLink(['communitySlug' => $community->getSlug()]) ?>" method="post" data-redirect-on-success="<?= Container::$routeCollection->getRoute('home')->generateLink() ?>"></form>
<?php endif; ?>
</div>
@endsection

View File

@ -70,6 +70,7 @@ Container::$routeCollection->group('communities', function (RouteCollection $rou
$routeCollection->get('community.settings', 'settings', [CommunityController::class, 'getCommunitySettings']);
$routeCollection->get('community.edit', 'edit', [CommunityController::class, 'getCommunityEdit']);
$routeCollection->post('community.edit-action', 'edit', [CommunityController::class, 'saveCommunity']);
$routeCollection->post('community.delete-action', 'delete', [CommunityController::class, 'deleteCommunity']);
$routeCollection->get('community.members', 'members', [CommunityController::class, 'getMembersEdit']);
$routeCollection->post('community.members.new-action', 'members/new', [CommunityController::class, 'saveMember']);
$routeCollection->post('community.members.edit-action', 'members/edit', [CommunityController::class, 'saveMember']);