PluginProbe
Booking Calendar / 11.7
Booking Calendar v11.7
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.7, at includes/page-bookings/booking_action/set_unavailable_times.php

206 lines 6.9 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 * Filter whether the Booking Listing availability toolbar button shows text.
87 *
88 * Presentation layers can request the compact icon-only variant without
89 * coupling this booking action controller to their runtime state.
90 *
91 * @param bool $show_button_text Whether to render the visible button text.
92 */
93 $show_button_text = (bool) apply_filters( 'wpbc_booking_listing_show_set_unavailable_times_button_text', true );
94
95 ?>
96 <div class="wpbc_ui_el__buttons_group wpbc_booking_listing__top_toolbar_group">
97 <a href="javascript:void(0);"
98 id="wpbc_booking_listing_set_unavailable_times_button"
99 class="button button-secondary"
100 onclick="wpbc_boo_listing__click__set_unavailable_times( '', '', '', '' );"
101 title="<?php esc_attr_e( 'Set times availability', 'booking' ); ?>"
102 aria-label="<?php esc_attr_e( 'Set times availability', 'booking' ); ?>">
103 <i class="menu_icon icon-1x wpbc-bi-clock-history" aria-hidden="true"></i><?php if ( $show_button_text ) : ?>&nbsp;
104 <?php esc_html_e( 'Set Times Availability', 'booking' ); ?><?php endif; ?>
105 </a>
106 </div>
107 <?php
108 }
109
110 /**
111 * Add action to Booking Listing dropdown.
112 *
113 * @param array $el_arr Dropdown configuration.
114 *
115 * @return array
116 */
117 public static function add_action_to_dropdown( $el_arr ) {
118
119 $button = self::get_button();
120 if ( false === $button ) {
121 return $el_arr;
122 }
123
124 $new_item = array( 'type' => 'html', 'html' => $button );
125 $insert_index = null;
126
127 foreach ( $el_arr['items'] as $index => $item ) {
128 if ( ( 'html' === $item['type'] ) && ( false !== strpos( $item['html'], 'ul_dropdown_menu_li_action_set_booking_locale' ) ) ) {
129 $insert_index = $index + 1;
130 break;
131 }
132 }
133
134 if ( null === $insert_index ) {
135 $el_arr['items'][] = $new_item;
136 return $el_arr;
137 }
138
139 array_splice( $el_arr['items'], $insert_index, 0, array( $new_item ) );
140
141 return $el_arr;
142 }
143
144 /**
145 * Get template for modal window.
146 *
147 * @return false|void
148 */
149 public static function template_for_modal() {
150
151 if (
152 ( ! function_exists( 'wpbc_availability_timeslots__render_timeline_component' ) )
153 || ( ! self::is_action_available() )
154 ) {
155 return false;
156 }
157
158 ?>
159 <span class="wpdevelop">
160 <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">
161 <div class="modal-dialog">
162 <div class="modal-content">
163 <div class="modal-header">
164 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
165 <h4 class="modal-title">
166 <?php esc_html_e( 'Set unavailable times', 'booking' ); ?>
167 <sup class="wpbc_modal__set_unavailable_times__booking_id wpbc_modal__booking_id__in_title"></sup>
168 </h4>
169 </div>
170 <div class="modal-body">
171 <?php
172 wpbc_availability_timeslots__render_timeline_component(
173 array(
174 'id_prefix' => 'wpbc_ts_listing_popup',
175 'wrap_class' => 'wpbc_ts_page wpbc_ts_popup',
176 'resource_id' => wpbc_get_default_resource(),
177 'show_hint' => false,
178 'show_legend' => true,
179 'auto_init' => false,
180 'show_toolbar_actions' => false,
181 )
182 );
183 ?>
184 </div>
185 <div class="modal-footer">
186 <a href="javascript:void(0)" class="button button-primary wpbc_ts_create_booking_button" data-wpbc-ts-create-booking="1">
187 <i class="menu_icon icon-1x wpbc-bi-calendar-plus"></i>&nbsp;
188 <?php esc_html_e( 'Create Booking for Selection', 'booking' ); ?>
189 </a>
190 <?php wpbc_availability_timeslots__render_action_buttons( 'wpbc_ts_action_buttons_inline wpbc_ts_footer_action_buttons' ); ?>
191 <a href="javascript:void(0)" class="button button-secondary" data-dismiss="modal">
192 <?php esc_html_e( 'Close', 'booking' ); ?>
193 </a>
194 </div>
195 </div><!-- /.modal-content -->
196 </div><!-- /.modal-dialog -->
197 </div><!-- /.modal -->
198 </span>
199 <?php
200 }
201 }
202
203 add_filter( 'wpbc_template__booking_listing__el__btn_action', array( 'WPBC_Action_Set_Unavailable_Times', 'add_action_to_dropdown' ) );
204 add_action( 'wpbc_hook_booking_template__hidden_templates', array( 'WPBC_Action_Set_Unavailable_Times', 'template_for_modal' ) );
205 add_action( 'wpbc_ui_el__top_nav__content_end', array( 'WPBC_Action_Set_Unavailable_Times', 'print_top_toolbar_button' ), 20, 3 );
206