Files
XenForoRomhackPlazaAddon/Service/Club/EditorService.php
2026-06-08 16:25:52 +02:00

73 lines
1.7 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\Http\Upload;
use XF\Service\AbstractService;
use XF\Service\ValidateAndSavableTrait;
use XF\Util\File;
class EditorService extends AbstractService
{
use ValidateAndSavableTrait;
/**
* @var Club
*/
protected $club;
public function __construct(App $app, Club $club)
{
parent::__construct($app);
$this->club = $club;
}
public function setContent(string $title, string $description)
{
$this->club->title = $title;
$this->club->description = $description;
}
public function setBannerUpload(?Upload $upload = null)
{
if( $upload ){
$upload->requireImage();
if( $upload->isValid() ){
$path = 'data://club_banners/' . $this->club->club_id . '.jpg';
if(File::copyFileToAbstractedPath($upload->getFileWrapper()->getFilePath(), $path)){
$this->club->banner_date = \XF::$time;
}
}
}
}
protected function syncForumNode()
{
if( $this->club->Forum && $this->club->Forum->Node )
{
$node = $this->club->Forum->Node;
$node->title = $this->club->title;
$node->description = $this->club->description;
$node->save();
}
}
protected function _validate()
{
$this->club->preSave();
return $this->club->getErrors();
}
protected function _save()
{
$this->club->save();
$this->syncForumNode();
return $this->club;
}
}