64 lines
1.5 KiB
PHP
64 lines
1.5 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace RomhackPlaza\Master\Service\Club;
|
||
|
|
|
||
|
|
use RomhackPlaza\Master\Entity\Club;
|
||
|
|
use XF\App;
|
||
|
|
use XF\Entity\Forum;
|
||
|
|
use XF\Entity\Node;
|
||
|
|
use XF\Service\AbstractService;
|
||
|
|
use XF\Util\File;
|
||
|
|
|
||
|
|
class ApproverService extends AbstractService
|
||
|
|
{
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @var Club
|
||
|
|
*/
|
||
|
|
protected $club;
|
||
|
|
|
||
|
|
public function __construct(App $app, Club $club)
|
||
|
|
{
|
||
|
|
parent::__construct($app);
|
||
|
|
|
||
|
|
$this->club = $club;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function approve(): bool
|
||
|
|
{
|
||
|
|
if( $this->club->club_state !== 'moderated' ) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
$this->club->club_state = 'visible';
|
||
|
|
$this->club->save();
|
||
|
|
|
||
|
|
/** @var Node $node */
|
||
|
|
$node = $this->em()->create('XF:Node');
|
||
|
|
|
||
|
|
$node->node_type_id = 'Forum';
|
||
|
|
$node->title = $this->club->title;
|
||
|
|
$node->description = $this->club->description;
|
||
|
|
$node->parent_node_id = \XF::options()->rhpz_club_node_id ?? 0;
|
||
|
|
$node->display_order = 1;
|
||
|
|
$node->save();
|
||
|
|
|
||
|
|
/** @var Forum $forum */
|
||
|
|
$forum = $this->em()->create('XF:Forum');
|
||
|
|
$forum->node_id = $node->node_id;
|
||
|
|
$forum->allow_posting = true;
|
||
|
|
$forum->save();
|
||
|
|
|
||
|
|
$this->club->node_id = $node->node_id;
|
||
|
|
$this->club->save();
|
||
|
|
|
||
|
|
$user = $this->club->User;
|
||
|
|
if( $user ){
|
||
|
|
/** @var ModeratorService $modManage */
|
||
|
|
$modManage = \XF::app()->service('RomhackPlaza\Master:Club\Moderator', $this->club, $user );
|
||
|
|
$modManage->addModerator( $error );
|
||
|
|
}
|
||
|
|
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
}
|