contact-forms
1 year ago
contact-forms.php
1 year ago
fluent-booking.php
9 months ago
index.php
1 month ago
newsletters.php
1 year ago
recommendation-page-post-type.php
1 year ago
recommendations-trait.php
3 months ago
siteleads.php
3 months ago
fluent-booking.php
97 lines
| 1 | <?php |
| 2 | use Kubio\Core\LodashBasic; |
| 3 | |
| 4 | |
| 5 | function kubio_is_fluent_booking_plugin_active() { |
| 6 | if ( ! class_exists( '\Kubio\PluginsManager' ) ) { |
| 7 | return false; |
| 8 | } |
| 9 | $manager = \Kubio\PluginsManager::getInstance(); |
| 10 | |
| 11 | return $manager->isPluginActive( 'fluent-booking' ); |
| 12 | } |
| 13 | |
| 14 | function kubio_get_fluent_booking_events() { |
| 15 | if ( ! kubio_is_fluent_booking_plugin_active() ) { |
| 16 | return array(); |
| 17 | } |
| 18 | if ( ! class_exists( '\FluentBooking\App\Models\CalendarSlot' ) || |
| 19 | ! class_exists( '\FluentBooking\App\Models\Calendar' ) || |
| 20 | ! method_exists( '\FluentBooking\App\Models\CalendarSlot', 'getTable' ) || |
| 21 | ! method_exists( '\FluentBooking\App\Models\Calendar', 'getTable' ) |
| 22 | ) { |
| 23 | return array(); |
| 24 | } |
| 25 | |
| 26 | global $wpdb; |
| 27 | $calendar_slot_model = new \FluentBooking\App\Models\CalendarSlot(); |
| 28 | $calendar_model = new \FluentBooking\App\Models\Calendar(); |
| 29 | $calendar_slot_table = $wpdb->prefix . $calendar_slot_model->getTable(); |
| 30 | $calendar_table = $wpdb->prefix . $calendar_model->getTable(); |
| 31 | |
| 32 | // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 33 | $calendars = $wpdb->get_results( "SELECT * FROM $calendar_table WHERE user_id = 1", ARRAY_A ); |
| 34 | |
| 35 | if ( $calendars === false || ! is_array( $calendars ) || $wpdb->last_error ) { |
| 36 | return array(); |
| 37 | } |
| 38 | |
| 39 | $calendar_id = LodashBasic::get( $calendars, '0.id' ); |
| 40 | |
| 41 | if ( empty( $calendar_id ) ) { |
| 42 | return array(); |
| 43 | } |
| 44 | // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 45 | $events = $wpdb->get_results( "SELECT * FROM $calendar_slot_table WHERE calendar_id = $calendar_id", ARRAY_A ); |
| 46 | |
| 47 | if ( $events === false || ! is_array( $events ) || $wpdb->last_error ) { |
| 48 | return array(); |
| 49 | } |
| 50 | |
| 51 | $slots = array_map( |
| 52 | function ( $event ) { |
| 53 | return array( |
| 54 | 'label' => LodashBasic::get( $event, 'title' ), |
| 55 | 'value' => intval( LodashBasic::get( $event, 'id' ) ), |
| 56 | ); |
| 57 | }, |
| 58 | $events |
| 59 | ); |
| 60 | |
| 61 | //We make sure we have the data we require |
| 62 | $slots = array_filter( |
| 63 | $slots, |
| 64 | function ( $item ) { |
| 65 | return LodashBasic::get( $item, 'value' ) !== null && LodashBasic::get( $item, 'label' ) !== null; |
| 66 | } |
| 67 | ); |
| 68 | return $slots; |
| 69 | } |
| 70 | |
| 71 | function kubio_get_fluent_booking_calendar_id() { |
| 72 | if ( ! kubio_is_fluent_booking_plugin_active() ) { |
| 73 | return null; |
| 74 | } |
| 75 | |
| 76 | if ( ! class_exists( '\FluentBooking\App\Models\Calendar' ) ) { |
| 77 | return null; |
| 78 | } |
| 79 | |
| 80 | ob_start(); |
| 81 | global $wpdb; |
| 82 | $calendar_model = new \FluentBooking\App\Models\Calendar(); |
| 83 | $calendar_table = $wpdb->prefix . $calendar_model->getTable(); |
| 84 | |
| 85 | // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 86 | $calendars = $wpdb->get_results( "SELECT * FROM $calendar_table WHERE user_id = 1", OBJECT ); |
| 87 | |
| 88 | $calendar_id = 1; |
| 89 | if ( count( $calendars ) > 0 ) { |
| 90 | $calendar_id = $calendars[0]->id; |
| 91 | } |
| 92 | |
| 93 | $errors = ob_get_clean(); |
| 94 | |
| 95 | return $calendar_id; |
| 96 | } |
| 97 |