PluginProbe
ShiftController Employee Shift Scheduling / 4.9.24
ShiftController Employee Shift Scheduling v4.9.24
4.9.97 4.9.96 4.9.95 4.9.74 4.9.75 4.9.76 4.9.77 4.9.78 4.9.84 4.9.85 4.9.87 4.9.91 4.9.92 trunk 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 3.2.4 All 38 releases
shiftcontroller / sh4 / shifts / availability.php

availability.php in ShiftController Employee Shift Scheduling 4.9.24, at sh4/shifts/availability.php

84 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if (! defined('ABSPATH')) exit; // Exit if accessed directly
2 interface SH4_Shifts_IAvailability
3 {
4 public function get( SH4_Shifts_Model $shift );
5 public function hasAvailability();
6 }
7
8 class SH4_Shifts_Availability implements SH4_Shifts_IAvailability
9 {
10 protected $checks = array();
11 protected $availabilityCalendars = array();
12
13 public function __construct(
14 HC3_Hooks $hooks,
15 SH4_Calendars_Query $calendarsQuery,
16 SH4_Shifts_Query $shiftsQuery
17 )
18 {
19 $this->shiftsQuery = $hooks->wrap( $shiftsQuery );
20 $this->calendarsQuery = $hooks->wrap( $calendarsQuery );
21
22 $this->availabilityCalendars = array();
23 $activeCalendars = $this->calendarsQuery->findActive();
24 foreach( $activeCalendars as $c ){
25 if( $c->isAvailability() ){
26 $this->availabilityCalendars[] = $c;
27 }
28 }
29 }
30
31 public function hasAvailability()
32 {
33 $return = count( $this->availabilityCalendars ) ? TRUE : FALSE;
34 return $return;
35 }
36
37 public function get( SH4_Shifts_Model $shift )
38 {
39 $return = array();
40
41 if( ! $this->availabilityCalendars ){
42 return $return;
43 }
44
45 $start = $shift->getStart();
46 $end = $shift->getEnd();
47 $employee = $shift->getEmployee();
48
49 $this->shiftsQuery
50 ->setStart( $start )
51 ->setEnd( $end )
52 ;
53
54 $shifts = $this->shiftsQuery->find();
55
56 foreach( $shifts as $checkShift ){
57 $checkCalendar = $checkShift->getCalendar();
58 if( ! $checkCalendar->isAvailability() ){
59 continue;
60 }
61
62 $checkEmployee = $checkShift->getEmployee();
63
64 if( $employee->getId() != $checkEmployee->getId() ){
65 continue;
66 }
67
68 $checkStart = $checkShift->getStart();
69 $checkEnd = $checkShift->getEnd();
70
71 if( $checkStart > $start ){
72 continue;
73 }
74
75 if( $checkEnd < $end ){
76 continue;
77 }
78
79 $return[] = $checkShift;
80 }
81
82 return $return;
83 }
84 }