feature/RVRNEXT-5-main-currency-of-community-should-be-a-general-currency #34
@ -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]));
|
||||
|
Loading…
Reference in New Issue
Block a user