A lot of things

This commit is contained in:
2026-06-16 16:21:43 +02:00
parent 4415a2e8c4
commit 73471162bf
37 changed files with 654 additions and 4 deletions

View File

@@ -0,0 +1,91 @@
<?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();
}
}

26
Entity/News.php Normal file
View File

@@ -0,0 +1,26 @@
<?php
namespace RomhackPlaza\Master\Entity;
use XF\Mvc\Entity\Entity;
use XF\Mvc\Entity\Structure;
class News extends Entity
{
#[Override]
public static function getStructure(Structure $structure)
{
$structure->shortName = 'RomhackPlaza\Master:News';
$structure->table = 'xf_romhackplaza_news'; // Unused.
$structure->primaryKey = 'id';
$structure->columns = [
'id' => ['type' => self::UINT],
'user_id' => ['type' => self::UINT, 'required' => true],
'title' => ['type' => self::STR, 'required' => true],
'slug' => ['type' => self::STR, 'required' => true],
];
return $structure;
}
}