Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Special thanks to member Peter who wrote 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement