Club System
This commit is contained in:
83
ApprovalQueue/ClubRequest.php
Normal file
83
ApprovalQueue/ClubRequest.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Master\ApprovalQueue;
|
||||
|
||||
use XF\ApprovalQueue\AbstractHandler;
|
||||
use XF\Mvc\Entity\Entity;
|
||||
|
||||
class ClubRequest extends AbstractHandler
|
||||
{
|
||||
|
||||
protected function canViewContent(Entity $content, &$error = null)
|
||||
{
|
||||
return $this->canActionContent($content, $error);
|
||||
}
|
||||
|
||||
protected function canActionContent(Entity $content, &$error = null)
|
||||
{
|
||||
return \XF::visitor()->hasAdminPermission('node');
|
||||
}
|
||||
|
||||
public function getEntityWith()
|
||||
{
|
||||
return ['User'];
|
||||
}
|
||||
|
||||
public function actionApprove(\RomhackPlaza\Master\Entity\ClubRequest $clubRequest)
|
||||
{
|
||||
$clubRequest->request_state = 'visible';
|
||||
$clubRequest->save();
|
||||
|
||||
$node = \XF::em()->create('XF:Node');
|
||||
$node->node_type_id = 'Forum';
|
||||
$node->title = $clubRequest->title;
|
||||
$node->description = $clubRequest->description;
|
||||
$node->parent_node_id = \XF::options()->rhpz_club_node_id ?? 0;
|
||||
$node->display_order = 1;
|
||||
$node->save();
|
||||
|
||||
$forum = \XF::em()->create('XF:Forum');
|
||||
$forum->node_id = $node->node_id;
|
||||
$forum->allow_posting = true;
|
||||
$forum->save();
|
||||
|
||||
$user = $clubRequest->User;
|
||||
if ($user) {
|
||||
|
||||
$modContent = \XF::em()->create('XF:ModeratorContent');
|
||||
$modContent->content_type = 'node';
|
||||
$modContent->content_id = $node->node_id;
|
||||
$modContent->user_id = $user->user_id;
|
||||
$modContent->save();
|
||||
|
||||
$permissionUpdater = \XF::app()->service('XF:UpdatePermissions');
|
||||
$permissionUpdater->setContent('node', $node->node_id);
|
||||
$permissionUpdater->setUser($user);
|
||||
|
||||
$permissionUpdater->updatePermissions([
|
||||
'forum' => [
|
||||
'editAnyPost' => 'content_allow',
|
||||
'deleteAnyPost' => 'content_allow',
|
||||
'deleteAnyThread' => 'content_allow',
|
||||
'inlineMod' => 'content_allow',
|
||||
'lockUnlockThread' => 'content_allow',
|
||||
'stickUnstickThread' => 'content_allow'
|
||||
]
|
||||
]);
|
||||
|
||||
// D. Reconstruction des permissions
|
||||
\XF::app()->jobManager()->enqueueUnique('permissionRebuild', 'XF:PermissionRebuild');
|
||||
}
|
||||
}
|
||||
|
||||
public function actionReject(\RomhackPlaza\Master\Entity\ClubRequest $clubRequest)
|
||||
{
|
||||
$clubRequest->request_state = 'rejected';
|
||||
$clubRequest->save();
|
||||
}
|
||||
|
||||
public function getTemplateName()
|
||||
{
|
||||
return 'public:approval_item_club_request';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user