PluginProbe
ShiftController Employee Shift Scheduling / 4.9.68
ShiftController Employee Shift Scheduling v4.9.68
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 / controller / time.php

time.php in ShiftController Employee Shift Scheduling 4.9.68, at sh4/shifts/controller/time.php

149 lines 3.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 #[AllowDynamicProperties]
3 class SH4_Shifts_Controller_Time
4 {
5 public function __construct(
6 HC3_Hooks $hooks,
7 HC3_Post $post,
8 HC3_Time $t,
9
10 SH4_Shifts_Conflicts $conflicts,
11 HC3_Auth $auth,
12 HC3_IPermission $permission,
13 SH4_App_Query $appQuery,
14 SH4_Calendars_Permissions $calendarsPermissions,
15
16 SH4_ShiftTypes_Query $shiftTypesQuery,
17
18 SH4_Shifts_Query $query,
19 SH4_Shifts_Command $command,
20 SH4_Employees_Query $employees
21 )
22 {
23 $this->post = $post;
24 $this->t = $t;
25
26 $this->shiftTypesQuery = $hooks->wrap($shiftTypesQuery);
27
28 $this->query = $hooks->wrap($query);
29 $this->command = $hooks->wrap($command);
30 $this->employees = $hooks->wrap($employees);
31
32 $this->auth = $hooks->wrap( $auth );
33 $this->permission = $hooks->wrap( $permission );
34 $this->conflicts = $hooks->wrap($conflicts);
35 $this->appQuery = $hooks->wrap( $appQuery );
36 $this->calendarsPermissions = $hooks->wrap( $calendarsPermissions );
37 }
38
39 public function execute( $shiftId )
40 {
41 $shift = $this->query->findById( $shiftId );
42
43 $shiftTypeId = $this->post->get('shifttype');
44 if( NULL !== $shiftTypeId ){
45 $shiftType = $this->shiftTypesQuery->findById( $shiftTypeId );
46
47 $timeStart = $shiftType->getStart();
48 $timeEnd = $shiftType->getEnd();
49 $startBreak = $shiftType->getBreakStart();
50 $endBreak = $shiftType->getBreakEnd();
51 }
52 else {
53 $time = $this->post->get('time');
54
55 if( NULL === $time ){
56 $to = 'schedule';
57 $msg = '__Required Field__';
58 $return = array( $to, $msg, TRUE );
59 return $return;
60 }
61
62 list( $timeStart, $timeEnd ) = explode( '-', $time );
63
64 $startBreak = $endBreak = NULL;
65 $breakOn = $this->post->get('break_on');
66 if( $breakOn ){
67 $break = $this->post->get('break');
68 list( $startBreak, $endBreak ) = explode( '-', $break );
69 }
70 }
71
72 $date = $shift->getDateStart();
73
74 $start = $this->t->setDateDb( $date )
75 ->modify( '+' . $timeStart . ' seconds' )
76 ->formatDateTimeDb()
77 ;
78 $end = $this->t->setDateDb( $date )
79 ->modify( '+' . $timeEnd . ' seconds' )
80 ->formatDateTimeDb()
81 ;
82
83 if( NULL !== $startBreak ){
84 $startBreak = $this->t->setDateDb( $date )
85 ->modify( '+' . $startBreak . ' seconds' )
86 ->formatDateTimeDb()
87 ;
88 }
89 if( NULL !== $endBreak ){
90 $endBreak = $this->t->setDateDb( $date )
91 ->modify( '+' . $endBreak . ' seconds' )
92 ->formatDateTimeDb()
93 ;
94 }
95
96 // check if it creates a conflict
97 $calendar = $shift->getCalendar();
98 $calendarId = $calendar->getId();
99
100 // $testModel = new SH4_Shifts_Model( NULL, $calendar, $start, $end, $shift->getEmployee(), $startBreak, $endBreak );
101 $testModel = new SH4_Shifts_Model( $shift->getId(), $calendar, $start, $end, $shift->getEmployee(), $startBreak, $endBreak );
102 $conflicts = $this->conflicts->get( $testModel );
103
104 $allowed = TRUE;
105 if( $conflicts ){
106 $isManager = FALSE;
107
108 $currentUser = $this->auth->getCurrentUser();
109 $currentUserId = $currentUser->getId();
110 if( $currentUserId ){
111 if( $this->permission->isAdmin($currentUser) ){
112 $isManager = TRUE;
113 }
114 else {
115 $calendarsAsManager = $this->appQuery->findCalendarsManagedByUser( $currentUser );
116 if( isset($calendarsAsManager[$calendarId]) ){
117 $isManager = TRUE;
118 }
119 }
120 }
121
122 if( ! $isManager ){
123 if( ! $this->calendarsPermissions->get($calendar, 'employee_create_own_conflicts') ){
124 $allowed = FALSE;
125 }
126 }
127 }
128
129 $to = $this->post->get( 'back' );
130 if( $to ){
131 $to = json_decode( $to, TRUE );
132 }
133 else {
134 $to = array( 'schedule', array() );
135 }
136
137 if( $allowed ){
138 $this->command->reschedule( $shift, $start, $end, $startBreak, $endBreak );
139 $msg = '__Shift Rescheduled__';
140 $return = array( $to, $msg );
141 }
142 else {
143 $msg = '__You cannot create new shifts with conflicts.__';
144 $return = array( $to, $msg, TRUE );
145 }
146
147 return $return;
148 }
149 }