Club System

This commit is contained in:
2026-06-02 20:54:08 +02:00
parent d79dbecad4
commit f4dc336c88
13 changed files with 371 additions and 40 deletions

75
Entity/ClubRequest.php Normal file
View File

@@ -0,0 +1,75 @@
<?php
namespace RomhackPlaza\Master\Entity;
use XF\Mvc\Entity\Entity;
use XF\Mvc\Entity\Structure;
class ClubRequest extends Entity
{
public static function getStructure(Structure $structure): Structure
{
$structure->table = 'xf_club_request';
$structure->shortName = 'RomhackPlaza\Master:ClubRequest';
$structure->primaryKey = 'request_id';
$structure->columns = [
'request_id' => ['type' => self::UINT, 'autoIncrement' => true],
'user_id' => ['type' => self::UINT, 'required' => true],
'title' => ['type' => self::STR, 'maxLength' => 100, 'required' => true],
'description' => ['type' => self::STR, 'required' => true],
'request_state' => ['type' => self::STR, 'default' => 'moderated',
'allowedValues' => ['visible', 'moderated', 'rejected']
],
'request_date' => ['type' => self::UINT, 'default' => \XF::$time]
];
$structure->relations = [
'User' => [
'entity' => 'XF:User',
'type' => self::TO_ONE,
'conditions' => 'user_id',
'primary' => true
]
];
return $structure;
}
protected function _postSave()
{
if( $this->isInsert() && $this->request_state == 'moderated' ){
$this->inQueue();
} else if( $this->isUpdate() && $this->isChanged('request_state') ){
if( $this->request_state === 'moderated' ){
$this->inQueue();
} else {
$this->removeQueue();
}
}
}
protected function _postDelete()
{
if( $this->request_state === 'moderated' ){
$this->removeQueue();
}
}
protected function inQueue()
{
$queue = $this->em()->find('XF:ApprovalQueue', ['club_request', $this->request_id ] );
if( !$queue )
{
$newQueue = $this->em()->create('XF:ApprovalQueue');
$newQueue->content_type = 'club_request';
$newQueue->content_id = $this->request_id;
$newQueue->save();
}
}
protected function removeQueue()
{
$queue = $this->em()->find('XF:ApprovalQueue', ['club_request', $this->request_id ] );
if( $queue )
$queue->delete();
}
}