From 49df206ddc9c0a578fb1050d464ebb71f4904829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Fri, 28 Apr 2023 21:20:08 +0200 Subject: [PATCH] RVRNEXT-5 move saveCommunity under getCommunityEdit --- src/Controller/CommunityController.php | 114 ++++++++++++------------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/src/Controller/CommunityController.php b/src/Controller/CommunityController.php index bf5419a..f14225e 100644 --- a/src/Controller/CommunityController.php +++ b/src/Controller/CommunityController.php @@ -75,6 +75,63 @@ class CommunityController implements IAuthenticationRequired ]); } + public function saveCommunity(): ?IContent + { + $name = \Container::$request->post('name'); + if (strlen($name) === 0) { + return new JsonContent([ + 'error' => ['errorText' => 'Please fill all required fields!'] + ]); + } + + $communityId = \Container::$request->query('communityId'); + if ($communityId){ + if (!$this->checkPermission($communityId, true, $community, $ownCommunityMember)) { + return null; + } + } else { + $mainCurrencyCode = \Container::$request->post('main_currency_code'); + $mainCurrencyRoundDigits = \Container::$request->post('main_currency_round_digits'); + if (strlen($mainCurrencyCode) === 0 || strlen($mainCurrencyCode) > 3 || $mainCurrencyRoundDigits < 0 || $mainCurrencyRoundDigits > 9) { + return new JsonContent([ + 'error' => ['errorText' => 'Please fill all required fields!'] + ]); + } + + $community = new Community(); + $community->setCreatedDate(new DateTime()); + } + + $community->setName($name); + \Container::$persistentDataManager->saveToDb($community); + + if (!$communityId) { + /** + * @var User $user + */ + $user = \Container::$request->user(); + + $communityMember = new CommunityMember(); + $communityMember->setCommunity($community); + $communityMember->setUser($user); + $communityMember->setOwner(true); + \Container::$persistentDataManager->saveToDb($communityMember); + + $mainCurrency = new Currency(); + $mainCurrency->setCommunity($community); + $mainCurrency->setCode($mainCurrencyCode); + $mainCurrency->setRoundDigits($mainCurrencyRoundDigits); + \Container::$persistentDataManager->saveToDb($mainCurrency); + + $community->setMainCurrency($mainCurrency); + \Container::$persistentDataManager->saveToDb($community); + } + + return new JsonContent([ + 'redirect' => ['target' => \Container::$routeCollection->getRoute('community')->generateLink(['communityId' => $community->getId()])] + ]); + } + public function getMembersEdit(): ?IContent { if (!$this->checkPermission(\Container::$request->query('communityId'), true, $community, $ownCommunityMember)) { @@ -267,63 +324,6 @@ class CommunityController implements IAuthenticationRequired return new JsonContent(['success' => true]); } - public function saveCommunity(): ?IContent - { - $name = \Container::$request->post('name'); - if (strlen($name) === 0) { - return new JsonContent([ - 'error' => ['errorText' => 'Please fill all required fields!'] - ]); - } - - $communityId = \Container::$request->query('communityId'); - if ($communityId){ - if (!$this->checkPermission($communityId, true, $community, $ownCommunityMember)) { - return null; - } - } else { - $mainCurrencyCode = \Container::$request->post('main_currency_code'); - $mainCurrencyRoundDigits = \Container::$request->post('main_currency_round_digits'); - if (strlen($mainCurrencyCode) === 0 || strlen($mainCurrencyCode) > 3 || $mainCurrencyRoundDigits < 0 || $mainCurrencyRoundDigits > 9) { - return new JsonContent([ - 'error' => ['errorText' => 'Please fill all required fields!'] - ]); - } - - $community = new Community(); - $community->setCreatedDate(new DateTime()); - } - - $community->setName($name); - \Container::$persistentDataManager->saveToDb($community); - - if (!$communityId) { - /** - * @var User $user - */ - $user = \Container::$request->user(); - - $communityMember = new CommunityMember(); - $communityMember->setCommunity($community); - $communityMember->setUser($user); - $communityMember->setOwner(true); - \Container::$persistentDataManager->saveToDb($communityMember); - - $mainCurrency = new Currency(); - $mainCurrency->setCommunity($community); - $mainCurrency->setCode($mainCurrencyCode); - $mainCurrency->setRoundDigits($mainCurrencyRoundDigits); - \Container::$persistentDataManager->saveToDb($mainCurrency); - - $community->setMainCurrency($mainCurrency); - \Container::$persistentDataManager->saveToDb($community); - } - - return new JsonContent([ - 'redirect' => ['target' => \Container::$routeCollection->getRoute('community')->generateLink(['communityId' => $community->getId()])] - ]); - } - private function getMembers(Community $community): array { $members = iterator_to_array($this->communityMemberRepository->getAllByCommunity($community, true, [User::class]));