• Resolved Gerald

    (@gerital)


    I use this plugin to program events at a community center and everything works great. Till now I used fixed slots of 1h but now I have the requirement for flexible slots depending of the kind of event used on reservation process.

    The plugin doesn’t support flexible slots and probably it would quite a lot of refactoring of how it works now to implement that. So I thought of trying the following approach:

    1. Hook into creating new appointment
    2. Look at the event type to get slot time
    3. Modify “end” column in “wp_ea_appointments” table using SQL

    Could this work using ea_new_app_from_customer hook or are there drawbacks I missed?

    • This topic was modified 6 years, 5 months ago by Gerald.
    • This topic was modified 6 years, 5 months ago by Gerald.
    • This topic was modified 6 years, 5 months ago by Gerald.
    • This topic was modified 6 years, 5 months ago by Gerald.
Viewing 1 replies (of 1 total)
  • Thread Starter Gerald

    (@gerital)

    Finally I managed to get the flexible slots running. I followed the approach drafted in the above question, here the code:

    function custom_create_appointment( $appointment_id, $appointment_data ) {
    	global $wpdb;
    
    	// get event id
    	$eventId = ($wpdb->get_row("SELECT value from wp_ea_fields WHERE app_id=".$appointment_id." AND field_id=5"))->value;
    
    	// get event duration (in seconds)
    	$duration = wp_get_attachment_metadata(get_post_meta($eventId, "duration", true));
    
    	// check if podcast lasts longer than slot of 30 minutes
    	if ($duration > 1800) {
    
    		// change end time of podcast
    		$slots = ceil($duration/1800);
    		$endtime = strtotime($appointment_data["start"]) + $slots*30*60;
    		$endtimeStr = date('H:i:s', $endtime);
    
    		// check if new endtime interferers with following event
    		$interfereEvent = $wpdb->get_results("SELECT * from wp_ea_appointments WHERE date='".$appointment_data["date"]."' AND end_date='".$appointment_data["end_date"]."' AND start < CAST('".$endtimeStr."' AS time) AND end > CAST('".$endtimeStr."' AS time)");
    		if (count($interfereEvent) < 1) {
    
      			$wpdb->update(
    				"wp_ea_appointments", 
    				array("end"=>$endtimeStr), 
    				array("id"=>$appointment_id)
    			);
    		}
    	}
    
    }
    add_action( 'ea_new_app_from_customer', 'custom_create_appointment', 10, 2 );

    This approach has the limitation that you can fill available slots with events which are longer than the slot, so users have to be careful!

    • This reply was modified 6 years, 5 months ago by Gerald.
    • This reply was modified 6 years, 5 months ago by Gerald. Reason: add condition so next events don't get interferred
Viewing 1 replies (of 1 total)
  • The topic ‘Create flexible slots’ is closed to new replies.