A lot of things.
This commit is contained in:
99
Service/Club/CreatorService.php
Normal file
99
Service/Club/CreatorService.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Master\Service\Club;
|
||||
|
||||
use RomhackPlaza\Master\Entity\Club;
|
||||
use RomhackPlaza\Master\XF\Entity\Forum;
|
||||
use XF\App;
|
||||
use XF\Entity\Node;
|
||||
use XF\Entity\User;
|
||||
use XF\Http\Upload;
|
||||
use XF\Service\AbstractService;
|
||||
use XF\Service\ValidateAndSavableTrait;
|
||||
use XF\Util\File;
|
||||
|
||||
class CreatorService extends AbstractService
|
||||
{
|
||||
use ValidateAndSavableTrait;
|
||||
|
||||
/**
|
||||
* @var Club
|
||||
*/
|
||||
protected $club;
|
||||
|
||||
/**
|
||||
* @var Upload
|
||||
*/
|
||||
protected $bannerUpload;
|
||||
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
public function __construct(App $app, User $creator)
|
||||
{
|
||||
parent::__construct($app);
|
||||
$this->club = $this->em()->create('RomhackPlaza\Master:Club');
|
||||
$this->setUser($creator);
|
||||
$this->setupDefaults();
|
||||
}
|
||||
|
||||
protected function setupDefaults()
|
||||
{
|
||||
$this->club->club_state = 'moderated';
|
||||
}
|
||||
|
||||
public function getClub()
|
||||
{
|
||||
return $this->club;
|
||||
}
|
||||
|
||||
public function getUser()
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
public function setUser(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->club->user_id = $this->user->user_id;
|
||||
}
|
||||
|
||||
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()){
|
||||
$this->bannerUpload = $upload;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function _validate()
|
||||
{
|
||||
$this->club->preSave();
|
||||
return $this->club->getErrors();
|
||||
}
|
||||
|
||||
protected function _save()
|
||||
{
|
||||
$this->club->save();
|
||||
|
||||
if( $this->bannerUpload ){
|
||||
$path = 'data://club_banners/' . $this->club->club_id . '.jpg';
|
||||
if( File::copyFileToAbstractedPath($this->bannerUpload->getFileWrapper()->getFilePath(), $path) ){
|
||||
$this->club->banner_date = \XF::$time;
|
||||
$this->club->save();
|
||||
}
|
||||
}
|
||||
|
||||
return $this->club;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user