[ '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(); } }