Uname: Linux p3plzcpnl499967.prod.phx3.secureserver.net 4.18.0-553.54.1.lve.el8.x86_64 #1 SMP Wed Jun 4 13:01:13 UTC 2025 x86_64
Software: Apache
PHP version: 8.2.30 [ PHP INFO ] PHP os: Linux
Server Ip: 208.109.40.231
Your Ip: 216.73.216.26
User: nayff91c5tsx (10005085) | Group: nayff91c5tsx (10005085)
Safe Mode: OFF
Disable Function:
NONE

name : booking-meta.php
<?php

namespace JET_ABAF\Dashboard;

#[\AllowDynamicProperties]
class Booking_Meta {

	public function __construct() {

		$this->apartment_post_type = jet_abaf()->settings->get( 'apartment_post_type' );

		if ( $this->apartment_post_type ) {
			add_action( 'add_meta_boxes_' . $this->apartment_post_type, [ $this, 'register_meta_box' ] );
			add_action( 'admin_enqueue_scripts', [ $this, 'init_upcoming_bookings' ], 99 );

			new Units_Manager( $this->apartment_post_type );
		}

	}

	/**
	 * Register meta box.
	 *
	 * Register booking instance post type meta boxes.
	 *
	 * @since 2.0.0
	 * @since 3.2.0 Refactored.
	 */
	public function register_meta_box() {
		add_meta_box(
			'jet-abaf',
			__( 'Upcoming Bookings', 'jet-booking' ),
			[ $this, 'render_meta_box' ],
			null,
			'normal',
			'high'
		);
	}

	/**
	 * Render meta box.
	 *
	 * Render booking instance post type meta boxes.
	 *
	 * @since  2.0.0
	 * @since  2.5.5 Added additional `$post_id` handling.
	 * @since  3.2.0 Refactored. Move template body to separate file.
	 */
	public function render_meta_box() {
		echo '<div id="jet_abaf_upcoming_bookings"></div>';
	}

	/**
	 * Initialize upcoming bookings.
	 *
	 * @since 3.2.0
	 */
	public function init_upcoming_bookings( $hook ) {

		if ( ! in_array( $hook, [ 'post.php', 'post-new.php' ] ) ) {
			return;
		}

		if ( $this->apartment_post_type !== get_post_type() ) {
			return;
		}

		$ui_data = jet_abaf()->framework->get_included_module_data( 'cherry-x-vue-ui.php' );
		$ui      = new \CX_Vue_UI( $ui_data );

		$ui->enqueue_assets();

		wp_enqueue_script(
			'jet-abaf-upcoming-bookings',
			JET_ABAF_URL . 'assets/js/admin/upcoming-bookings.js',
			[ 'cx-vue-ui', 'wp-api-fetch' ],
			JET_ABAF_VERSION,
			true
		);

		global $post;

		$post_id  = jet_abaf()->db->get_initial_booking_item_id( $post->ID );
		$bookings = jet_abaf()->db->get_future_bookings( $post_id );

		$bookings = array_map( function ( $booking ) {
			$booking['check_in_date']  = date_i18n( get_option( 'date_format' ), $booking['check_in_date'] );
			$booking['check_out_date'] = date_i18n( get_option( 'date_format' ), $booking['check_out_date'] );

			return $booking;
		}, $bookings );

		wp_localize_script( 'jet-abaf-upcoming-bookings', 'JetABAFUpcomingBookingsData', [
			'api'           => jet_abaf()->rest_api->get_urls( false ),
			'bookings'      => $bookings,
			'bookings_link' => add_query_arg( [ 'page' => 'jet-abaf-bookings', ], admin_url( 'admin.php' ) ),
			'edit_link'     => add_query_arg( [ 'post' => '%id%', 'action' => 'edit', ], admin_url( 'post.php' ) ),
		] );

		add_action( 'admin_footer', [ $this, 'upcoming_bookings_template' ] );

	}

	/**
	 * Load upcoming bookings template.
	 *
	 * @since 3.2.0
	 */
	public function upcoming_bookings_template() {
		ob_start();
		include JET_ABAF_PATH . 'templates/admin/post-meta/upcoming-bookings.php';
		printf( '<script type="text/x-template" id="jet-abaf-upcoming-bookings">%s</script>', ob_get_clean() );
	}

}
© 2026 GrazzMean