ameliabooking
/
src
/
Infrastructure
/
WP
/
InstallActions
/
DB
/
Notification
/
NotificationsTable.php
NotificationsLogTable.php
4 years ago
NotificationsSMSHistoryTable.php
4 years ago
NotificationsTable.php
2 years ago
NotificationsTableInsertRows.php
1 year ago
NotificationsToEntitiesTable.php
4 years ago
NotificationsTable.php
65 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 | |
| 19 | const TABLE = 'notifications'; |
| 20 | |
| 21 | /** |
| 22 | * @return string |
| 23 | * @throws InvalidArgumentException |
| 24 | */ |
| 25 | public static function buildTable() |
| 26 | { |
| 27 | global $wpdb; |
| 28 | |
| 29 | $table = self::getTableName(); |
| 30 | |
| 31 | $name = Name::MAX_LENGTH; |
| 32 | $typeEmail = NotificationType::EMAIL; |
| 33 | $typeSms = NotificationType::SMS; |
| 34 | $typeWhatsApp = NotificationType::WHATSAPP; |
| 35 | $sendToCustomer = NotificationSendTo::CUSTOMER; |
| 36 | $sendToProvider = NotificationSendTo::PROVIDER; |
| 37 | |
| 38 | if ($wpdb->get_var("SHOW TABLES LIKE '{$table}'") === $table && |
| 39 | $wpdb->query("SHOW KEYS FROM {$table} WHERE Key_name = 'name'") |
| 40 | ) { |
| 41 | $wpdb->query("ALTER TABLE {$table} DROP INDEX name"); |
| 42 | } |
| 43 | |
| 44 | return "CREATE TABLE {$table} ( |
| 45 | `id` INT(11) NOT NULL AUTO_INCREMENT, |
| 46 | `name` VARCHAR({$name}) NOT NULL DEFAULT '', |
| 47 | `customName` VARCHAR(255) DEFAULT NULL, |
| 48 | `status` ENUM('enabled', 'disabled') NOT NULL DEFAULT 'enabled', |
| 49 | `type` ENUM('{$typeEmail}', '{$typeSms}', '{$typeWhatsApp}') NOT NULL, |
| 50 | `entity` ENUM('appointment', 'event') NOT NULL DEFAULT 'appointment', |
| 51 | `time` TIME NULL DEFAULT NULL, |
| 52 | `timeBefore` INT(11) NULL DEFAULT NULL, |
| 53 | `timeAfter` INT(11) NULL DEFAULT NULL, |
| 54 | `sendTo` ENUM('{$sendToCustomer}', '{$sendToProvider}') NOT NULL, |
| 55 | `subject` VARCHAR(255) NOT NULL DEFAULT '', |
| 56 | `content` TEXT NULL, |
| 57 | `translations` TEXT NULL DEFAULT NULL, |
| 58 | `sendOnlyMe` TINYINT(1) DEFAULT 0, |
| 59 | `whatsAppTemplate` VARCHAR(255) NULL DEFAULT NULL, |
| 60 | `minimumTimeBeforeBooking` TEXT NULL DEFAULT NULL, |
| 61 | PRIMARY KEY (`id`) |
| 62 | ) DEFAULT CHARSET=utf8 COLLATE utf8_general_ci"; |
| 63 | } |
| 64 | } |
| 65 |