| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yatra\Database\Tables; |
| 4 |
|
| 5 |
/** |
| 6 |
* Reviews Table Class |
| 7 |
* |
| 8 |
* Represents the reviews table (wp_yatra_reviews) containing trip review data |
| 9 |
* including ratings, content, author information, status management, |
| 10 |
* and helpful voting. |
| 11 |
* |
| 12 |
* This table follows the new simplified pattern with only two static methods: |
| 13 |
* - getTableName(): Returns the prefixed table name |
| 14 |
* - getSchema(): Returns the complete CREATE TABLE SQL statement |
| 15 |
* |
| 16 |
* Usage: |
| 17 |
* ReviewsTable::getTableName() // Returns 'wp_yatra_reviews' |
| 18 |
* ReviewsTable::getSchema() // Returns complete SQL schema |
| 19 |
* |
| 20 |
* @package Yatra\Database\Tables |
| 21 |
* @since 1.0.0 |
| 22 |
*/ |
| 23 |
class ReviewsTable extends BaseTable |
| 24 |
{ |
| 25 |
/** |
| 26 |
* Table name without prefix |
| 27 |
* |
| 28 |
* @var string The base table name without WordPress prefix |
| 29 |
*/ |
| 30 |
protected static string $table = 'yatra_reviews'; |
| 31 |
|
| 32 |
/** |
| 33 |
* Get the complete table schema as raw SQL CREATE TABLE statement |
| 34 |
* |
| 35 |
* Returns the full SQL schema for the reviews table using heredoc syntax |
| 36 |
* for proper IDE syntax highlighting. Includes all columns, indexes, |
| 37 |
* and constraints from the original Database.php schema. |
| 38 |
* |
| 39 |
* @return string Complete CREATE TABLE SQL statement |
| 40 |
*/ |
| 41 |
public static function getSchema(): string |
| 42 |
{ |
| 43 |
$tableName = static::getTableName(); |
| 44 |
$charsetCollate = static::getCharsetCollate(); |
| 45 |
|
| 46 |
return <<<SQL |
| 47 |
CREATE TABLE IF NOT EXISTS `{$tableName}` ( |
| 48 |
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, |
| 49 |
`trip_id` bigint(20) UNSIGNED NOT NULL, |
| 50 |
`user_id` bigint(20) UNSIGNED DEFAULT 0, |
| 51 |
`rating` tinyint(1) UNSIGNED NOT NULL, |
| 52 |
`title` varchar(255) DEFAULT NULL, |
| 53 |
`content` text NOT NULL, |
| 54 |
`author_name` varchar(100) NOT NULL, |
| 55 |
`author_email` varchar(100) DEFAULT NULL, |
| 56 |
`author_location` varchar(100) DEFAULT NULL, |
| 57 |
`status` enum('pending','approved','rejected','spam','trash') DEFAULT 'pending', |
| 58 |
`helpful_count` int(11) UNSIGNED DEFAULT 0, |
| 59 |
`created_at` datetime DEFAULT CURRENT_TIMESTAMP, |
| 60 |
`updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| 61 |
`created_by` bigint(20) unsigned DEFAULT NULL COMMENT 'User ID who created this review', |
| 62 |
`updated_by` bigint(20) unsigned DEFAULT NULL COMMENT 'User ID who last updated this review', |
| 63 |
|
| 64 |
PRIMARY KEY (`id`), |
| 65 |
KEY `idx_trip_status` (`trip_id`, `status`), |
| 66 |
KEY `idx_user_id` (`user_id`), |
| 67 |
KEY `idx_status` (`status`), |
| 68 |
KEY `idx_rating` (`rating`), |
| 69 |
KEY `idx_created_at` (`created_at`) |
| 70 |
) {$charsetCollate} COMMENT='Trip reviews and ratings'; |
| 71 |
SQL; |
| 72 |
} |
| 73 |
} |
| 74 |
|