A lot of things.
This commit is contained in:
73
Service/Club/EditorService.php
Normal file
73
Service/Club/EditorService.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user