PluginProbe
ShiftController Employee Shift Scheduling / 4.9.26
ShiftController Employee Shift Scheduling v4.9.26
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 / new / controller / confirm.php

confirm.php in ShiftController Employee Shift Scheduling 4.9.26, at sh4/new/controller/confirm.php

182 lines 5.3 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 class SH4_New_Controller_Confirm
3 {
4 public function __construct(
5 HC3_Hooks $hooks,
6 HC3_Post $post,
7 HC3_Notificator $notificator,
8
9 SH4_New_Controller_Common $common,
10 SH4_Shifts_Command $shiftsCommand,
11
12 SH4_Calendars_Query $calendars,
13 SH4_Employees_Query $employees,
14 SH4_ShiftTypes_Query $shiftTypes,
15
16 HC3_Time $t
17 )
18 {
19 $this->t = $t;
20 $this->post = $hooks->wrap( $post );
21 $this->notificator = $notificator;
22
23 $this->common = $hooks->wrap( $common );
24 $this->shiftsCommand = $hooks->wrap($shiftsCommand);
25
26 $this->calendars = $hooks->wrap($calendars);
27 $this->employees = $hooks->wrap($employees);
28 $this->shiftTypes = $hooks->wrap($shiftTypes);
29
30 $this->self = $hooks->wrap($this);
31 }
32
33 public function executePublish( $calendarId, $shiftTypeId, $dateString, $employeeString )
34 {
35 return $this->_execute( $calendarId, $shiftTypeId, $dateString, $employeeString, 'publish' );
36 }
37
38 public function executeDraft( $calendarId, $shiftTypeId, $dateString, $employeeString )
39 {
40 return $this->_execute( $calendarId, $shiftTypeId, $dateString, $employeeString, 'draft' );
41 }
42
43 public function _execute( $calendarId, $shiftTypeId, $dateString, $employeeString, $status )
44 {
45 set_time_limit( 600 );
46 $this->common->beforeExecute();
47
48 $shiftType = $this->shiftTypes->findById( $shiftTypeId );
49 $calendar = $this->calendars->findById( $calendarId );
50
51 $employeesIds = HC3_Functions::unglueArray( $employeeString );
52
53 // if we have multiple open shifts
54 $multiOpenShifts = 0;
55 for( $ii = 0; $ii < count($employeesIds); $ii++ ){
56 if( substr($employeesIds[$ii], 0, strlen('0' . SH4_NEW_OPEN_SEPARATOR)) == '0'.SH4_NEW_OPEN_SEPARATOR ){
57 $multiOpenShifts = substr( $employeesIds[$ii], strlen('0'.SH4_NEW_OPEN_SEPARATOR) );
58 $employeesIds[$ii] = substr( $employeesIds[$ii], 0, -strlen(SH4_NEW_OPEN_SEPARATOR . $multiOpenShifts) );
59 break;
60 }
61 }
62
63 $employees = $this->employees->findManyActiveById( $employeesIds );
64
65 $dates = HC3_Functions::unglueArray( $dateString );
66
67 $shifts = array();
68 $ids = array();
69
70 $range = $shiftType->getRange();
71 switch( $range ){
72 case SH4_ShiftTypes_Model::RANGE_DAYS:
73 $start = $this->t->setDateDb( $dates[0] )
74 ->formatDateTimeDb()
75 ;
76 $end = $this->t->setDateDb( $dates[1] )
77 ->modify('+1 day')
78 ->formatDateTimeDb()
79 ;
80 foreach( $employees as $employee ){
81 $toCreate = 1;
82 $employeeId = $employee->getId();
83 if( (! $employeeId) && $multiOpenShifts ){
84 $toCreate = $multiOpenShifts;
85 }
86
87 for( $ii = 1; $ii <= $toCreate; $ii++ ){
88 $shift = new SH4_Shifts_Model( NULL, $calendar, $start, $end, $employee );
89 $shifts[] = $shift;
90 }
91 }
92 break;
93
94 case SH4_ShiftTypes_Model::RANGE_HOURS:
95 $timeStart = $shiftType->getStart();
96 $timeEnd = $shiftType->getEnd();
97
98 $breakTimeStart = $shiftType->getBreakStart();
99 $breakTimeEnd = $shiftType->getBreakEnd();
100
101 reset( $dates );
102 foreach( $dates as $date ){
103 $start = $this->t->setDateDb( $date )
104 ->modify( '+' . $timeStart . ' seconds' )
105 ->formatDateTimeDb()
106 ;
107 $end = $this->t->setDateDb( $date )
108 ->modify( '+' . $timeEnd . ' seconds' )
109 ->formatDateTimeDb()
110 ;
111
112 $breakStart = $breakEnd = NULL;
113 if( ! ((NULL === $breakTimeStart) && (NULL === $breakTimeEnd)) ){
114 if( $breakTimeStart OR $breakTimeEnd ){
115 $breakStart = $this->t->setDateDb( $date );
116 if( $breakTimeStart ){
117 $this->t->modify( '+' . $breakTimeStart . ' seconds' );
118 }
119 $breakStart = $this->t->formatDateTimeDb();
120
121 $breakEnd = $this->t->setDateDb( $date );
122 if( $breakTimeEnd ){
123 $this->t->modify( '+' . $breakTimeEnd . ' seconds' );
124 }
125 $breakEnd = $this->t->formatDateTimeDb();
126 }
127 }
128
129 foreach( $employees as $employee ){
130 $toCreate = 1;
131 $employeeId = $employee->getId();
132 if( (! $employeeId) && $multiOpenShifts ){
133 $toCreate = $multiOpenShifts;
134 }
135
136 for( $ii = 1; $ii <= $toCreate; $ii++ ){
137 $shift = new SH4_Shifts_Model( NULL, $calendar, $start, $end, $employee, $breakStart, $breakEnd );
138 $shifts[] = $shift;
139 }
140 }
141 }
142 break;
143 }
144
145 $count = count( $shifts );
146 for( $ii = 0; $ii < $count; $ii++ ){
147 $id = $this->shiftsCommand->createNew( $shifts[$ii] );
148 $ids[] = $id;
149 }
150
151 $this->common->afterExecute( $ids );
152
153 for( $ii = 0; $ii < $count; $ii++ ){
154 switch( $status ){
155 case 'publish':
156 $id = $this->shiftsCommand->publish( $shifts[$ii] );
157 break;
158 case 'draft':
159 $id = $this->shiftsCommand->draft( $shifts[$ii] );
160 break;
161 }
162 }
163
164 $scheduleLink = $this->post->get( 'back' );
165 if( $scheduleLink ){
166 $scheduleLink = json_decode( $scheduleLink, TRUE );
167 }
168 else {
169 $scheduleLink = HC3_Session::instance()->getUserdata( 'scheduleLink' );
170 if( ! $scheduleLink ){
171 $scheduleLink = array( 'schedule', array() );
172 }
173 $scheduleLink = array( 'schedule', array() );
174 }
175
176 $returnToDate = $dates[0];
177 $scheduleLink[1]['start'] = $returnToDate;
178
179 $return = array( $scheduleLink, '__New Created__' . ' [' . count($ids) . ']' );
180 return $return;
181 }
182 }