feature/RVRNEXT-39-delete-communities #58
@ -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
 | 
					    public function getMembersEdit(): ?IContent
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (!$this->checkPermission(\Container::$request->query('communitySlug'), true, $community, $ownCommunityMember)) {
 | 
					        if (!$this->checkPermission(\Container::$request->query('communitySlug'), true, $community, $ownCommunityMember)) {
 | 
				
			||||||
 | 
				
			|||||||
@ -33,12 +33,12 @@ class Community extends ModelWithSlug
 | 
				
			|||||||
        $this->currency = $currency;
 | 
					        $this->currency = $currency;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function setMainCurrency(Currency $mainCurrency): void
 | 
					    public function setMainCurrency(?Currency $mainCurrency): void
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->mainCurrency = $mainCurrency;
 | 
					        $this->mainCurrency = $mainCurrency;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function setMainCurrencyId(int $mainCurrencyId): void
 | 
					    public function setMainCurrencyId(?int $mainCurrencyId): void
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->mainCurrencyId = $mainCurrencyId;
 | 
					        $this->mainCurrencyId = $mainCurrencyId;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -25,9 +25,15 @@
 | 
				
			|||||||
                <input type="number" class="text big fullWidth" name="main_currency_round_digits" min="0" max="9" required>
 | 
					                <input type="number" class="text big fullWidth" name="main_currency_round_digits" min="0" max="9" required>
 | 
				
			||||||
            <?php endif; ?>
 | 
					            <?php endif; ?>
 | 
				
			||||||
            <p id="communityFormError" class="formError justify marginTop"></p>
 | 
					            <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>
 | 
					                <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>
 | 
					            </div>
 | 
				
			||||||
        </form>
 | 
					        </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>
 | 
					    </div>
 | 
				
			||||||
@endsection
 | 
					@endsection
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										1
									
								
								web.php
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								web.php
									
									
									
									
									
								
							@ -70,6 +70,7 @@ Container::$routeCollection->group('communities', function (RouteCollection $rou
 | 
				
			|||||||
        $routeCollection->get('community.settings', 'settings', [CommunityController::class, 'getCommunitySettings']);
 | 
					        $routeCollection->get('community.settings', 'settings', [CommunityController::class, 'getCommunitySettings']);
 | 
				
			||||||
        $routeCollection->get('community.edit', 'edit', [CommunityController::class, 'getCommunityEdit']);
 | 
					        $routeCollection->get('community.edit', 'edit', [CommunityController::class, 'getCommunityEdit']);
 | 
				
			||||||
        $routeCollection->post('community.edit-action', 'edit', [CommunityController::class, 'saveCommunity']);
 | 
					        $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->get('community.members', 'members', [CommunityController::class, 'getMembersEdit']);
 | 
				
			||||||
        $routeCollection->post('community.members.new-action', 'members/new', [CommunityController::class, 'saveMember']);
 | 
					        $routeCollection->post('community.members.new-action', 'members/new', [CommunityController::class, 'saveMember']);
 | 
				
			||||||
        $routeCollection->post('community.members.edit-action', 'members/edit', [CommunityController::class, 'saveMember']);
 | 
					        $routeCollection->post('community.members.edit-action', 'members/edit', [CommunityController::class, 'saveMember']);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user