getMessageKeys(); foreach($keys as $key) { // Structure for each message type: // - enable: whether the message is active // - templates: array keyed by language code, each containing: // - template_sid: the selected WhatsApp template SID // - template_name: the template name (for display) // - field_mapping: array mapping template variables to booking fields $list[$key.'_enable'] = 0; $list[$key] = []; // Will hold per-language configuration } return $list; } /** * List of items to navigate (sidebar) * * @return array[] */ /** * List of items to navigate (sidebar) * * @return array[] */ public function listItems() { return [ [ 'label' => __eva('Booking pending (Guest)'), 'slug' => 'booking_pending', 'is_enabled' => (bool) $this->booking_pending_enable, ], [ 'label' => __eva('Booking pending payment (Guest)'), 'slug' => 'booking_pending_payment', 'is_enabled' => (bool) $this->booking_pending_payment_enable, ], [ 'label' => __eva('Booking confirmed (Guest)'), 'slug' => 'booking_booked', 'is_enabled' => (bool) $this->booking_booked_enable, ], /*[ 'label' => __eva('Booking modified (Guest)'), 'slug' => 'booking_modified', 'is_enabled' => (bool) $this->booking_modified_enable, ],*/ [ 'label' => __eva('User re-confirmed (Guest)'), 'slug' => 'booking_confirmed', 'is_enabled' => (bool) $this->booking_confirmed_enable, ], [ 'label' => __eva('Booking denied (Guest)'), 'slug' => 'booking_denied', 'is_enabled' => (bool) $this->booking_denied_enable, ], [ 'label' => __eva('Booking cancelled (Guest)'), 'slug' => 'booking_cancelled', 'is_enabled' => (bool) $this->booking_cancelled_enable, ], [ 'label' => __eva('Booking no show (Guest)'), 'slug' => 'booking_no_show', 'is_enabled' => (bool) $this->booking_no_show_enable, ], [ 'label' => __eva('Booking finished (Guest)'), 'slug' => 'booking_finished', 'is_enabled' => (bool) $this->booking_finished_enable, ], [ 'label' => __eva('Menu pending to fill (Guest)'), 'slug' => 'menu_pending', 'is_enabled' => (bool) $this->menu_pending_enable, ], /*[ 'label' => __eva('Received pending (Admin)'), 'slug' => 'booking_pending_admin', 'is_enabled' => (bool) $this->booking_pending_admin_enable, ], [ 'label' => __eva('Received confirmed (Admin)'), 'slug' => 'booking_booked_admin', 'is_enabled' => (bool) $this->booking_booked_admin_enable, ], [ 'label' => __eva('Received User re-confirmed (Admin)'), 'slug' => 'booking_confirmed_admin', 'is_enabled' => (bool) $this->booking_confirmed_admin_enable, ], [ 'label' => __eva('Received cancelled (Admin)'), 'slug' => 'booking_cancelled_admin', 'is_enabled' => (bool) $this->booking_cancelled_admin_enable, ],*/ ]; } /** * Fields for the admin editor * * @return array */ public function fields() { $keys = [ 'booking_pending' => [ __eva('Booking Pending'), __eva('WhatsApp message sent to the guest when the reservation is pending confirmation.') ], 'booking_pending_payment' => [ __eva('Booking Pending Payment'), __eva('WhatsApp message sent to the guest when the reservation is pending payment.') ], 'booking_booked' => [ __eva('Booking Confirmed'), __eva('WhatsApp message sent to the guest when the reservation has been confirmed.') ], /*'booking_modified' => [ __eva('Booking Modified'), __eva('WhatsApp message sent to the guest when the reservation has been modified.') ],*/ 'booking_confirmed' => [ __eva('Booking Re-confirmed'), __eva('WhatsApp message sent to the guest when they have re-confirmed the reservation.') ], 'booking_denied' => [ __eva('Booking Denied'), __eva('WhatsApp message sent to the guest when the reservation has been denied.') ], 'booking_cancelled' => [ __eva('Booking Cancelled'), __eva('WhatsApp message sent to the guest when the reservation has been cancelled.') ], 'booking_no_show' => [ __eva('Booking No-Show'), __eva('WhatsApp message sent to the guest when marked as no-show.') ], 'booking_finished' => [ __eva('Booking Finished'), __eva('WhatsApp message sent to the guest after the reservation is completed.') ], 'menu_pending' => [ __eva('Menu pending to fill'), __eva('WhatsApp message sent to the guest when they still have to select the menu after booking. Map a variable to {mybooking} for the link.') ], /*'booking_pending_admin' => [ __eva('Booking Pending (Admin)'), __eva('WhatsApp message sent to the admin when a new pending reservation is received.') ], 'booking_booked_admin' => [ __eva('Booking Confirmed (Admin)'), __eva('WhatsApp message sent to the admin when a reservation is confirmed.') ], 'booking_confirmed_admin' => [ __eva('Booking Re-confirmed (Admin)'), __eva('WhatsApp message sent to the admin when a guest re-confirms.') ], 'booking_cancelled_admin' => [ __eva('Booking Cancelled (Admin)'), __eva('WhatsApp message sent to the admin when a reservation is cancelled.') ],*/ ]; $list = []; foreach ($keys as $key => $labels) { $isAdmin = strpos($key, '_admin') !== false; $fields = [ [ 'attribute' => $key.'_enable', 'stacked' => true, 'name' => __eva('Active'), 'helpText' => __eva('Activate this WhatsApp message.'), 'component' => 'boolean-field', 'type' => 'switch', 'value' => $this->{$key.'_enable'}, ], ]; // Add admin phone field for admin messages if ($isAdmin) { $fields[] = [ 'attribute' => $key.'_phone', 'stacked' => true, 'name' => __eva('Phone number that will receive this notification'), 'component' => 'text-field', 'helpText' => __eva('Enter the WhatsApp phone number with country code (e.g., +34612345678).'), 'value' => $this->{$key.'_phone'} ?? '' ]; } // Main WhatsApp template selector field $fields[] = [ 'attribute' => $key, 'stacked' => true, 'name' => $labels[0], 'component' => 'group-whatsapp-template-field', 'value' => $this->valueWithLanguagesFor($key), 'helpText' => $labels[1], 'bookingFields' => self::getBookingFields(), 'isAdmin' => $isAdmin, ]; $list[$key] = $fields; } return $list; } /** * Get value with languages for a specific message type * * @param string $key * @return array */ public function valueWithLanguagesFor($key) { $languages = evavel_languages_allowed(); $value = $this->{$key}; if (!is_array($value)) { $value = []; } // Ensure all languages have a configuration foreach ($languages as $lang => $label) { if (!isset($value[$lang])) { $value[$lang] = [ 'template_sid' => '', 'template_name' => '', 'field_mapping' => [], ]; } } return $value; } /** * Get configured template for a specific message type and language * * @param string $messageType * @param string $language * @return array|null */ public function getTemplateConfig($messageType, $language) { $config = $this->{$messageType}; if (!is_array($config) || !isset($config[$language])) { return null; } return $config[$language]; } /** * Check if a message type is enabled * * @param string $messageType * @return bool */ public function isEnabled($messageType) { return (bool) $this->{$messageType.'_enable'}; } /** * Get the admin phone for admin messages * * @param string $messageType * @return string|null */ public function getAdminPhone($messageType) { if (strpos($messageType, '_admin') === false) { return null; } return $this->{$messageType.'_phone'} ?? null; } }