ameliabooking
/
src
/
Infrastructure
/
WP
/
InstallActions
/
DB
/
Notification
/
NotificationsTable.php
NotificationsLogTable.php
1 month ago
NotificationsSMSHistoryTable.php
2 months ago
NotificationsTable.php
2 months ago
NotificationsTableInsertRows.php
6 months ago
NotificationsToEntitiesTable.php
2 months ago
NotificationsTable.php
67 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaBooking\Infrastructure\WP\InstallActions\DB\Notification; |
| 4 | |
| 5 | use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException; |
| 6 | use AmeliaBooking\Domain\ValueObjects\String\Name; |
| 7 | use AmeliaBooking\Domain\ValueObjects\String\NotificationSendTo; |
| 8 | use AmeliaBooking\Domain\ValueObjects\String\NotificationType; |
| 9 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\AbstractDatabaseTable; |
| 10 | |
| 11 | /** |
| 12 | * Class NotificationsTable |
| 13 | * |
| 14 | * @package AmeliaBooking\Infrastructure\WP\InstallActions\DB\Notification |
| 15 | */ |
| 16 | class NotificationsTable extends AbstractDatabaseTable |
| 17 | { |
| 18 | public const TABLE = 'notifications'; |
| 19 | |
| 20 | /** |
| 21 | * @return string |
| 22 | * @throws InvalidArgumentException |
| 23 | */ |
| 24 | public static function buildTable() |
| 25 | { |
| 26 | global $wpdb; |
| 27 | |
| 28 | $table = self::getTableName(); |
| 29 | |
| 30 | $charsetCollate = self::getCharsetCollate(); |
| 31 | |
| 32 | $name = Name::MAX_LENGTH; |
| 33 | $typeEmail = NotificationType::EMAIL; |
| 34 | $typeSms = NotificationType::SMS; |
| 35 | $typeWhatsApp = NotificationType::WHATSAPP; |
| 36 | $sendToCustomer = NotificationSendTo::CUSTOMER; |
| 37 | $sendToProvider = NotificationSendTo::PROVIDER; |
| 38 | |
| 39 | if ( |
| 40 | $wpdb->get_var("SHOW TABLES LIKE '{$table}'") === $table && |
| 41 | $wpdb->query("SHOW KEYS FROM {$table} WHERE Key_name = 'name'") |
| 42 | ) { |
| 43 | $wpdb->query("ALTER TABLE {$table} DROP INDEX name"); |
| 44 | } |
| 45 | |
| 46 | return "CREATE TABLE {$table} ( |
| 47 | `id` INT(11) NOT NULL AUTO_INCREMENT, |
| 48 | `name` VARCHAR({$name}) NOT NULL DEFAULT '', |
| 49 | `customName` VARCHAR(255) DEFAULT NULL, |
| 50 | `status` ENUM('enabled', 'disabled') NOT NULL DEFAULT 'enabled', |
| 51 | `type` ENUM('{$typeEmail}', '{$typeSms}', '{$typeWhatsApp}') NOT NULL, |
| 52 | `entity` ENUM('appointment', 'event') NOT NULL DEFAULT 'appointment', |
| 53 | `time` TIME NULL DEFAULT NULL, |
| 54 | `timeBefore` INT(11) NULL DEFAULT NULL, |
| 55 | `timeAfter` INT(11) NULL DEFAULT NULL, |
| 56 | `sendTo` ENUM('{$sendToCustomer}', '{$sendToProvider}') NOT NULL, |
| 57 | `subject` VARCHAR(255) NOT NULL DEFAULT '', |
| 58 | `content` TEXT NULL, |
| 59 | `translations` TEXT NULL DEFAULT NULL, |
| 60 | `sendOnlyMe` TINYINT(1) DEFAULT 0, |
| 61 | `whatsAppTemplate` VARCHAR(255) NULL DEFAULT NULL, |
| 62 | `minimumTimeBeforeBooking` TEXT NULL DEFAULT NULL, |
| 63 | PRIMARY KEY (`id`) |
| 64 | ) {$charsetCollate};"; |
| 65 | } |
| 66 | } |
| 67 |