/**
  * Short Description. (use period)
  *
  * Long Description.
  *
  * @since    1.0.0
  */
 public static function activate_resource_booking()
 {
     if (!current_user_can('activate_plugins')) {
         return;
     }
     // At plugin activation creates the database
     $db_man = new Resource_Booking_DB();
     $db_man->check_version();
 }
 /**
  * Called when a Resource is deleted. It deletes all the reservations of the the deleted Resource.
  *
  * @since    0.1.0
  */
 public function delete_resource_reservations($post_id)
 {
     $post = get_post($post_id);
     if ('resource' === $post->post_type) {
         $rb_db = new Resource_Booking_DB();
         $rb_db->delete_resource($post_id);
         // postmeta rows are deleted automatically by wp
     }
 }
 public static function check_if_not_overlapping_or_die(Resource_Booking_DB $rb_db, $resource_id, $booking_id, $start, $end)
 {
     $bookings = $rb_db->check_if_overlapping($resource_id, $booking_id, $start, $end);
     if (count($bookings) > 0) {
         // And die
         wp_send_json_error(array("message" => "Booking overlapping"));
     }
 }
 /**
  * Check if the if the database needs to be updated
  *
  * @since    0.1.0
  */
 public function check_version()
 {
     global $wpdb;
     $booking_table_name = $wpdb->prefix . Resource_Booking_DB::$booking_table;
     if (get_option('rb_db_version') != Resource_Booking_DB::$rb_db_version || $wpdb->get_var("SHOW TABLES LIKE '{$booking_table_name}'") != $booking_table_name) {
         Resource_Booking_DB::create_tables();
     }
 }