update
This commit is contained in:
@@ -0,0 +1,282 @@
|
||||
<?php
|
||||
/**
|
||||
* Yacht Calendar (All) Widget for Elementor
|
||||
*
|
||||
* Wspólny kalendarz pokazujący rezerwacje WSZYSTKICH publikowanych jachtów + globalne
|
||||
* wydarzenia (sync_mode=global). Read-only, kolory per-jacht z auto palety, half-day
|
||||
* przez timed events 12:00 → 12:00.
|
||||
*
|
||||
* @package YachtBooking
|
||||
*/
|
||||
|
||||
namespace YachtBooking;
|
||||
|
||||
// Exit if accessed directly
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
use Elementor\Controls_Manager;
|
||||
use Elementor\Widget_Base;
|
||||
|
||||
/**
|
||||
* Yacht Calendar (All) Widget Class
|
||||
*/
|
||||
class Calendar_Widget_All extends Widget_Base {
|
||||
|
||||
/**
|
||||
* Widget name (Elementor identifier).
|
||||
*/
|
||||
public function get_name() {
|
||||
return 'yacht-calendar-all';
|
||||
}
|
||||
|
||||
/**
|
||||
* Widget title.
|
||||
*/
|
||||
public function get_title() {
|
||||
return esc_html__( 'Kalendarz Jachtów (wszystkie)', 'yacht-booking' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Widget icon.
|
||||
*/
|
||||
public function get_icon() {
|
||||
return 'eicon-calendar';
|
||||
}
|
||||
|
||||
/**
|
||||
* Widget categories.
|
||||
*/
|
||||
public function get_categories() {
|
||||
return array( 'basic' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Widget keywords.
|
||||
*/
|
||||
public function get_keywords() {
|
||||
return array( 'yacht', 'calendar', 'wszystkie', 'flota', 'kalendarz', 'rezerwacje' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register widget controls.
|
||||
*/
|
||||
protected function register_controls() {
|
||||
$this->start_controls_section(
|
||||
'content_section',
|
||||
array(
|
||||
'label' => esc_html__( 'Ustawienia Kalendarza', 'yacht-booking' ),
|
||||
'tab' => Controls_Manager::TAB_CONTENT,
|
||||
)
|
||||
);
|
||||
|
||||
$this->add_control(
|
||||
'calendar_height',
|
||||
array(
|
||||
'label' => esc_html__( 'Wysokość kalendarza', 'yacht-booking' ),
|
||||
'type' => Controls_Manager::SLIDER,
|
||||
'range' => array(
|
||||
'px' => array(
|
||||
'min' => 400,
|
||||
'max' => 1000,
|
||||
),
|
||||
),
|
||||
'default' => array(
|
||||
'size' => 650,
|
||||
'unit' => 'px',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$this->add_control(
|
||||
'show_legend',
|
||||
array(
|
||||
'label' => esc_html__( 'Pokaż legendę kolorów', 'yacht-booking' ),
|
||||
'type' => Controls_Manager::SWITCHER,
|
||||
'label_on' => esc_html__( 'Tak', 'yacht-booking' ),
|
||||
'label_off' => esc_html__( 'Nie', 'yacht-booking' ),
|
||||
'return_value' => 'yes',
|
||||
'default' => 'yes',
|
||||
)
|
||||
);
|
||||
|
||||
$this->end_controls_section();
|
||||
}
|
||||
|
||||
/**
|
||||
* Render widget output.
|
||||
*/
|
||||
protected function render() {
|
||||
$settings = $this->get_settings_for_display();
|
||||
$height = ! empty( $settings['calendar_height']['size'] ) ? (int) $settings['calendar_height']['size'] : 650;
|
||||
$show_legend = ! isset( $settings['show_legend'] ) || 'yes' === $settings['show_legend'];
|
||||
$dom_id = 'yacht-calendar-all-' . $this->get_id();
|
||||
|
||||
echo Calendar_All_View::render( $dom_id, $height, $show_legend ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pomocnicza klasa renderująca markup widgetu i shortcode.
|
||||
*
|
||||
* Wspólna dla widgetu Elementor i shortcode `[yacht_calendar_all]` żeby uniknąć duplikacji.
|
||||
*/
|
||||
class Calendar_All_View {
|
||||
|
||||
/**
|
||||
* Render markup wspólnego kalendarza.
|
||||
*
|
||||
* @param string $dom_id Unikalny ID kontenera FullCalendar.
|
||||
* @param int $height Wysokość kalendarza w px.
|
||||
* @param bool $show_legend Czy renderować legendę.
|
||||
* @return string HTML.
|
||||
*/
|
||||
public static function render( $dom_id, $height = 650, $show_legend = true ) {
|
||||
$rest_url = esc_url_raw( rest_url( 'yacht-booking/v1/availability/all' ) );
|
||||
|
||||
// Yachts for legend + form select.
|
||||
$yacht_posts = get_posts(
|
||||
array(
|
||||
'post_type' => 'yacht',
|
||||
'post_status' => 'publish',
|
||||
'posts_per_page' => -1,
|
||||
'orderby' => 'ID',
|
||||
'order' => 'ASC',
|
||||
)
|
||||
);
|
||||
$yacht_ids = wp_list_pluck( $yacht_posts, 'ID' );
|
||||
$color_map = \YachtBooking\Rest_Controller::get_yacht_color_palette( $yacht_ids );
|
||||
$global_color = \YachtBooking\Rest_Controller::GLOBAL_EVENT_COLOR;
|
||||
$sync_mode = \YachtBooking\Settings::get_ical_sync_mode();
|
||||
$terms_url = \YachtBooking\Settings::get_terms_page_url();
|
||||
$form_uid = preg_replace( '/[^a-z0-9_-]/i', '', $dom_id );
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
<div class="yacht-calendar-all-wrapper"
|
||||
data-rest="<?php echo esc_attr( $rest_url ); ?>"
|
||||
data-show-legend="<?php echo $show_legend ? '1' : '0'; ?>"
|
||||
data-height="<?php echo esc_attr( (int) $height ); ?>">
|
||||
|
||||
<div class="yacht-calendar-instructions">
|
||||
<p>
|
||||
<?php esc_html_e( 'Aby zarezerwować termin, wypełnij formularz po prawej stronie albo skontaktuj się z nami telefonicznie lub mailowo.', 'yacht-booking' ); ?>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<?php if ( $show_legend ) : ?>
|
||||
<div class="yacht-calendar-legend yacht-calendar-all-legend" aria-label="<?php esc_attr_e( 'Legenda kalendarza', 'yacht-booking' ); ?>">
|
||||
<?php if ( 'global' === $sync_mode ) : ?>
|
||||
<span class="yacht-legend-item">
|
||||
<span class="yacht-legend-swatch" style="background-color: <?php echo esc_attr( $global_color ); ?>;"></span>
|
||||
<?php esc_html_e( 'Rezerwacja', 'yacht-booking' ); ?>
|
||||
</span>
|
||||
<?php else : ?>
|
||||
<?php foreach ( $yacht_posts as $yacht ) : ?>
|
||||
<?php $color = isset( $color_map[ $yacht->ID ] ) ? $color_map[ $yacht->ID ] : $global_color; ?>
|
||||
<span class="yacht-legend-item">
|
||||
<span class="yacht-legend-swatch" style="background-color: <?php echo esc_attr( $color ); ?>;"></span>
|
||||
<?php echo esc_html( $yacht->post_title ); ?>
|
||||
</span>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="yacht-inquiry-layout yacht-calendar-all-layout">
|
||||
<div class="yacht-inquiry-calendar-col">
|
||||
<div id="<?php echo esc_attr( $dom_id ); ?>"
|
||||
class="yacht-calendar yacht-calendar-all"
|
||||
style="height: <?php echo esc_attr( $height ); ?>px;"></div>
|
||||
</div>
|
||||
|
||||
<div class="yacht-inquiry-form-col">
|
||||
<div class="yacht-inquiry-form-container">
|
||||
<h4><?php esc_html_e( 'Zapytaj o rezerwację', 'yacht-booking' ); ?></h4>
|
||||
<p class="yacht-inquiry-desc">
|
||||
<?php esc_html_e( 'Wybierz jacht i wypełnij formularz — odezwiemy się w sprawie dostępności i cen.', 'yacht-booking' ); ?>
|
||||
</p>
|
||||
<form class="yacht-inquiry-form yacht-calendar-all-inquiry-form">
|
||||
<?php wp_nonce_field( 'yacht_inquiry_submit', 'yacht_inquiry_nonce' ); ?>
|
||||
|
||||
<div class="form-field">
|
||||
<label for="all_inquiry_yacht_<?php echo esc_attr( $form_uid ); ?>">
|
||||
<?php esc_html_e( 'Jacht', 'yacht-booking' ); ?> <span class="required">*</span>
|
||||
</label>
|
||||
<select id="all_inquiry_yacht_<?php echo esc_attr( $form_uid ); ?>" name="yacht_id" required>
|
||||
<option value=""><?php esc_html_e( '— wybierz jacht —', 'yacht-booking' ); ?></option>
|
||||
<?php foreach ( $yacht_posts as $yacht ) : ?>
|
||||
<option value="<?php echo esc_attr( $yacht->ID ); ?>"><?php echo esc_html( $yacht->post_title ); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-field">
|
||||
<label for="all_inquiry_name_<?php echo esc_attr( $form_uid ); ?>">
|
||||
<?php esc_html_e( 'Imię i nazwisko', 'yacht-booking' ); ?> <span class="required">*</span>
|
||||
</label>
|
||||
<input type="text" id="all_inquiry_name_<?php echo esc_attr( $form_uid ); ?>" name="customer_name" required>
|
||||
</div>
|
||||
|
||||
<div class="form-field">
|
||||
<label for="all_inquiry_email_<?php echo esc_attr( $form_uid ); ?>">
|
||||
<?php esc_html_e( 'Email', 'yacht-booking' ); ?> <span class="required">*</span>
|
||||
</label>
|
||||
<input type="email" id="all_inquiry_email_<?php echo esc_attr( $form_uid ); ?>" name="customer_email" required>
|
||||
</div>
|
||||
|
||||
<div class="form-field">
|
||||
<label for="all_inquiry_phone_<?php echo esc_attr( $form_uid ); ?>">
|
||||
<?php esc_html_e( 'Telefon', 'yacht-booking' ); ?> <span class="required">*</span>
|
||||
</label>
|
||||
<input type="tel" id="all_inquiry_phone_<?php echo esc_attr( $form_uid ); ?>" name="customer_phone" required>
|
||||
</div>
|
||||
|
||||
<div class="form-field">
|
||||
<label for="all_inquiry_dates_<?php echo esc_attr( $form_uid ); ?>">
|
||||
<?php esc_html_e( 'Preferowane terminy', 'yacht-booking' ); ?>
|
||||
</label>
|
||||
<input type="text"
|
||||
id="all_inquiry_dates_<?php echo esc_attr( $form_uid ); ?>"
|
||||
name="preferred_dates"
|
||||
placeholder="<?php esc_attr_e( 'np. 15-22 lipca', 'yacht-booking' ); ?>">
|
||||
</div>
|
||||
|
||||
<div class="form-field">
|
||||
<label for="all_inquiry_message_<?php echo esc_attr( $form_uid ); ?>">
|
||||
<?php esc_html_e( 'Wiadomość', 'yacht-booking' ); ?>
|
||||
</label>
|
||||
<textarea id="all_inquiry_message_<?php echo esc_attr( $form_uid ); ?>"
|
||||
name="message"
|
||||
rows="3"
|
||||
placeholder="<?php esc_attr_e( 'Dodatkowe pytania lub uwagi...', 'yacht-booking' ); ?>"></textarea>
|
||||
</div>
|
||||
|
||||
<?php if ( $terms_url ) : ?>
|
||||
<p class="booking-terms">
|
||||
<?php
|
||||
printf(
|
||||
wp_kses_post( __( 'Wysyłając formularz akceptujesz %s.', 'yacht-booking' ) ),
|
||||
'<a href="' . esc_url( $terms_url ) . '" target="_blank" rel="noopener">' . esc_html__( 'regulamin', 'yacht-booking' ) . '</a>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="form-actions">
|
||||
<button type="submit" class="yacht-booking-submit">
|
||||
<?php esc_html_e( 'Wyślij zapytanie', 'yacht-booking' ); ?>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="yacht-inquiry-response yacht-calendar-all-inquiry-response"></div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
return ob_get_clean();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user