PluginProbe
ShiftController Employee Shift Scheduling / 4.9.85
ShiftController Employee Shift Scheduling v4.9.85
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.85, at sh4/shifts/availability.php

85 lines 1.9 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 public $self, $shiftsQuery, $calendarsQuery;
13
14 public function __construct(
15 HC3_Hooks $hooks,
16 SH4_Calendars_Query $calendarsQuery,
17 SH4_Shifts_Query $shiftsQuery
18 )
19 {
20 $this->shiftsQuery = $hooks->wrap( $shiftsQuery );
21 $this->calendarsQuery = $hooks->wrap( $calendarsQuery );
22
23 $this->availabilityCalendars = array();
24 $activeCalendars = $this->calendarsQuery->findActive();
25 foreach( $activeCalendars as $c ){
26 if( $c->isAvailability() ){
27 $this->availabilityCalendars[] = $c;
28 }
29 }
30 }
31
32 public function hasAvailability()
33 {
34 $return = count( $this->availabilityCalendars ) ? TRUE : FALSE;
35 return $return;
36 }
37
38 public function get( SH4_Shifts_Model $shift )
39 {
40 $return = array();
41
42 if( ! $this->availabilityCalendars ){
43 return $return;
44 }
45
46 $start = $shift->getStart();
47 $end = $shift->getEnd();
48 $employee = $shift->getEmployee();
49
50 $this->shiftsQuery
51 ->setStart( $start )
52 ->setEnd( $end )
53 ;
54
55 $shifts = $this->shiftsQuery->find();
56
57 foreach( $shifts as $checkShift ){
58 $checkCalendar = $checkShift->getCalendar();
59 if( ! $checkCalendar->isAvailability() ){
60 continue;
61 }
62
63 $checkEmployee = $checkShift->getEmployee();
64
65 if( $employee->getId() != $checkEmployee->getId() ){
66 continue;
67 }
68
69 $checkStart = $checkShift->getStart();
70 $checkEnd = $checkShift->getEnd();
71
72 if( $checkStart > $start ){
73 continue;
74 }
75
76 if( $checkEnd < $end ){
77 continue;
78 }
79
80 $return[] = $checkShift;
81 }
82
83 return $return;
84 }
85 }