| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Elementor WPBC_Elementor_Calendar_Skin_Selection_Control control. |
| 5 |
* |
| 6 |
* A control for displaying a select field with the ability to choose booking_calendar_skins. |
| 7 |
* |
| 8 |
* @since 1.0.0 |
| 9 |
*/ |
| 10 |
class WPBC_Elementor_Calendar_Skin_Selection_Control extends \Elementor\Base_Data_Control { |
| 11 |
|
| 12 |
/** |
| 13 |
* Get calendar_skin control type. |
| 14 |
* |
| 15 |
* Retrieve the control type, in this case `calendar_skin`. |
| 16 |
* |
| 17 |
* @since 1.0.0 |
| 18 |
* @access public |
| 19 |
* @return string Control type. |
| 20 |
*/ |
| 21 |
public function get_type(): string { |
| 22 |
return 'wpbc_calendar_skin_selection'; |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Get booking_calendar_skins. |
| 27 |
* |
| 28 |
* Retrieve all the available booking_calendar_skins. |
| 29 |
* |
| 30 |
* @return array Available booking_calendar_skins. |
| 31 |
* @since 1.0.0 |
| 32 |
* @access public |
| 33 |
* @static |
| 34 |
*/ |
| 35 |
public static function get_booking_calendar_skins(): array { |
| 36 |
|
| 37 |
$transformed_cal_arr = wpbc_get_calendar_skin_options_with_legacy_sections(); |
| 38 |
|
| 39 |
$sorted_options_list = array(); |
| 40 |
|
| 41 |
foreach ( $transformed_cal_arr as $cal_index => $cal_item ) { |
| 42 |
if ( is_array( $cal_item ) ) { |
| 43 |
if ( isset( $cal_item['optgroup'] ) ) { |
| 44 |
$sorted_options_list[] = $cal_item; |
| 45 |
} else { |
| 46 |
// Legacy skins with attributes: 'style=>'color:#ccc;' . |
| 47 |
$cal_item['url'] = $cal_index; |
| 48 |
$sorted_options_list[] = $cal_item; |
| 49 |
} |
| 50 |
} else { |
| 51 |
$sorted_options_list[] = array( |
| 52 |
'url' => $cal_index, |
| 53 |
'title' => $cal_item, |
| 54 |
); |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
return $sorted_options_list; |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Get calendar_skin control default settings. |
| 63 |
* |
| 64 |
* Retrieve the default settings of the calendar_skin control. Used to return |
| 65 |
* the default settings while initializing the calendar_skin control. |
| 66 |
* |
| 67 |
* @since 1.0.0 |
| 68 |
* @access protected |
| 69 |
* @return array Currency control default settings. |
| 70 |
*/ |
| 71 |
protected function get_default_settings(): array { |
| 72 |
return [ |
| 73 |
'booking_calendar_skins' => self::get_booking_calendar_skins(), |
| 74 |
'default' => wpbc_get_calendar_skin_url(), |
| 75 |
]; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
public function get_value( $control, $settings ) { |
| 80 |
$current_value = wpbc_get_calendar_skin_url(); // or default skin string. |
| 81 |
return $current_value; |
| 82 |
} |
| 83 |
|
| 84 |
public function get_default_value() { |
| 85 |
return wpbc_get_calendar_skin_url(); // fallback if no user value exists. |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Render calendar_skin control output in the editor. |
| 90 |
* |
| 91 |
* Used to generate the control HTML in the editor using Underscore JS |
| 92 |
* template. The variables for the class are available using `data` JS |
| 93 |
* object. |
| 94 |
* |
| 95 |
* @since 1.0.0 |
| 96 |
* @access public |
| 97 |
*/ |
| 98 |
public function content_template(): void { |
| 99 |
$control_uid = $this->get_control_uid(); |
| 100 |
?> |
| 101 |
<div class="elementor-control-field elementor-control-type-select"> |
| 102 |
|
| 103 |
<# if ( data.label ) {#> |
| 104 |
<label for="<?php echo esc_attr($control_uid); ?>" class="elementor-control-title">{{{ data.label }}}</label> |
| 105 |
<# } #> |
| 106 |
|
| 107 |
<div class="elementor-control-input-wrapper"> |
| 108 |
<select id="<?php echo esc_attr($control_uid); ?>" data-setting0="{{ data.name }}" onchange="javascript:document.getElementById('elementor-preview-iframe').contentWindow.wpbc__calendar__change_skin( jQuery( this ).val() );" > |
| 109 |
<# |
| 110 |
_.each( data.booking_calendar_skins, function( calendar_skin_arr, calendar_skin_index ) { |
| 111 |
if ( calendar_skin_arr['optgroup'] ) { // OPTGROUP |
| 112 |
|
| 113 |
if ( ! calendar_skin_arr['close'] ) { |
| 114 |
#><optgroup label="{{{calendar_skin_arr['title']}}}"><# |
| 115 |
} else { |
| 116 |
#></optgroup><# |
| 117 |
} |
| 118 |
|
| 119 |
} else { |
| 120 |
#><option value="{{ calendar_skin_arr['url'] }}" <# if (calendar_skin_arr['url'] === data.controlValue) { #>selected="selected"<# } #>>{{{ calendar_skin_arr['title'] }}}</option><# |
| 121 |
} |
| 122 |
} ); #> |
| 123 |
</select> |
| 124 |
</div> |
| 125 |
|
| 126 |
</div> |
| 127 |
|
| 128 |
<div class="elementor-control-field elementor-control-type-save-button"> |
| 129 |
<div class="elementor-button-wrapper"> |
| 130 |
<button class="elementor-button elementor-save-skin" type="button" id="elementor-save-skin-<?php echo esc_attr(wp_rand( 10, 1000000 )); ?>" processing_title="<?php esc_attr_e('Processing', 'booking'); ?>"> |
| 131 |
<!--i class="eicon-check" aria-hidden="true"></i--> |
| 132 |
<?php esc_html_e( 'Save Calendar Skin', 'booking' ); ?> |
| 133 |
</button> |
| 134 |
</div> |
| 135 |
</div> |
| 136 |
|
| 137 |
<# if ( data.description ) { #> |
| 138 |
<div class="elementor-control-field-description">{{{ data.description }}}</div> |
| 139 |
<# } #> |
| 140 |
<?php |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
|