PluginProbe
Booking Calendar / 11.2
Booking Calendar v11.2
11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 10.11.2 All 203 releases
booking / includes / elementor-booking-form / controls / elementor_resource_selection.php

elementor_resource_selection.php in Booking Calendar 11.2, at includes/elementor-booking-form/controls/elementor_resource_selection.php

141 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Elementor WPBC_Elementor_Booking_Resource_Selection_Control control.
5 *
6 * A control for displaying a select field with the ability to choose booking_resources.
7 *
8 * @since 1.0.0
9 */
10 class WPBC_Elementor_Booking_Resource_Selection_Control extends \Elementor\Base_Data_Control {
11
12 /**
13 * Get resource control type.
14 *
15 * Retrieve the control type, in this case `resource`.
16 *
17 * @since 1.0.0
18 * @access public
19 * @return string Control type.
20 */
21 public function get_type(): string {
22 return 'wpbc_resource_selection';
23 }
24
25 /**
26 * Get booking_resources.
27 *
28 * Retrieve all the available booking_resources.
29 *
30 * @since 1.0.0
31 * @access public
32 * @static
33 * @return array Available booking_resources.
34 */
35 public static function get_booking_resources(): array {
36
37 $resources_arr = wpbc_ajx_get_all_booking_resources_arr();
38 $resources_arr_sorted = wpbc_ajx_get_sorted_booking_resources_arr( $resources_arr );
39
40 foreach ( $resources_arr_sorted as $resource_index => $br ) {
41
42 $br_option_title = $br['title'];
43
44 if ( ( isset( $br['parent'] ) ) && ( $br['parent'] == 0 ) && ( isset( $br['count'] ) ) && ( $br['count'] > 1 ) ) {
45 $br_option_title .= ' [' . __( 'parent resource', 'booking' ) . ']';
46 }
47
48 // == CSS ==
49 $resources_arr_sorted[ $resource_index ]['css_class'] = 'wpbc_single_resource';
50 if ( isset( $br['parent'] ) ) {
51 if ( $br['parent'] == 0 ) {
52 if ( ( isset( $br['count'] ) ) && ( $br['count'] > 1 ) ) {
53 $resources_arr_sorted[ $resource_index ]['css_class'] = 'wpbc_parent_resource';
54 }
55 } else {
56 $resources_arr_sorted[ $resource_index ]['css_class'] = 'wpbc_child_resource';
57 }
58 }
59
60 if ( 'wpbc_child_resource' === $resources_arr_sorted[ $resource_index ]['css_class'] ) {
61 $br_option_title = ' &nbsp;&nbsp;&nbsp; ' . $br_option_title;
62 }
63
64 $resources_arr_sorted[ $resource_index ]['title'] = $br_option_title;
65 }
66 return $resources_arr_sorted;
67 }
68
69 /**
70 * Get resource control default settings.
71 *
72 * Retrieve the default settings of the resource control. Used to return
73 * the default settings while initializing the resource control.
74 *
75 * @since 1.0.0
76 * @access protected
77 * @return array Currency control default settings.
78 */
79 protected function get_default_settings(): array {
80 return [
81 'booking_resources' => self::get_booking_resources()
82 ];
83 }
84
85 /**
86 * Get resource control default value.
87 *
88 * Retrieve the default value of the resource control. Used to return the
89 * default value while initializing the control.
90 *
91 * @since 1.0.0
92 * @access public
93 * @return array Currency control default value.
94 */
95 public function get_default_value(): string {
96
97 $booking_resources_arr = self::get_booking_resources();
98
99 foreach ( $booking_resources_arr as $index => $resource_arr ) {
100 return $resource_arr['booking_type_id'];
101 }
102 return '1';
103 }
104
105
106 /**
107 * Render resource control output in the editor.
108 *
109 * Used to generate the control HTML in the editor using Underscore JS
110 * template. The variables for the class are available using `data` JS
111 * object.
112 *
113 * @since 1.0.0
114 * @access public
115 */
116 public function content_template(): void {
117 $control_uid = $this->get_control_uid();
118 ?>
119 <div class="elementor-control-field elementor-control-type-select">
120
121 <# if ( data.label ) {#>
122 <label for="<?php echo esc_attr( $control_uid ); ?>" class="elementor-control-title">{{{ data.label }}}</label>
123 <# } #>
124
125 <div class="elementor-control-input-wrapper">
126 <select id="<?php echo esc_attr( $control_uid ); ?>" data-setting="{{ data.name }}">
127 <# _.each( data.booking_resources, function( resource_arr, resource_index ) { #>
128 <option value="{{ resource_arr.booking_type_id }}" class="{{ resource_arr.css_class }}">{{{ resource_arr.title }}}</option>
129 <# } ); #>
130 </select>
131 </div>
132
133 </div>
134 <# if ( data.description ) { #>
135 <div class="elementor-control-field-description">{{{ data.description }}}</div>
136 <# } #>
137 <?php
138 }
139
140 }
141