Jake Vanderwerf
2026-04-15 c4aa5cdb5e90ad4b420e22772797d16980232a2b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?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');
    }
 
}