PluginProbe
Booking Calendar / 11.4
Booking Calendar v11.4
11.9 11.8.4 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 All 205 releases
booking / includes / page-bookings / booking_action / set_unavailable_times.php

set_unavailable_times.php in Booking Calendar 11.4, at includes/page-bookings/booking_action/set_unavailable_times.php

196 lines 6.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Set unavailable times from the Booking Listing action menu.
4 *
5 * @package Booking Calendar
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit, if accessed directly.
10 }
11
12 /**
13 * Class WPBC_Action_Set_Unavailable_Times
14 */
15 class WPBC_Action_Set_Unavailable_Times {
16
17 const ACTION = 'set_unavailable_times';
18
19 /**
20 * Check whether current user can manage time-slot availability.
21 *
22 * @return bool
23 */
24 public static function is_action_available() {
25
26 if ( function_exists( 'wpbc_availability_timeslots__get_manage_cap' ) ) {
27 return current_user_can( wpbc_availability_timeslots__get_manage_cap() );
28 }
29
30 return current_user_can( 'manage_options' );
31 }
32
33 /**
34 * Get action button for the booking row menu.
35 *
36 * @return false|string
37 */
38 public static function get_button() {
39
40 if (
41 ( ! function_exists( 'wpbc_availability_timeslots__render_timeline_component' ) )
42 || ( ! self::is_action_available() )
43 ) {
44 return false;
45 }
46
47 $html = "<a class='ul_dropdown_menu_li_action ul_dropdown_menu_li_action_" . esc_js( self::ACTION ) . "'
48 href=\"javascript:void(0)\"
49 onclick=\"wpbc_boo_listing__click__set_unavailable_times(
50 {{data['parsed_fields']['booking_id']}},
51 {{data['parsed_fields']['resource_id']}},
52 '{{data['short_dates'][0]}}',
53 '{{data['short_dates'][ data['short_dates'].length > 2 ? ( data['short_dates'].length - 1 ) : 0 ]}}'
54 );\"
55 >" .
56 esc_js( __( 'Set unavailable times', 'booking' ) ) .
57 "<i class='menu_icon icon-1x wpbc_icn_do_not_disturb_on'></i>" .
58 '</a>';
59
60 return $html;
61 }
62
63 /**
64 * Print top toolbar button for opening the availability popup without booking context.
65 *
66 * @param string $page_tag Current page tag.
67 * @param string $active_page_tab Current tab.
68 * @param string $active_page_subtab Current subtab.
69 *
70 * @return false|void
71 */
72 public static function print_top_toolbar_button( $page_tag, $active_page_tab, $active_page_subtab ) {
73
74 if ( ( 'wpbc' !== $page_tag ) || ( 'vm_booking_listing' !== $active_page_tab ) ) {
75 return false;
76 }
77
78 if (
79 ( ! function_exists( 'wpbc_availability_timeslots__render_timeline_component' ) )
80 || ( ! self::is_action_available() )
81 ) {
82 return false;
83 }
84
85 ?>
86 <div class="wpbc_ui_el__buttons_group wpbc_booking_listing__top_toolbar_group">
87 <a href="javascript:void(0);"
88 id="wpbc_booking_listing_set_unavailable_times_button"
89 class="button button-secondary"
90 onclick="wpbc_boo_listing__click__set_unavailable_times( '', '', '', '' );"
91 title="<?php esc_attr_e( 'Set times availability', 'booking' ); ?>">
92 <i class="menu_icon icon-1x wpbc-bi-clock-history"></i>&nbsp;
93 <?php esc_html_e( 'Set Times Availability', 'booking' ); ?>
94 </a>
95 </div>
96 <?php
97 }
98
99 /**
100 * Add action to Booking Listing dropdown.
101 *
102 * @param array $el_arr Dropdown configuration.
103 *
104 * @return array
105 */
106 public static function add_action_to_dropdown( $el_arr ) {
107
108 $button = self::get_button();
109 if ( false === $button ) {
110 return $el_arr;
111 }
112
113 $new_item = array( 'type' => 'html', 'html' => $button );
114 $insert_index = null;
115
116 foreach ( $el_arr['items'] as $index => $item ) {
117 if ( ( 'html' === $item['type'] ) && ( false !== strpos( $item['html'], 'ul_dropdown_menu_li_action_set_booking_locale' ) ) ) {
118 $insert_index = $index + 1;
119 break;
120 }
121 }
122
123 if ( null === $insert_index ) {
124 $el_arr['items'][] = $new_item;
125 return $el_arr;
126 }
127
128 array_splice( $el_arr['items'], $insert_index, 0, array( $new_item ) );
129
130 return $el_arr;
131 }
132
133 /**
134 * Get template for modal window.
135 *
136 * @return false|void
137 */
138 public static function template_for_modal() {
139
140 if (
141 ( ! function_exists( 'wpbc_availability_timeslots__render_timeline_component' ) )
142 || ( ! self::is_action_available() )
143 ) {
144 return false;
145 }
146
147 ?>
148 <span class="wpdevelop">
149 <div id="wpbc_modal__set_unavailable_times__section" class="modal wpbc_popup_modal wpbc_modal_in_listing wpbc_modal__availability_timeslots__section" tabindex="-1" role="dialog">
150 <div class="modal-dialog">
151 <div class="modal-content">
152 <div class="modal-header">
153 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
154 <h4 class="modal-title">
155 <?php esc_html_e( 'Set unavailable times', 'booking' ); ?>
156 <sup class="wpbc_modal__set_unavailable_times__booking_id wpbc_modal__booking_id__in_title"></sup>
157 </h4>
158 </div>
159 <div class="modal-body">
160 <?php
161 wpbc_availability_timeslots__render_timeline_component(
162 array(
163 'id_prefix' => 'wpbc_ts_listing_popup',
164 'wrap_class' => 'wpbc_ts_page wpbc_ts_popup',
165 'resource_id' => wpbc_get_default_resource(),
166 'days_count' => 7,
167 'show_hint' => false,
168 'show_legend' => true,
169 'auto_init' => false,
170 'show_toolbar_actions' => false,
171 )
172 );
173 ?>
174 </div>
175 <div class="modal-footer">
176 <a href="javascript:void(0)" class="button button-primary wpbc_ts_create_booking_button" data-wpbc-ts-create-booking="1">
177 <i class="menu_icon icon-1x wpbc-bi-calendar-plus"></i>&nbsp;
178 <?php esc_html_e( 'Create Booking for Selection', 'booking' ); ?>
179 </a>
180 <?php wpbc_availability_timeslots__render_action_buttons( 'wpbc_ts_action_buttons_inline wpbc_ts_footer_action_buttons' ); ?>
181 <a href="javascript:void(0)" class="button button-secondary" data-dismiss="modal">
182 <?php esc_html_e( 'Close', 'booking' ); ?>
183 </a>
184 </div>
185 </div><!-- /.modal-content -->
186 </div><!-- /.modal-dialog -->
187 </div><!-- /.modal -->
188 </span>
189 <?php
190 }
191 }
192
193 add_filter( 'wpbc_template__booking_listing__el__btn_action', array( 'WPBC_Action_Set_Unavailable_Times', 'add_action_to_dropdown' ) );
194 add_action( 'wpbc_hook_booking_template__hidden_templates', array( 'WPBC_Action_Set_Unavailable_Times', 'template_for_modal' ) );
195 add_action( 'wpbc_ui_el__top_nav__content_end', array( 'WPBC_Action_Set_Unavailable_Times', 'print_top_toolbar_button' ), 20, 3 );
196