91 lines
2.8 KiB
PHP
91 lines
2.8 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace RomhackPlaza\Master\Entity;
|
||
|
|
|
||
|
|
use XF\Entity\ApprovalQueue;
|
||
|
|
use XF\Entity\User;
|
||
|
|
use XF\Mvc\Entity\Entity;
|
||
|
|
use XF\Mvc\Entity\Structure;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @property-read int featured_request_id
|
||
|
|
* @property int $entry_id
|
||
|
|
* @property int $user_id
|
||
|
|
* @property string $entry_title
|
||
|
|
* @property string featured_request_state
|
||
|
|
* @property int featured_request_date
|
||
|
|
* @property-read ?User User
|
||
|
|
*/
|
||
|
|
class EntryFeaturedRequest extends Entity
|
||
|
|
{
|
||
|
|
#[\Override]
|
||
|
|
public static function getStructure(Structure $structure)
|
||
|
|
{
|
||
|
|
$structure->shortName = 'RomhackPlaza\Master:EntryFeaturedRequest';
|
||
|
|
$structure->table = 'xf_romhackplaza_entry_featured_request';
|
||
|
|
$structure->primaryKey = 'featured_request_id';
|
||
|
|
|
||
|
|
$structure->columns = [
|
||
|
|
'featured_request_id' => ['type' => self::UINT, 'autoIncrement' => true],
|
||
|
|
'entry_id' => ['type' => self::UINT, 'required' => true],
|
||
|
|
'user_id' => ['type' => self::UINT],
|
||
|
|
'entry_title' => ['type' => self::STR, 'maxLength' => 255],
|
||
|
|
'featured_request_state' => ['type' => self::STR, 'default' => 'moderated',
|
||
|
|
'allowedValues' => ['visible', 'moderated', 'rejected']
|
||
|
|
],
|
||
|
|
'featured_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->featured_request_state === 'moderated' ) {
|
||
|
|
$this->inQueue();
|
||
|
|
} else if( $this->isUpdate() && $this->isChanged('featured_request_state') ) {
|
||
|
|
if( $this->featured_request_state === 'moderated' ) {
|
||
|
|
$this->inQueue();
|
||
|
|
} else {
|
||
|
|
$this->removeQueue();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
protected function _postDelete()
|
||
|
|
{
|
||
|
|
if( $this->featured_request_state === 'moderated' ) {
|
||
|
|
$this->removeQueue();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
protected function inQueue()
|
||
|
|
{
|
||
|
|
$queue = $this->em()->find('XF:ApprovalQueue', ['rhpz_entry_featurerequest', $this->featured_request_id ] );
|
||
|
|
if( !$queue )
|
||
|
|
{
|
||
|
|
/** @var ApprovalQueue $newQueue */
|
||
|
|
$newQueue = $this->em()->create('XF:ApprovalQueue');
|
||
|
|
$newQueue->content_type = 'rhpz_entry_featurerequest';
|
||
|
|
$newQueue->content_id = $this->featured_request_id;
|
||
|
|
$newQueue->save();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
protected function removeQueue()
|
||
|
|
{
|
||
|
|
$queue = $this->em()->find('XF:ApprovalQueue', ['rhpz_entry_featurerequest', $this->featured_request_id ] );
|
||
|
|
if( $queue )
|
||
|
|
$queue->delete();
|
||
|
|
}
|
||
|
|
}
|