<?php
|
namespace JVBase\managers;
|
|
use JVBase\registrar\Registrar;
|
|
if (!defined('ABSPATH')) {
|
exit; // Exit if accessed directly
|
}
|
/**
|
* Forum Manager
|
* TODO
|
* Handles a forum functionality
|
*/
|
class ForumManager
|
{
|
protected CustomTable $relationships;
|
protected CustomTable $forum;
|
protected KarmaManager $karma;
|
|
public function __construct()
|
{
|
$this->defineTables();
|
$this->registerHooks();
|
}
|
public function registerHooks():void
|
{
|
add_action('jvbDefineRegistrar', [$this, 'registerForum']);
|
add_action('jvbDefineRegistrarFields', [$this, 'registerForumFields']);
|
add_action('plugins_loaded', [$this, 'registerForum'], 1);
|
add_action('plugins_loaded', [$this, 'registerForum'], 2);
|
}
|
public function registerForum():void
|
{
|
Registrar::forPost('jvbforum', 'Post', 'Posts')
|
->setIcon('note')
|
->make([
|
'public' => false,
|
'taxonomies' => [
|
'topic'
|
]
|
]);
|
|
Registrar::forTerm('jvbtopic', 'Topic', 'Topics')
|
->setIcon('folder')
|
->make([
|
'hierarchical' => true,
|
'for' => ['jvbforum']
|
]);
|
}
|
public function registerForumFields():void
|
{
|
$forum = Registrar::getInstance('jvbforum');
|
$fields = $forum->fields();
|
|
$topic = Registrar::getInstance('jvbtopic');
|
$topicFields = $topic->fields();
|
}
|
|
|
protected function defineTables():void
|
{
|
$this->definedRelationshipsTable();
|
$this->karma = KarmaManager::for('forum', 'post');
|
}
|
protected function definedRelationshipsTable():void
|
{
|
$table = CustomTable::for('forum_relationship');
|
|
$table->setColumns([
|
'id' => 'bigint(20) unsigned NOT NULL AUTO_INCREMENT',
|
'term_id' => "{$table->getTermIDType()} NOT NULL",
|
'user_id' => "{$table->getUserIDType()} NOT NULL",
|
'profile_id'=> "{$table->getPostIDType()} NOT NULL",
|
'forum_count' => 'int(10) unsigned NOT NULL',
|
'last_post_date'=> 'datetime DEFAULT NULL',
|
'updated_at' => 'timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'
|
]);
|
|
$table->setKeys([
|
['key' => 'PRIMARY', 'value' => '(`id`)'],
|
['key' => 'UNIQUE', 'value' => '`term_user` (`term_id`, `user_id`)'],
|
'`term_id` (`term_id`)',
|
'`user_id` (`user_id`)',
|
'`profile_id` (`profile_id`)',
|
]);
|
$base = BASE;
|
$table->setConstraints([
|
"CONSTRAINT `{$base}fr_term_forum_term` FOREIGN KEY (`term_id`)
|
REFERENCES `{$table->getTermTable()}` (`term_id`) ON DELETE CASCADE",
|
"CONSTRAINT `{$base}fr_term_forum_user` FOREIGN KEY (`user_id`)
|
REFERENCES `{$table->getUserTable()}` (`ID`) ON DELETE CASCADE",
|
"CONSTRAINT `{$base}fr_term_news_profile` FOREIGN KEY (`profile_id`)
|
REFERENCES `{$table->getPostTable()}` (`ID`) ON DELETE CASCADE",
|
]);
|
|
$table->defineTable();
|
$this->relationships = $table;
|
}
|
}
|