A lot of things.
This commit is contained in:
120
Entity/Club.php
Normal file
120
Entity/Club.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Master\Entity;
|
||||
|
||||
use XF\Entity\ApprovalQueue;
|
||||
use XF\Entity\Forum;
|
||||
use XF\Mvc\Entity\Entity;
|
||||
use XF\Mvc\Entity\Structure;
|
||||
|
||||
/**
|
||||
* @property-read int club_id
|
||||
* @property int node_id
|
||||
* @property int user_id
|
||||
* @property string title
|
||||
* @property string description
|
||||
* @property string club_state
|
||||
* @property int club_date
|
||||
* @property int banner_date
|
||||
* @property ?Forum Forum
|
||||
*/
|
||||
class Club extends Entity
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public const array MOD_PERMISSIONS = [
|
||||
'forum' => [
|
||||
'editAnyPost' => 'content_allow',
|
||||
'deleteAnyPost' => 'content_allow',
|
||||
'deleteAnyThread' => 'content_allow',
|
||||
'inlineMod' => 'content_allow',
|
||||
'lockUnlockThread' => 'content_allow',
|
||||
'stickUnstickThread' => 'content_allow'
|
||||
]
|
||||
];
|
||||
|
||||
public static function getStructure(Structure $structure): Structure
|
||||
{
|
||||
$structure->table = 'xf_club';
|
||||
$structure->shortName = 'RomhackPlaza\Master:Club';
|
||||
$structure->primaryKey = 'club_id';
|
||||
$structure->columns = [
|
||||
'club_id' => ['type' => self::UINT, 'autoIncrement' => true],
|
||||
'node_id' => ['type' => self::UINT, 'default' => 0],
|
||||
'user_id' => ['type' => self::UINT, 'required' => true],
|
||||
'title' => ['type' => self::STR, 'maxLength' => 100, 'required' => true],
|
||||
'description' => ['type' => self::STR, 'required' => true],
|
||||
'club_state' => ['type' => self::STR, 'default' => 'moderated',
|
||||
'allowedValues' => ['visible', 'moderated', 'rejected']
|
||||
],
|
||||
'club_creation_date' => ['type' => self::UINT, 'default' => \XF::$time],
|
||||
'banner_date' => ['type' => self::UINT, 'default' => 0],
|
||||
];
|
||||
$structure->relations = [
|
||||
'User' => [
|
||||
'entity' => 'XF:User',
|
||||
'type' => self::TO_ONE,
|
||||
'conditions' => 'user_id',
|
||||
'primary' => true
|
||||
],
|
||||
'Forum' => [
|
||||
'entity' => 'XF:Forum',
|
||||
'type' => self::TO_ONE,
|
||||
'conditions' => 'node_id',
|
||||
'primary' => true
|
||||
]
|
||||
];
|
||||
|
||||
return $structure;
|
||||
}
|
||||
|
||||
public function getBannerUrl(): ?string
|
||||
{
|
||||
if( !$this->banner_date )
|
||||
return null;
|
||||
|
||||
return \XF::app()->applyExternalDataUrl("club_banners/{$this->club_id}.jpg?{$this->banner_date}");
|
||||
}
|
||||
|
||||
protected function _postSave()
|
||||
{
|
||||
if( $this->isInsert() && $this->club_state == 'moderated' ){
|
||||
$this->inQueue();
|
||||
} else if( $this->isUpdate() && $this->isChanged('club_state') ){
|
||||
if( $this->club_state === 'moderated' ){
|
||||
$this->inQueue();
|
||||
} else {
|
||||
$this->removeQueue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function _postDelete()
|
||||
{
|
||||
if( $this->club_state === 'moderated' ){
|
||||
$this->removeQueue();
|
||||
}
|
||||
}
|
||||
|
||||
protected function inQueue()
|
||||
{
|
||||
$queue = $this->em()->find('XF:ApprovalQueue', ['club', $this->club_id ] );
|
||||
if( !$queue )
|
||||
{
|
||||
/** @var ApprovalQueue $newQueue */
|
||||
$newQueue = $this->em()->create('XF:ApprovalQueue');
|
||||
$newQueue->content_type = 'club';
|
||||
$newQueue->content_id = $this->club_id;
|
||||
$newQueue->save();
|
||||
}
|
||||
}
|
||||
|
||||
protected function removeQueue()
|
||||
{
|
||||
$queue = $this->em()->find('XF:ApprovalQueue', ['club', $this->club_id ] );
|
||||
if( $queue )
|
||||
$queue->delete();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user