Last active
August 29, 2015 14:14
-
-
Save JudeRosario/c98c6b5228539f54b3b3 to your computer and use it in GitHub Desktop.
Add 4th Color to Appointments Table
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add the 4th Option to the array | |
function get_classes() { | |
return apply_filters( 'app_box_class_names', | |
array( | |
'free' => __('Free', 'appointments'), | |
'busy' => __('Busy', 'appointments'), | |
'notpossible' => __('Not possible', 'appointments'), | |
// Add the option and description here | |
'free_but_collision' => __(‘Free, but Collision', 'appointments') | |
) | |
); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Special thanks to member Peter who contributed this | |
* check only if outside working hours (based on is_service_possible_function) | |
* Check if the time is inside working hours | |
* @return bool | |
*/ | |
function is_service_outside_working_hours( $ccs, $cce, $capacity ) { | |
// If this cell exceeds app limit then return false | |
if ( $this->get_app_limit() < ceil( ( $ccs - $this->local_time ) /86400 ) ) | |
return false; | |
$result = $this->get_service( $this->service ); | |
if ( !$result !== null ) { | |
$duration = $result->duration; | |
if( !$duration ) | |
return true; // This means min time will be applied. No need to look | |
// The same for break time | |
if ( isset( $this->options["allow_overwork_break"] ) && 'yes' == $this->options["allow_overwork_break"] ) | |
$allow_overwork_break = true; | |
else | |
$allow_overwork_break = false; | |
// Now look where our working hour ends | |
$days = wp_cache_get('app-open_times-for-' . $this->worker); | |
if (!$days) { | |
// Preprocess and cache workhours | |
// Look where our working hour ends | |
$result_days = $this->get_work_break($this->location, $this->worker, 'open'); | |
if ($result_days && is_object($result_days) && !empty($result_days->hours)) $days = maybe_unserialize($result_days->hours); | |
if ($days) wp_cache_set('app-open_times-for-' . $this->worker, $days); | |
} | |
if (!is_array($days) || empty($days)) return true; | |
// If overwork is allowed, lets mark this | |
if ( isset( $this->options["allow_overwork"] ) && 'yes' == $this->options["allow_overwork"] ) | |
$allow_overwork = true; | |
else | |
$allow_overwork = false; | |
// What is the name of this day? | |
$this_days_name = date("l", $ccs ); | |
// This days midnight | |
$this_day = date("d F Y", $ccs ); | |
// Will the service exceed or working time? | |
$css_plus_duration = $ccs + ($duration *60); | |
foreach( $days as $day_name=>$day ) { | |
if ( $day_name == $this_days_name && isset( $day["active"] ) && 'yes' == $day["active"] ) { | |
// Special case: End time is 00:00 | |
$end_mil = $this->to_military( $day["end"] ); | |
if ( '00:00' == $end_mil ) | |
$end_mil = '24:00'; | |
if ( $allow_overwork ) { | |
if ( $ccs >= $this->str2time( $this_day, $end_mil ) ) | |
return false; | |
} | |
else if ( $ccs > $this->str2time( $this_day, $end_mil ) ) { | |
return false; | |
} | |
else if ( $css_plus_duration > $this->str2time( $this_day, $end_mil ) ) { | |
return true; | |
} | |
// We need to check a special case where schedule starts on eg 4pm, but our work starts on 4:30pm. | |
if ( $ccs < strtotime( $this_day . " " . $this->to_military( $day["start"] ) , $this->local_time ) ) | |
return false; | |
} | |
} | |
} | |
return true; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Line #2371 in `Appointments.php` changed from: | |
# ======================== | |
else if ( !$this->is_service_possible( $ccs, $cce, $capacity ) ) | |
$class_name = 'notpossible service_notpossible'; | |
# changed to: | |
#============= | |
// Then check if the time window is inside working hours | |
else if ( !$this->is_service_outside_working_hours( $ccs, $cce, $capacity ) ) | |
$class_name = 'notpossible'; | |
// Then check if we have enough time to fulfill this app | |
else if ( !$this-> is_service_possible( $ccs, $cce, $capacity ) ) | |
$class_name = 'free_but_collision'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# changed "is_possible fuction" to two independent functions (used in step 2) to check working hours and pre-appointment collisions independently | |
/** | |
* Special thanks to member Peter who contributed this | |
* Edited by moving the working hour checks to independent function 'is_service_outside_working_hours' below | |
* Check if time is enough for this service | |
* e.g if we are working until 6pm, it is not possible to take an app with 60 mins duration at 5:30pm | |
* Please note that "not possible" is an exception | |
* @return bool | |
*/ | |
function is_service_possible( $ccs, $cce, $capacity ) { | |
$result = $this->get_service( $this->service ); | |
if ( !$result !== null ) { | |
$duration = $result->duration; | |
if( !$duration ) | |
return true; // This means min time will be applied. No need to look | |
// The same for break time | |
if ( isset( $this->options["allow_overwork_break"] ) && 'yes' == $this->options["allow_overwork_break"] ) | |
$allow_overwork_break = true; | |
else | |
$allow_overwork_break = false; | |
// Check for further appointments or breaks on this day, if this is a lasting appointment | |
if ( $duration > $this->get_min_time() ) { | |
$step = ceil( $duration/$this->get_min_time() ); | |
$min_secs = $this->get_min_time() *60; | |
if ( $step < 20 ) { // Let's not exaggerate ! | |
for ( $n =1; $n < $step; $n++ ) { | |
if ( $this->is_busy( $ccs + $n * $min_secs, $ccs + ($n+1) * $min_secs, $capacity ) ) | |
return false; // There is an appointment in the predeeding times | |
// We can check breaks here too | |
if ( !$allow_overwork_break ) { | |
if ( $this->is_break( $ccs + $n * $min_secs, $ccs + ($n+1) * $min_secs ) ) | |
return false; // There is a break in the predeeding times | |
} | |
} | |
} | |
} | |
// Now look where our working hour ends | |
$days = wp_cache_get('app-open_times-for-' . $this->worker); | |
if (!$days) { | |
// Preprocess and cache workhours | |
// Look where our working hour ends | |
$result_days = $this->get_work_break($this->location, $this->worker, 'open'); | |
if ($result_days && is_object($result_days) && !empty($result_days->hours)) $days = maybe_unserialize($result_days->hours); | |
if ($days) wp_cache_set('app-open_times-for-' . $this->worker, $days); | |
} | |
if (!is_array($days) || empty($days)) return true; | |
// If overwork is allowed, lets mark this | |
if ( isset( $this->options["allow_overwork"] ) && 'yes' == $this->options["allow_overwork"] ) | |
$allow_overwork = true; | |
else | |
$allow_overwork = false; | |
// What is the name of this day? | |
$this_days_name = date("l", $ccs ); | |
// This days midnight | |
$this_day = date("d F Y", $ccs ); | |
// Will the service exceed or working time? | |
$css_plus_duration = $ccs + ($duration *60); | |
foreach( $days as $day_name=>$day ) { | |
if ( $day_name == $this_days_name && isset( $day["active"] ) && 'yes' == $day["active"] ) { | |
// Special case: End time is 00:00 | |
$end_mil = $this->to_military( $day["end"] ); | |
if ( '00:00' == $end_mil ) | |
$end_mil = '24:00'; | |
if ( $allow_overwork ) { | |
if ( $ccs >= $this->str2time( $this_day, $end_mil ) ) | |
return false; | |
} | |
else if ( $css_plus_duration > $this->str2time( $this_day, $end_mil ) ) { | |
return false; | |
} | |
// We need to check a special case where schedule starts on eg 4pm, but our work starts on 4:30pm. | |
if ( $ccs < strtotime( $this_day . " " . $this->to_military( $day["start"] ) , $this->local_time ) ) | |
return false; | |
} | |
} | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment