| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yatra\Database\Tables; |
| 4 |
|
| 5 |
use Yatra\Database\Tables\BaseTable; |
| 6 |
|
| 7 |
/** |
| 8 |
* Optimized TripContent Table Class |
| 9 |
* |
| 10 |
* Consolidates multiple content tables into a unified system: |
| 11 |
* - yatra_trip_gallery_images |
| 12 |
* - yatra_trip_downloads |
| 13 |
* - yatra_trip_highlights |
| 14 |
* - yatra_trip_faqs |
| 15 |
* |
| 16 |
* This unified content system handles all trip-related content with |
| 17 |
* type-based differentiation and flexible metadata. |
| 18 |
* |
| 19 |
* Key improvements: |
| 20 |
* - Single table for all trip content |
| 21 |
* - Type-based content organization |
| 22 |
* - JSON metadata for flexibility |
| 23 |
* - Built-in sorting and display control |
| 24 |
* - Support for future content types |
| 25 |
* |
| 26 |
* @package Yatra\Database\Tables\Optimized |
| 27 |
* @since 2.0.0 |
| 28 |
*/ |
| 29 |
class TripContentTable extends BaseTable |
| 30 |
{ |
| 31 |
/** |
| 32 |
* Table name without prefix |
| 33 |
* |
| 34 |
* @var string The base table name without WordPress prefix |
| 35 |
*/ |
| 36 |
protected static string $table = 'yatra_trip_content'; |
| 37 |
|
| 38 |
/** |
| 39 |
* Get the complete table schema as raw SQL CREATE TABLE statement |
| 40 |
* |
| 41 |
* Returns the optimized schema that unifies all trip content |
| 42 |
* into a single flexible table with type-based organization. |
| 43 |
* |
| 44 |
* @return string Complete CREATE TABLE SQL statement |
| 45 |
*/ |
| 46 |
public static function getSchema(): string |
| 47 |
{ |
| 48 |
$tableName = static::getTableName(); |
| 49 |
$charsetCollate = static::getCharsetCollate(); |
| 50 |
|
| 51 |
return <<<SQL |
| 52 |
CREATE TABLE IF NOT EXISTS `{$tableName}` ( |
| 53 |
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| 54 |
`trip_id` bigint(20) unsigned NOT NULL, |
| 55 |
`content_type` enum('image','video','youtube','virtual_tour','document','highlight','faq','download','testimonial', 'landmark') NOT NULL, |
| 56 |
`title` varchar(255) DEFAULT NULL, |
| 57 |
`description` text, |
| 58 |
`content_url` varchar(500) DEFAULT NULL, |
| 59 |
`file_path` varchar(500) DEFAULT NULL, |
| 60 |
`file_size` bigint(20) unsigned DEFAULT NULL, |
| 61 |
`file_type` varchar(50) DEFAULT NULL, |
| 62 |
`thumbnail_url` varchar(500) DEFAULT NULL, |
| 63 |
`metadata` longtext COMMENT 'JSON: Type-specific metadata (image dimensions, FAQ answer, download permissions, etc.)', |
| 64 |
`display_options` longtext COMMENT 'JSON: Display configuration, layout options, etc.', |
| 65 |
`sort_order` smallint(5) unsigned DEFAULT 0, |
| 66 |
`is_featured` tinyint(1) DEFAULT 0, |
| 67 |
`is_downloadable` tinyint(1) DEFAULT 0, |
| 68 |
`is_public` tinyint(1) DEFAULT 1, |
| 69 |
`requires_login` tinyint(1) DEFAULT 0, |
| 70 |
`access_level` enum('public','registered','customer','premium') DEFAULT 'public', |
| 71 |
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| 72 |
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| 73 |
`created_by` bigint(20) unsigned DEFAULT NULL COMMENT 'User ID who created this record', |
| 74 |
`updated_by` bigint(20) unsigned DEFAULT NULL COMMENT 'User ID who last updated this record', |
| 75 |
|
| 76 |
PRIMARY KEY (`id`), |
| 77 |
KEY `idx_trip_content_type` (`trip_id`, `content_type`), |
| 78 |
KEY `content_type` (`content_type`), |
| 79 |
KEY `is_featured` (`is_featured`), |
| 80 |
KEY `is_downloadable` (`is_downloadable`), |
| 81 |
KEY `is_public` (`is_public`), |
| 82 |
KEY `access_level` (`access_level`), |
| 83 |
KEY `sort_order` (`sort_order`), |
| 84 |
KEY `created_at` (`created_at`), |
| 85 |
FULLTEXT KEY `search_content` (`title`, `description`) |
| 86 |
) {$charsetCollate} COMMENT='Unified trip content management system'; |
| 87 |
SQL; |
| 88 |
} |
| 89 |
} |
| 90 |
|