Compare commits
No commits in common. "882b326aca5294f4f6154b1165a2da2725638ddc" and "a021aff92c57d8da3b70d574b1459109e668ac34" have entirely different histories.
882b326aca
...
a021aff92c
@ -85,25 +85,34 @@ class CommunityController implements IAuthenticationRequired
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function saveMember(): ?IContent
|
public function newMember(): ?IContent
|
||||||
{
|
{
|
||||||
if (!$this->checkPermission(\Container::$request->query('communityId'), true, $community, $ownCommunityMember)) {
|
if (!$this->checkPermission(\Container::$request->query('communityId'), true, $community, $ownCommunityMember)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$communityMemberId = \Container::$request->query('community_member_id');
|
$user = $this->userRepository->getById(\Container::$request->post('user_id'));
|
||||||
if ($communityMemberId) {
|
|
||||||
$communityMember = $this->communityMemberRepository->getById($communityMemberId);
|
$communityMember = new CommunityMember();
|
||||||
if ($communityMember->getUserId() === $ownCommunityMember->getUserId()) {
|
$communityMember->setCommunity($community);
|
||||||
return new JsonContent([
|
$communityMember->setUser($user);
|
||||||
'error' => ['errorText' => 'Own user cannot be edited.']
|
$communityMember->setOwner((bool)\Container::$request->post('owner'));
|
||||||
]);
|
\Container::$persistentDataManager->saveToDb($communityMember);
|
||||||
}
|
|
||||||
} else {
|
return new JsonContent(['success' => true]);
|
||||||
$user = $this->userRepository->getById(\Container::$request->post('user_id'));
|
}
|
||||||
$communityMember = new CommunityMember();
|
|
||||||
$communityMember->setCommunity($community);
|
public function editMember(): ?IContent
|
||||||
$communityMember->setUser($user);
|
{
|
||||||
|
if (!$this->checkPermission(\Container::$request->query('communityId'), true, $community, $ownCommunityMember)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$communityMember = $this->communityMemberRepository->getById(\Container::$request->query('community_member_id'));
|
||||||
|
if ($communityMember->getUserId() === \Container::$request->user()->getUniqueId()) {
|
||||||
|
return new JsonContent([
|
||||||
|
'error' => ['errorText' => 'Own user cannot be edited.']
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$communityMember->setOwner((bool)\Container::$request->post('owner'));
|
$communityMember->setOwner((bool)\Container::$request->post('owner'));
|
||||||
@ -142,7 +151,7 @@ class CommunityController implements IAuthenticationRequired
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function saveCurrency(): ?IContent
|
public function newCurrency(): ?IContent
|
||||||
{
|
{
|
||||||
if (!$this->checkPermission(\Container::$request->query('communityId'), true, $community, $ownCommunityMember)) {
|
if (!$this->checkPermission(\Container::$request->query('communityId'), true, $community, $ownCommunityMember)) {
|
||||||
return null;
|
return null;
|
||||||
@ -156,21 +165,15 @@ class CommunityController implements IAuthenticationRequired
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$currencyId = \Container::$request->query('currency_id');
|
|
||||||
if ($currencyId){
|
|
||||||
$currency = $this->currencyRepository->getById($currencyId);
|
|
||||||
} else {
|
|
||||||
$currency = new Currency();
|
|
||||||
$currency->setCommunity($community);
|
|
||||||
}
|
|
||||||
|
|
||||||
$existingCurrency = $this->currencyRepository->getByCommunityAndCurrencyCode($community, $code);
|
$existingCurrency = $this->currencyRepository->getByCommunityAndCurrencyCode($community, $code);
|
||||||
if ($existingCurrency !== null && $currency->getId() !== $existingCurrency->getId()) {
|
if ($existingCurrency !== null) {
|
||||||
return new JsonContent([
|
return new JsonContent([
|
||||||
'error' => ['errorText' => 'A currency with the same code exists for this community.']
|
'error' => ['errorText' => 'A currency with the same code exists for this community.']
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$currency = new Currency();
|
||||||
|
$currency->setCommunity($community);
|
||||||
$currency->setCode($code);
|
$currency->setCode($code);
|
||||||
$currency->setRoundDigits($roundDigits);
|
$currency->setRoundDigits($roundDigits);
|
||||||
\Container::$persistentDataManager->saveToDb($currency);
|
\Container::$persistentDataManager->saveToDb($currency);
|
||||||
@ -178,6 +181,20 @@ class CommunityController implements IAuthenticationRequired
|
|||||||
return new JsonContent(['success' => true]);
|
return new JsonContent(['success' => true]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function editCurrency(): ?IContent
|
||||||
|
{
|
||||||
|
if (!$this->checkPermission(\Container::$request->query('communityId'), true, $community, $ownCommunityMember)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$currency = $this->currencyRepository->getById(\Container::$request->query('currency_id'));
|
||||||
|
$currency->setCode(\Container::$request->post('code'));
|
||||||
|
$currency->setRoundDigits((int)\Container::$request->post('round_digits'));
|
||||||
|
\Container::$persistentDataManager->saveToDb($currency);
|
||||||
|
|
||||||
|
return new JsonContent(['success' => true]);
|
||||||
|
}
|
||||||
|
|
||||||
public function deleteCurrency(): ?IContent
|
public function deleteCurrency(): ?IContent
|
||||||
{
|
{
|
||||||
if (!$this->checkPermission(\Container::$request->query('communityId'), true, $community, $ownCommunityMember)) {
|
if (!$this->checkPermission(\Container::$request->query('communityId'), true, $community, $ownCommunityMember)) {
|
||||||
@ -211,7 +228,7 @@ class CommunityController implements IAuthenticationRequired
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function saveCurrencyExchangeRate(): ?IContent
|
public function newCurrencyExchangeRate(): ?IContent
|
||||||
{
|
{
|
||||||
if (!$this->checkPermission(\Container::$request->query('communityId'), true, $community, $ownCommunityMember)) {
|
if (!$this->checkPermission(\Container::$request->query('communityId'), true, $community, $ownCommunityMember)) {
|
||||||
return null;
|
return null;
|
||||||
@ -229,15 +246,29 @@ class CommunityController implements IAuthenticationRequired
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$currencyExchangeRateId = \Container::$request->query('currency_exchange_rate_id');
|
$currencyExchangeRate = new CurrencyExchangeRate();
|
||||||
if ($currencyExchangeRateId){
|
$currencyExchangeRate->setCurrency($currency);
|
||||||
$currencyExchangeRate = $this->currencyExchangeRatesRepository->getById($currencyExchangeRateId);
|
$currencyExchangeRate->setExchangeRate($exchangeRate);
|
||||||
} else {
|
$currencyExchangeRate->setValidFromDate(new DateTime(\Container::$request->post('valid_from')));
|
||||||
$currencyExchangeRate = new CurrencyExchangeRate();
|
\Container::$persistentDataManager->saveToDb($currencyExchangeRate);
|
||||||
$currencyExchangeRate->setCurrency($currency);
|
|
||||||
|
return new JsonContent(['success' => true]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function editCurrencyExchangeRate(): ?IContent
|
||||||
|
{
|
||||||
|
if (!$this->checkPermission(\Container::$request->query('communityId'), true, $community, $ownCommunityMember)) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$currencyExchangeRate->setExchangeRate($exchangeRate);
|
$currency = $this->currencyRepository->getByCommunityAndCurrencyCode($community, \Container::$request->query('code'));
|
||||||
|
if ($currency === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$currencyExchangeRate = $this->currencyExchangeRatesRepository->getById(\Container::$request->query('currency_exchange_rate_id'));
|
||||||
|
$currencyExchangeRate->setCurrency($currency);
|
||||||
|
$currencyExchangeRate->setExchangeRate((float)\Container::$request->post('exchange_rate'));
|
||||||
$currencyExchangeRate->setValidFromDate(new DateTime(\Container::$request->post('valid_from')));
|
$currencyExchangeRate->setValidFromDate(new DateTime(\Container::$request->post('valid_from')));
|
||||||
\Container::$persistentDataManager->saveToDb($currencyExchangeRate);
|
\Container::$persistentDataManager->saveToDb($currencyExchangeRate);
|
||||||
|
|
||||||
@ -263,6 +294,15 @@ class CommunityController implements IAuthenticationRequired
|
|||||||
|
|
||||||
public function saveCommunity(): ?IContent
|
public function saveCommunity(): ?IContent
|
||||||
{
|
{
|
||||||
|
$communityId = \Container::$request->query('communityId');
|
||||||
|
if ($communityId){
|
||||||
|
if (!$this->checkPermission($communityId, true, $community, $ownCommunityMember)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$community = new Community();
|
||||||
|
}
|
||||||
|
|
||||||
$name = \Container::$request->post('name');
|
$name = \Container::$request->post('name');
|
||||||
$currency = \Container::$request->post('currency');
|
$currency = \Container::$request->post('currency');
|
||||||
if (strlen($name) === 0 || strlen($currency) === 0 || strlen($currency) > 3) {
|
if (strlen($name) === 0 || strlen($currency) === 0 || strlen($currency) > 3) {
|
||||||
@ -271,18 +311,11 @@ class CommunityController implements IAuthenticationRequired
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$communityId = \Container::$request->query('communityId');
|
|
||||||
if ($communityId){
|
|
||||||
if (!$this->checkPermission($communityId, true, $community, $ownCommunityMember)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$community = new Community();
|
|
||||||
$community->setCreatedDate(new DateTime());
|
|
||||||
}
|
|
||||||
|
|
||||||
$community->setName($name);
|
$community->setName($name);
|
||||||
$community->setCurrency($currency);
|
$community->setCurrency($currency);
|
||||||
|
if (!$communityId) {
|
||||||
|
$community->setCreatedDate(new DateTime());
|
||||||
|
}
|
||||||
\Container::$persistentDataManager->saveToDb($community);
|
\Container::$persistentDataManager->saveToDb($community);
|
||||||
|
|
||||||
if (!$communityId) {
|
if (!$communityId) {
|
||||||
|
12
web.php
12
web.php
@ -63,17 +63,17 @@ Container::$routeCollection->group('communities', function (RouteCollection $rou
|
|||||||
$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->get('community-members', 'members', [CommunityController::class, 'getMembersEdit']);
|
$routeCollection->get('community-members', 'members', [CommunityController::class, 'getMembersEdit']);
|
||||||
$routeCollection->post('community-members-new', 'newMember', [CommunityController::class, 'saveMember']);
|
$routeCollection->post('community-members-new', 'newMember', [CommunityController::class, 'newMember']);
|
||||||
$routeCollection->post('community-members-edit', 'editMember', [CommunityController::class, 'saveMember']);
|
$routeCollection->post('community-members-edit', 'editMember', [CommunityController::class, 'editMember']);
|
||||||
$routeCollection->post('community-members-delete', 'deleteMember', [CommunityController::class, 'deleteMember']);
|
$routeCollection->post('community-members-delete', 'deleteMember', [CommunityController::class, 'deleteMember']);
|
||||||
$routeCollection->get('community-currencies', 'currencies', [CommunityController::class, 'getCurrenciesEdit']);
|
$routeCollection->get('community-currencies', 'currencies', [CommunityController::class, 'getCurrenciesEdit']);
|
||||||
$routeCollection->post('community-currencies-new', 'newCurrency', [CommunityController::class, 'saveCurrency']);
|
$routeCollection->post('community-currencies-new', 'newCurrency', [CommunityController::class, 'newCurrency']);
|
||||||
$routeCollection->post('community-currencies-edit', 'editCurrency', [CommunityController::class, 'saveCurrency']);
|
$routeCollection->post('community-currencies-edit', 'editCurrency', [CommunityController::class, 'editCurrency']);
|
||||||
$routeCollection->post('community-currencies-delete', 'deleteCurrency', [CommunityController::class, 'deleteCurrency']);
|
$routeCollection->post('community-currencies-delete', 'deleteCurrency', [CommunityController::class, 'deleteCurrency']);
|
||||||
$routeCollection->group('currencyExchangeRates', function (RouteCollection $routeCollection) {
|
$routeCollection->group('currencyExchangeRates', function (RouteCollection $routeCollection) {
|
||||||
$routeCollection->get('community-currency-exchange-rates', '{code}', [CommunityController::class, 'getCurrencyExchangeRates']);
|
$routeCollection->get('community-currency-exchange-rates', '{code}', [CommunityController::class, 'getCurrencyExchangeRates']);
|
||||||
$routeCollection->post('community-currency-exchange-rates-new', '{code}/new', [CommunityController::class, 'saveCurrencyExchangeRate']);
|
$routeCollection->post('community-currency-exchange-rates-new', '{code}/new', [CommunityController::class, 'newCurrencyExchangeRate']);
|
||||||
$routeCollection->post('community-currency-exchange-rates-edit', '{code}/edit', [CommunityController::class, 'saveCurrencyExchangeRate']);
|
$routeCollection->post('community-currency-exchange-rates-edit', '{code}/edit', [CommunityController::class, 'editCurrencyExchangeRate']);
|
||||||
$routeCollection->post('community-currency-exchange-rates-delete', '{code}/delete', [CommunityController::class, 'deleteCurrencyExchangeRate']);
|
$routeCollection->post('community-currency-exchange-rates-delete', '{code}/delete', [CommunityController::class, 'deleteCurrencyExchangeRate']);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user