76 lines
2.1 KiB
PHP
76 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace RomhackPlaza\Master\ApprovalQueue;
|
|
|
|
use XF\ApprovalQueue\AbstractHandler;
|
|
use XF\Mvc\Entity\Entity;
|
|
|
|
class Club 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\Club $club)
|
|
{
|
|
$club->club_state = 'visible';
|
|
$club->save();
|
|
|
|
$node = \XF::em()->create('XF:Node');
|
|
$node->node_type_id = 'Forum';
|
|
$node->title = $club->title;
|
|
$node->description = $club->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();
|
|
|
|
$club->node_id = $node->node_id;
|
|
$club->save();
|
|
|
|
$user = $club->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(\RomhackPlaza\Master\Entity\Club::MOD_PERMISSIONS);
|
|
|
|
\XF::app()->jobManager()->enqueueUnique('permissionRebuild', 'XF:PermissionRebuild');
|
|
}
|
|
}
|
|
|
|
public function actionReject(\RomhackPlaza\Master\Entity\Club $club)
|
|
{
|
|
$club->club_state = 'rejected';
|
|
$club->save();
|
|
}
|
|
|
|
public function getTemplateName()
|
|
{
|
|
return 'public:approval_item_club_request';
|
|
}
|
|
} |