PluginProbe
Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar / 2.0
Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar v2.0
2.1.21 2.1.20 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 trunk 1.1 2.0 2.0.1 2.0.10.2 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.16 2.0.17 2.0.18 2.0.2 2.0.20 2.0.21 2.0.22 All 55 releases
booking-manager / core / wpbc / wpbm-bc.php

wpbm-bc.php in Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar 2.0, at core/wpbc/wpbm-bc.php

211 lines 6.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @version 1.0
4 * @description Booking Calendar integration - Support Functions
5 *
6 * @author wpdevelop
7 * @link http://oplugins.com/
8 * @email info@oplugins.com
9 *
10 * @modified 2017-06-28
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
14
15
16 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
17 // S u p p o r t Functions for integration with Booking Calendar
18 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
19
20
21 // Final Class for Creation new Bookings into Booking Calendar
22 final class WPBM_create_bookings_from_events {
23
24 static private $instance = NULL;
25
26 public static $current_ics_dates = array(); // unlike a const, static property values can be changed
27
28
29 /** Init this class only once
30 *
31 * @return obj
32 */
33 public static function init() {
34
35 if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WPBM_create_bookings_from_events ) ) {
36 self::$instance = new WPBM_create_bookings_from_events;
37 }
38 return self::$instance;
39 }
40
41
42 /** Get array of assigned form fields from the Booking Calendar plugin
43 *
44 * @return array array(
45 [0] => Array (
46 [ics_field_name] => title
47 [type] => text
48 [name] => name
49 )
50 [1] => Array (
51 [ics_field_name] => description
52 [type] => textarea
53 [name] => details
54 )
55 )
56 */
57 public static function get_assigned_form_fields() {
58
59 if ( ! function_exists( 'get_bk_option' ) ) return false;
60
61 $wpbc_assigned_form_fields = get_bk_option( 'booking_gcal_events_form_fields' );
62 $wpbc_assigned_form_fields = maybe_unserialize( $wpbc_assigned_form_fields );
63 /** $wpbc_assigned_form_fields = array(
64 [title] => text^name
65 [description] => customform^textarea^details
66 [where] => text^
67 )
68 */
69
70
71 $assigned_fields_arr = array();
72
73 foreach ( $wpbc_assigned_form_fields as $assign_ics_field_name => $wpbc_field_str ) {
74
75 $wpbc_field_arr = explode( '^', $wpbc_field_str );
76 $wpbc_field_arr_count = count( $wpbc_field_arr ) - 1;
77
78 if ( ! empty( $wpbc_field_arr[ $wpbc_field_arr_count ] ) ) {
79 $assigned_fields_arr[] = array(
80 'ics_field_name' => $assign_ics_field_name
81 , 'type' => $wpbc_field_arr[ ($wpbc_field_arr_count - 1 ) ]
82 , 'name' => $wpbc_field_arr[ $wpbc_field_arr_count ]
83 );
84 }
85
86 }
87 /** $assigned_fields_arr = array(
88 [0] => Array (
89 [ics_field_name] => title
90 [type] => text
91 [name] => name
92 )
93 [1] => Array (
94 [ics_field_name] => description
95 [type] => textarea
96 [name] => details
97 )
98 )
99 */
100 return $assigned_fields_arr;
101 }
102
103
104 public static function set_ics_dates( $value ) {
105 self::$current_ics_dates = $value;
106 }
107
108 public static function get_ics_dates() {
109 return self::$current_ics_dates;
110 }
111
112 public static function erase_ics_dates() {
113 self::$current_ics_dates = array();
114 }
115
116
117
118 }
119 WPBM_create_bookings_from_events::init(); // Initial Start
120
121
122 /** Hook for overwriting saving dates
123 *
124 * // From: ..\wp-content\plugins\booking\core\wpbc-dates.php
125 * // apply_filters( 'wpbc_get_insert_sql_for_dates', $is_return_dates, $dates_in_diff_formats , $is_approved_dates, $booking_id, $is_return_only_array );
126 *
127 * @param type $is_return_dates
128 * @param type $dates_in_diff_formats
129 * @param type $is_approved_dates
130 * @param type $booking_id
131 * @param type $is_return_only_array
132 * @return type
133 */
134 function wpbm_get_insert_sql_for_dates( $is_return_dates, $dates_in_diff_formats , $is_approved_dates, $booking_id, $is_return_only_array ) {
135
136 $dates_to_insert = WPBM_create_bookings_from_events::get_ics_dates();
137
138 if ( empty( $dates_to_insert ) )
139 return $is_return_dates;
140
141 $insert_arr = array();
142 $insert = array();
143
144 foreach ( $dates_to_insert as $date) {
145
146 // Loop
147 $insert_arr []= array( $booking_id, $date, $is_approved_dates );
148 $insert []= "('$booking_id', '$date', '$is_approved_dates' )";
149
150 }
151
152 $insert = implode( ',', $insert );
153
154 //debuge($booking_id, $insert);
155
156 if ( $is_return_only_array ) {
157 return $insert_arr;
158 } else {
159 return $insert;
160 }
161
162 }
163
164
165 /** Hook for overwriting updating dates. Usually used for do not allow to make this updating.
166 *
167 * // From: ..\wp-content\plugins\booking\inc\_bl\biz_l.php
168 * // $is_continue = apply_filters( 'wpbc_is_reupdate_dates_to_child_resources', $is_exit, $booking_id, $bktype, $dates, $start_end_time_arr , $formdata, $skip_page_checking_for_updating );
169 *
170 * @param type $is_exit
171 * @param type $booking_id
172 * @param type $bktype
173 * @param type $dates
174 * @param type $start_end_time_arr
175 * @param type $formdata
176 * @param type $skip_page_checking_for_updating
177 * @return boolean
178 */
179 function wpbm_is_reupdate_dates_to_child_resources( $is_exit, $booking_id, $bktype, $dates, $start_end_time_arr , $formdata, $skip_page_checking_for_updating ) {
180 return true;
181 }
182
183
184 /** Getting only Booking fields ( starting '_BOOKING' ) from Parsed ICS array
185 * - its support helpful function
186 *
187 * @param type $ics_array
188 * @return type
189 */
190 function wpbm_get_booking_fields_from_ics_array( $ics_array ) {
191
192 $booking_array = array();
193
194 foreach ( $ics_array as $ics_n => $ics_event_arr ) {
195
196 $one_booking = array();
197
198 foreach ( $ics_event_arr as $event_field_key => $event_field_value ) {
199
200 $is_booking_field = strpos( $event_field_key, '_BOOKING' );
201 if ( $is_booking_field !== false ) {
202 $one_booking[ $event_field_key ] = $event_field_value;
203 }
204 }
205
206 if ( ! empty( $one_booking ) ) {
207 $booking_array[] = $one_booking;
208 }
209 }
210 return $booking_array;
211 }