From c7641b85e70f989c1f09fdfbd7b6bd855abb1d65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Fri, 16 Jun 2023 21:28:42 +0200 Subject: [PATCH 1/4] RVRNEXT-39 make main currency nullable --- src/PersistentData/Model/Community.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PersistentData/Model/Community.php b/src/PersistentData/Model/Community.php index 8419576..5a05ead 100644 --- a/src/PersistentData/Model/Community.php +++ b/src/PersistentData/Model/Community.php @@ -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; } From 1267cb3d95cf38fbb9eac788275148adacd0a637 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Fri, 16 Jun 2023 21:28:59 +0200 Subject: [PATCH 2/4] RVRNEXT-39 implement community delete --- src/Controller/CommunityController.php | 37 ++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/Controller/CommunityController.php b/src/Controller/CommunityController.php index 5366638..74ee8f1 100644 --- a/src/Controller/CommunityController.php +++ b/src/Controller/CommunityController.php @@ -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)) { From bb5b51031502a9d3317e3429a9c749a7d21c8e10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Fri, 16 Jun 2023 21:29:59 +0200 Subject: [PATCH 3/4] RVRNEXT-39 add delete button for communities --- views/communities/community_edit.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/views/communities/community_edit.php b/views/communities/community_edit.php index 2f6f5bd..77f182d 100644 --- a/views/communities/community_edit.php +++ b/views/communities/community_edit.php @@ -25,9 +25,15 @@

-
+
+ + +
+ +
+
@endsection From ade02f4736d1e3180096a47782c2a0535fa81f34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Fri, 16 Jun 2023 21:30:13 +0200 Subject: [PATCH 4/4] RVRNEXT-39 add endpoint for community delete --- web.php | 1 + 1 file changed, 1 insertion(+) diff --git a/web.php b/web.php index 3ad14df..5b77f8c 100644 --- a/web.php +++ b/web.php @@ -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']);