This commit is contained in:
20 files changed
+135
-237
No files matched your search
@@ -8,28 +8,20 @@ use RVR\Repository\CommunityRepository;
|
||||
use RVR\Repository\CommunityMemberRepository;
|
||||
use RVR\Repository\UserRepository;
|
||||
use SokoWeb\Interfaces\Authentication\IAuthenticationRequired;
|
||||
use SokoWeb\Interfaces\Request\IRequest;
|
||||
use SokoWeb\Interfaces\Response\IContent;
|
||||
use SokoWeb\PersistentData\PersistentDataManager;
|
||||
use SokoWeb\Response\HtmlContent;
|
||||
use SokoWeb\Response\JsonContent;
|
||||
|
||||
class CommunityController implements IAuthenticationRequired
|
||||
{
|
||||
private IRequest $request;
|
||||
|
||||
private PersistentDataManager $pdm;
|
||||
|
||||
private UserRepository $userRepository;
|
||||
|
||||
private CommunityRepository $communityRepository;
|
||||
|
||||
private CommunityMemberRepository $communityMemberRepository;
|
||||
|
||||
public function __construct(IRequest $request)
|
||||
public function __construct()
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->pdm = new PersistentDataManager();
|
||||
$this->userRepository = new UserRepository();
|
||||
$this->communityRepository = new CommunityRepository();
|
||||
$this->communityMemberRepository = new CommunityMemberRepository();
|
||||
@@ -42,7 +34,7 @@ class CommunityController implements IAuthenticationRequired
|
||||
|
||||
public function getCommunityHome(): ?IContent
|
||||
{
|
||||
if (!$this->checkPermission($this->request->query('communityId'), false, $community, $ownCommunityMember)) {
|
||||
if (!$this->checkPermission(\Container::$request->query('communityId'), false, $community, $ownCommunityMember)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -62,7 +54,7 @@ class CommunityController implements IAuthenticationRequired
|
||||
|
||||
public function getCommunityEdit(): ?IContent
|
||||
{
|
||||
if (!$this->checkPermission($this->request->query('communityId'), true, $community, $ownCommunityMember)) {
|
||||
if (!$this->checkPermission(\Container::$request->query('communityId'), true, $community, $ownCommunityMember)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -73,7 +65,7 @@ class CommunityController implements IAuthenticationRequired
|
||||
|
||||
public function getMembersEdit(): ?IContent
|
||||
{
|
||||
if (!$this->checkPermission($this->request->query('communityId'), true, $community, $ownCommunityMember)) {
|
||||
if (!$this->checkPermission(\Container::$request->query('communityId'), true, $community, $ownCommunityMember)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -95,60 +87,60 @@ class CommunityController implements IAuthenticationRequired
|
||||
|
||||
public function newMember(): ?IContent
|
||||
{
|
||||
if (!$this->checkPermission($this->request->query('communityId'), true, $community, $ownCommunityMember)) {
|
||||
if (!$this->checkPermission(\Container::$request->query('communityId'), true, $community, $ownCommunityMember)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$user = $this->userRepository->getById($this->request->post('user_id'));
|
||||
$user = $this->userRepository->getById(\Container::$request->post('user_id'));
|
||||
|
||||
$communityMember = new CommunityMember();
|
||||
$communityMember->setCommunity($community);
|
||||
$communityMember->setUser($user);
|
||||
$this->pdm->saveToDb($communityMember);
|
||||
\Container::$persistentDataManager->saveToDb($communityMember);
|
||||
|
||||
return new JsonContent(['success' => true]);
|
||||
}
|
||||
|
||||
public function editMember(): ?IContent
|
||||
{
|
||||
if (!$this->checkPermission($this->request->query('communityId'), true, $community, $ownCommunityMember)) {
|
||||
if (!$this->checkPermission(\Container::$request->query('communityId'), true, $community, $ownCommunityMember)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$communityMember = $this->communityMemberRepository->getById($this->request->post('community_member_id'));
|
||||
if ($communityMember->getUserId() === $this->request->user()->getUniqueId()) {
|
||||
$communityMember = $this->communityMemberRepository->getById(\Container::$request->post('community_member_id'));
|
||||
if ($communityMember->getUserId() === \Container::$request->user()->getUniqueId()) {
|
||||
return new JsonContent([
|
||||
'error' => ['errorText' => 'Own user cannot be edited.']
|
||||
]);
|
||||
}
|
||||
|
||||
$communityMember->setOwner($this->request->post('owner'));
|
||||
$this->pdm->saveToDb($communityMember);
|
||||
$communityMember->setOwner(\Container::$request->post('owner'));
|
||||
\Container::$persistentDataManager->saveToDb($communityMember);
|
||||
|
||||
return new JsonContent(['success' => true]);
|
||||
}
|
||||
|
||||
public function deleteMember(): ?IContent
|
||||
{
|
||||
if (!$this->checkPermission($this->request->query('communityId'), true, $community, $ownCommunityMember)) {
|
||||
if (!$this->checkPermission(\Container::$request->query('communityId'), true, $community, $ownCommunityMember)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$communityMember = $this->communityMemberRepository->getById($this->request->post('community_member_id'));
|
||||
if ($communityMember->getUserId() === $this->request->user()->getUniqueId()) {
|
||||
$communityMember = $this->communityMemberRepository->getById(\Container::$request->post('community_member_id'));
|
||||
if ($communityMember->getUserId() === \Container::$request->user()->getUniqueId()) {
|
||||
return new JsonContent([
|
||||
'error' => ['errorText' => 'Own user cannot be deleted.']
|
||||
]);
|
||||
}
|
||||
|
||||
$this->pdm->deleteFromDb($communityMember);
|
||||
\Container::$persistentDataManager->deleteFromDb($communityMember);
|
||||
|
||||
return new JsonContent(['success' => true]);
|
||||
}
|
||||
|
||||
public function saveCommunity(): ?IContent
|
||||
{
|
||||
$communityId = $this->request->query('communityId');
|
||||
$communityId = \Container::$request->query('communityId');
|
||||
if ($communityId){
|
||||
if (!$this->checkPermission($communityId, true, $community, $ownCommunityMember)) {
|
||||
return null;
|
||||
@@ -157,8 +149,8 @@ class CommunityController implements IAuthenticationRequired
|
||||
$community = new Community();
|
||||
}
|
||||
|
||||
$name = $this->request->post('name');
|
||||
$currency = $this->request->post('currency');
|
||||
$name = \Container::$request->post('name');
|
||||
$currency = \Container::$request->post('currency');
|
||||
if (strlen($name) === 0 || strlen($currency) === 0 || strlen($currency) > 3) {
|
||||
return new JsonContent([
|
||||
'error' => ['errorText' => 'Please fill all required fields!']
|
||||
@@ -170,19 +162,19 @@ class CommunityController implements IAuthenticationRequired
|
||||
if (!$communityId) {
|
||||
$community->setCreatedDate(new DateTime());
|
||||
}
|
||||
$this->pdm->saveToDb($community);
|
||||
\Container::$persistentDataManager->saveToDb($community);
|
||||
|
||||
if (!$communityId) {
|
||||
/**
|
||||
* @var User $user
|
||||
*/
|
||||
$user = $this->request->user();
|
||||
$user = \Container::$request->user();
|
||||
|
||||
$communityMember = new CommunityMember();
|
||||
$communityMember->setCommunity($community);
|
||||
$communityMember->setUser($user);
|
||||
$communityMember->setOwner(true);
|
||||
$this->pdm->saveToDb($communityMember);
|
||||
\Container::$persistentDataManager->saveToDb($communityMember);
|
||||
}
|
||||
|
||||
return new JsonContent([
|
||||
@@ -204,7 +196,7 @@ class CommunityController implements IAuthenticationRequired
|
||||
/**
|
||||
* @var User $user
|
||||
*/
|
||||
$user = $this->request->user();
|
||||
$user = \Container::$request->user();
|
||||
|
||||
$ownCommunityMember = $this->communityMemberRepository->getByCommunityAndUser($community, $user);
|
||||
if ($ownCommunityMember === null || ($needToBeOwner && !$ownCommunityMember->getOwner())) {
|
||||
|
||||
Reference in new issue
Block a user