Advertisement
Guest User

Untitled

a guest
Jan 29th, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.25 KB | None | 0 0
  1. /**
  2. * Special thanks to member Peter who wrote this: check only if outside working hours (based on is_service_possible_function)
  3. * Check if the time is inside working hours
  4. * @return bool
  5. */
  6.  
  7. function is_service_outside_working_hours( $ccs, $cce, $capacity ) {
  8.  
  9. // If this cell exceeds app limit then return false
  10. if ( $this->get_app_limit() < ceil( ( $ccs - $this->local_time ) /86400 ) )
  11. return false;
  12.  
  13. $result = $this->get_service( $this->service );
  14. if ( !$result !== null ) {
  15. $duration = $result->duration;
  16. if( !$duration )
  17. return true; // This means min time will be applied. No need to look
  18.  
  19. // The same for break time
  20. if ( isset( $this->options["allow_overwork_break"] ) && 'yes' == $this->options["allow_overwork_break"] )
  21. $allow_overwork_break = true;
  22. else
  23. $allow_overwork_break = false;
  24.  
  25. // Now look where our working hour ends
  26.  
  27. $days = wp_cache_get('app-open_times-for-' . $this->worker);
  28. if (!$days) {
  29. // Preprocess and cache workhours
  30. // Look where our working hour ends
  31. $result_days = $this->get_work_break($this->location, $this->worker, 'open');
  32. if ($result_days && is_object($result_days) && !empty($result_days->hours)) $days = maybe_unserialize($result_days->hours);
  33. if ($days) wp_cache_set('app-open_times-for-' . $this->worker, $days);
  34. }
  35. if (!is_array($days) || empty($days)) return true;
  36.  
  37. // If overwork is allowed, lets mark this
  38. if ( isset( $this->options["allow_overwork"] ) && 'yes' == $this->options["allow_overwork"] )
  39. $allow_overwork = true;
  40. else
  41. $allow_overwork = false;
  42.  
  43. // What is the name of this day?
  44. $this_days_name = date("l", $ccs );
  45. // This days midnight
  46. $this_day = date("d F Y", $ccs );
  47. // Will the service exceed or working time?
  48. $css_plus_duration = $ccs + ($duration *60);
  49.  
  50. foreach( $days as $day_name=>$day ) {
  51. if ( $day_name == $this_days_name && isset( $day["active"] ) && 'yes' == $day["active"] ) {
  52.  
  53. // Special case: End time is 00:00
  54. $end_mil = $this->to_military( $day["end"] );
  55. if ( '00:00' == $end_mil )
  56. $end_mil = '24:00';
  57.  
  58. if ( $allow_overwork ) {
  59. if ( $ccs >= $this->str2time( $this_day, $end_mil ) )
  60. return false;
  61. }
  62. else if ( $ccs > $this->str2time( $this_day, $end_mil ) ) {
  63. return false;
  64. }
  65. else if ( $css_plus_duration > $this->str2time( $this_day, $end_mil ) ) {
  66. return true;
  67. }
  68.  
  69. // We need to check a special case where schedule starts on eg 4pm, but our work starts on 4:30pm.
  70. if ( $ccs < strtotime( $this_day . " " . $this->to_military( $day["start"] ) , $this->local_time ) )
  71. return false;
  72. }
  73. }
  74.  
  75. }
  76. return true;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement