<?php
|
namespace JVBase\managers;
|
|
if (!defined('ABSPATH')) {
|
exit; // Exit if accessed directly
|
}
|
/**
|
* Response Manager
|
*
|
* Handles a responses
|
* TODO
|
*/
|
class ResponseManager
|
{
|
protected CustomTable $response;
|
protected KarmaManager $karma;
|
|
public function __construct()
|
{
|
$this->defineTables();
|
}
|
protected function defineTables():void
|
{
|
$table = CustomTable::for('responses');
|
|
$table->setColumns([
|
'id' => 'bigint(20) unsigned NOT NULL AUTO_INCREMENT',
|
'item_id' => "{$table->getPostIDType()} NOT NULL",
|
'type' => 'varchar(50) NOT NULL',
|
'user_id' => "{$table->getUserIdType()} NOT NULL",
|
'parent_id' => 'bigint(20) unsigned DEFAULT 0',
|
'response' => 'text NOT NULL',
|
'upvotes' => 'int NOT NULL DEFAULT 0',
|
'downvotes' => 'int NOT NULL DEFAULT 0',
|
'karma' => 'int NOT NULL DEFAULT 0',
|
'status' => "ENUM('publish', 'hidden','flagged','deleted') DEFAULT 'publish'",
|
'is_user_deleted' => 'tinyint(1) DEFAULT 0',
|
'created_at'=> 'datetime DEFAULT CURRENT_TIMESTAMP',
|
'updated_at'=> 'datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP',
|
]);
|
|
$table->setKeys([
|
['key' => 'PRIMARY', 'value' => '`id`'],
|
'`item_lookup` (`item_id`)',
|
'`user_lookup` (`user_id`)',
|
'`parent_lookup` (`parent_id`)',
|
'`karma` (`karma`)',
|
'`upvote` (`upvotes`)',
|
'`downvote` (`downvotes`)',
|
]);
|
|
$base = BASE;
|
$table->setConstraints([
|
"CONSTRAINT `{$base}responses_item` FOREIGN KEY (`item_id`)
|
REFERENCES `{$table->getPostTable()}` (`ID`) ON DELETE CASCADE",
|
]);
|
$table->defineTable();
|
|
$this->response = $table;
|
|
$this->karma = KarmaManager::for('responses', 'responses');
|
}
|
|
}
|