PluginProbe
ShiftController Employee Shift Scheduling / 4.9.60
ShiftController Employee Shift Scheduling v4.9.60
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 / view / confirm.php

confirm.php in ShiftController Employee Shift Scheduling 4.9.60, at sh4/new/view/confirm.php

463 lines 12.2 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_New_View_Confirm
4 {
5 public function __construct(
6 HC3_Hooks $hooks,
7
8 HC3_Auth $auth,
9 HC3_IPermission $permission,
10 SH4_Shifts_Conflicts $conflicts,
11
12 HC3_Request $request,
13 HC3_Ui $ui,
14 HC3_Ui_Layout1 $layout,
15 HC3_Settings $settings,
16
17 SH4_New_View_Common $common,
18
19 SH4_Shifts_Availability $availability,
20
21 SH4_Calendars_Query $calendars,
22 SH4_Employees_Query $employees,
23 SH4_ShiftTypes_Query $shiftTypesQuery,
24
25 SH4_Employees_Presenter $employeesPresenter,
26 SH4_Calendars_Presenter $calendarsPresenter,
27 SH4_ShiftTypes_Presenter $shiftTypesPresenter,
28
29 SH4_Calendars_Permissions $calendarsPermissions,
30
31 SH4_App_Query $appQuery,
32 SH4_New_Query $newQuery,
33
34 HC3_Time $t
35 )
36 {
37 $this->self = $hooks->wrap( $this );
38
39 $this->auth = $hooks->wrap( $auth );
40 $this->permission = $hooks->wrap( $permission );
41 $this->request = $request;
42 $this->ui = $ui;
43 $this->layout = $layout;
44 $this->common = $hooks->wrap($common);
45
46 $this->calendarsPermissions = $hooks->wrap( $calendarsPermissions );
47 $this->t = $t;
48
49 $this->settings = $hooks->wrap( $settings );
50
51 $this->conflicts = $hooks->wrap($conflicts);
52 $this->availability = $hooks->wrap( $availability );
53
54 $this->calendars = $hooks->wrap($calendars);
55 $this->employees = $hooks->wrap($employees);
56 $this->shiftTypesQuery = $hooks->wrap( $shiftTypesQuery );
57
58 $this->employeesPresenter = $hooks->wrap( $employeesPresenter );
59 $this->calendarsPresenter = $hooks->wrap( $calendarsPresenter );
60 $this->shiftTypesPresenter = $hooks->wrap( $shiftTypesPresenter );
61
62 $this->appQuery = $hooks->wrap( $appQuery );
63 $this->newQuery = $hooks->wrap( $newQuery );
64 }
65
66 public function render()
67 {
68 $params = $this->request->getParams();
69
70 $calendarId = $params['calendar'];
71 $shiftTypeId = $params['shifttype'];
72 $dateString = $params['date'];
73 $employeeString = $params['employee'];
74
75 $dates = HC3_Functions::unglueArray( $dateString );
76
77 $datesView = array();
78 foreach( $dates as $date ){
79 $this->t->setDateDb( $date );
80 $dateView = $this->t->getWeekdayName() . ', ' . $this->t->formatDate();
81 $dateView = $this->ui->makeBlock( $dateView )
82 ->tag('border')
83 ->tag('border-color', 'gray')
84 ->tag('padding', 2)
85 ;
86 $datesView[] = $dateView;
87 }
88
89 $shiftType = $this->shiftTypesQuery->findById( $shiftTypeId );
90 $range = $shiftType->getRange();
91 switch( $range ){
92 case SH4_ShiftTypes_Model::RANGE_DAYS:
93 $datesView = $this->ui->makeListInline( $datesView )
94 ->separated( '&rarr;' )
95 ;
96 break;
97
98 case SH4_ShiftTypes_Model::RANGE_HOURS:
99 $datesView = $this->ui->makeListInline( $datesView )
100 ->gutter(1)
101 ;
102 break;
103 }
104
105 $label = ( count($dates) > 1 ) ? '__Dates__' : '__Date__';
106 $datesView = $this->ui->makeLabelled( $label, $datesView );
107
108 $shiftType = $this->shiftTypesQuery->findById( $shiftTypeId );
109
110 // employees
111 $calendars = $this->newQuery->findAllCalendars();
112 if( array_key_exists($calendarId, $calendars) ){
113 $calendar = $calendars[$calendarId];
114 }
115 else {
116 $calendar = NULL;
117 }
118
119 if( ! $calendar ){
120 return;
121 }
122
123 $isAvailability = $calendar->isAvailability();
124
125 $employees = $this->newQuery->findAllEmployees();
126
127 if( $calendar ){
128 $filter = $this->appQuery->findEmployeesForCalendar( $calendar );
129
130 $filterIds = array_keys( $filter );
131 $ids = array_keys( $employees );
132 foreach( $ids as $id ){
133 if( ! in_array($id, $filterIds) ){
134 unset( $employees[$id] );
135 }
136 }
137 }
138
139 $openQty = 0;
140 $suppliedEmployeesIds = HC3_Functions::unglueArray( $employeeString );
141 if( in_array(0, $suppliedEmployeesIds) ){
142 $openQty = 1;
143 }
144
145 $ids = array_keys( $employees );
146
147 foreach( $suppliedEmployeesIds as $id ){
148 if( strpos($id, SH4_NEW_OPEN_SEPARATOR) !== FALSE ){
149 list( $id, $openQty ) = explode( SH4_NEW_OPEN_SEPARATOR, $id );
150 $suppliedEmployeesIds[] = $id;
151 break;
152 }
153 }
154
155 foreach( $ids as $id ){
156 if( ! in_array($id, $suppliedEmployeesIds) ){
157 unset( $employees[$id] );
158 }
159 }
160
161 if( ! $openQty ){
162 unset( $employees[0] );
163 }
164
165 if( ! $employees ){
166 return;
167 }
168
169 $out = array();
170 $calendarView = $this->calendarsPresenter->presentTitle( $calendar );
171
172 $description = $this->calendarsPresenter->presentDescription( $calendar );
173 if( strlen($description) ){
174 $len = 100;
175 if( strlen($description) > $len ){
176 $descriptionSummary = substr( $description, 0, $len ) . '...';
177 $descriptionSummary = $this->ui->makeElement( 'summary', $descriptionSummary );
178 $descriptionView = $this->ui->makeCollection( array($descriptionSummary, $description) );
179 $descriptionView = $this->ui->makeElement( 'details', $descriptionView );
180 }
181 else {
182 $descriptionView = $description;
183 }
184
185 $calendarView = $this->ui->makeList( array($calendarView, $descriptionView) )
186 ->gutter(0)
187 ;
188 }
189
190 $shiftTypeView = $this->shiftTypesPresenter->presentTitleTime( $shiftType );
191
192 $calendarView = $this->ui->makeList( array($calendarView, $shiftTypeView) )
193 ->gutter(0)
194 ;
195 $calendarView = $this->ui->makeBlock( $calendarView )
196 ->tag('border')
197 ->tag('border-color', 'gray')
198 ->tag('padding', 2)
199 ;
200
201 $out[] = $calendarView;
202
203 $employeesView = array();
204 $timeStart = $shiftType->getStart();
205 $timeEnd = $shiftType->getEnd();
206
207 foreach( $employees as $employee ){
208 $withConflicts = 0;
209 $withAvailability = 0;
210 $withNothing = 0;
211
212 $employeeId = $employee->getId();
213 $thisView = array();
214
215 $label = $this->employeesPresenter->presentTitle( $employee );
216
217 if( ! $employeeId ){
218 if( $openQty > 1 ){
219 $label = $openQty . ' x ' . $label;
220 }
221 }
222
223 $thisView[] = $label;
224
225 // check conflicts
226 if( $employeeId && (! $isAvailability) ){
227 $testModels = array();
228
229 $range = $shiftType->getRange();
230 switch( $range ){
231 case SH4_ShiftTypes_Model::RANGE_DAYS:
232 $start = $this->t->setDateDb( $dates[0] )
233 ->formatDateTimeDb()
234 ;
235 $end = $this->t->setDateDb( $dates[1] )
236 ->modify('+1 day')
237 ->formatDateTimeDb()
238 ;
239
240 $testModel = new SH4_Shifts_Model( NULL, $calendar, $start, $end, $employee );
241 $testModels[] = $testModel;
242 break;
243
244 case SH4_ShiftTypes_Model::RANGE_HOURS:
245 $timeStart = $shiftType->getStart();
246 $timeEnd = $shiftType->getEnd();
247 reset( $dates );
248 foreach( $dates as $date ){
249 $start = $this->t->setDateDb( $date )
250 ->modify( '+' . $timeStart . ' seconds' )
251 ->formatDateTimeDb()
252 ;
253 $end = $this->t->setDateDb( $date )
254 ->modify( '+' . $timeEnd . ' seconds' )
255 ->formatDateTimeDb()
256 ;
257 $testModel = new SH4_Shifts_Model( NULL, $calendar, $start, $end, $employee );
258 $testModels[] = $testModel;
259 }
260 break;
261 }
262
263 reset( $testModels );
264 foreach( $testModels as $testModel ){
265 $conflicts = $this->conflicts->get( $testModel );
266
267 if( $conflicts ){
268 $withConflicts++;
269 }
270 else {
271 if( (! $this->availability->hasAvailability()) OR $this->availability->get($testModel) ){
272 $withAvailability++;
273 }
274 else {
275 $withNothing++;
276 }
277 }
278 }
279
280 $conflictsView = array();
281
282 if( $withAvailability ){
283 $sign = ( count($testModels) < 2 ) ? '&check;' : $withAvailability;
284 $sign = $this->ui->makeBlock( $sign )
285 ->tag('padding', 'x1')
286 ->tag('color', 'white')
287 ->tag('bgcolor', 'olive')
288 ->addAttr( 'title', '__Available__' )
289 ;
290 $conflictsView[] = $sign;
291 }
292
293 if( $withNothing ){
294 $sign = ( count($testModels) < 2 ) ? '&check;' : $withNothing;
295 $sign = $this->ui->makeBlock( $sign )
296 ->tag('padding', 'x1')
297 ->tag('color', 'white')
298 ->tag('bgcolor', 'gray')
299 ->addAttr( 'title', '__No Availability__' )
300 ;
301 $conflictsView[] = $sign;
302 }
303
304 if( $withConflicts ){
305 $sign = (count($testModels) < 2) ? '&nbsp;!&nbsp;' : $withConflicts;
306 $sign = $this->ui->makeBlock( $sign )
307 ->tag('padding', 'x1')
308 ->tag('color', 'white')
309 ->tag('bgcolor', 'maroon')
310 ->addAttr( 'title', '__Conflicts__' )
311 ;
312 $conflictsView[] = $sign;
313 }
314
315 $conflictsView = $this->ui->makeListInline( $conflictsView )
316 ->gutter(1)
317 ;
318 array_unshift( $thisView, $conflictsView );
319 }
320
321 $thisView = $this->ui->makeListInline( $thisView );
322 $thisView = $this->ui->makeBlock( $thisView )
323 ->addAttr('style', 'position: relative;')
324 ;
325
326 $thisView = $this->ui->makeBlock( $thisView )
327 ->tag('border')
328 ->tag('padding', 2)
329 ;
330
331 if( $withAvailability == count($dates) ){
332 $thisView
333 ->tag('border-color', 'green')
334 ;
335 }
336 elseif( $withConflicts ){
337 $thisView
338 ->tag('border-color', 'red')
339 ;
340 }
341 else {
342 $thisView
343 ->tag('border-color', 'gray')
344 ;
345 }
346
347 $employeesView[] = $thisView;
348 }
349
350 $employeesView = $this->ui->makeListInline( $employeesView );
351 $label = ( count($employees) > 1 ) ? '__Employees__' : '__Employee__';
352 $employeesView = $this->ui->makeLabelled( $label, $employeesView );
353
354 $out[] = $datesView;
355 $out[] = $employeesView;
356
357 $out = $this->ui->makeList( $out );
358
359 $out = array( $out );
360
361 // employee_create_own_conflicts
362 $showButtons = TRUE;
363
364 if( $withConflicts ){
365 $isManager = FALSE;
366
367 $currentUser = $this->auth->getCurrentUser();
368 $currentUserId = $currentUser->getId();
369 if( $currentUserId ){
370 if( $this->permission->isAdmin($currentUser) ){
371 $isManager = TRUE;
372 }
373 else {
374 $calendarsAsManager = $this->appQuery->findCalendarsManagedByUser( $currentUser );
375 if( isset($calendarsAsManager[$calendarId]) ){
376 $isManager = TRUE;
377 }
378 }
379 }
380
381 if( ! $isManager ){
382 if( ! $this->calendarsPermissions->get($calendar, 'employee_create_own_conflicts') ){
383 $showButtons = FALSE;
384 }
385 }
386 }
387
388 if( $showButtons ){
389 $btn = $this->self->buttons( $calendarId, $shiftTypeId, $dateString, $employeeString );
390 $btn = $this->ui->makeListInline( $btn );
391 }
392 else {
393 $btn = '__You cannot create new shifts with conflicts.__';
394 }
395
396 // open shift
397 $inputs = $this->common->inputs( $calendarId, $shiftTypeId, $employeeId );
398 $out = array_merge( $out, $inputs );
399
400 $out[] = $btn;
401
402 $out = $this->ui->makeList( $out )->gutter(3);
403
404 // schedule link
405 $scheduleLink = HC3_Session::instance()->getUserdata( 'scheduleLink' );
406 if( ! $scheduleLink ){
407 $scheduleLink = array( 'schedule', array() );
408 }
409 $scheduleLinkValue = json_encode( $scheduleLink );
410 $inputBackHidden = $this->ui->makeInputHidden( 'back', $scheduleLinkValue );
411 $out = $this->ui->makeCollection( array($out, $inputBackHidden) );
412
413 $to = array( 'new', $calendarId, $shiftTypeId, $dateString, $employeeString );
414 $to = join( '/', $to );
415 $out = $this->ui->makeForm( $to, $out );
416
417 $this->layout
418 ->setContent( $out )
419 // ->setBreadcrumb( $this->common->breadcrumb($calendarId, $shiftTypeId) )
420 ->setHeader( $this->self->header() )
421 ;
422 $out = $this->layout->render();
423
424 return $out;
425 }
426
427 public function buttons( $calendarId, $shiftTypeId, $dateString, $employeeString )
428 {
429 $ret = array();
430
431 $noDraft = $this->settings->get('shifts_no_draft') ? TRUE : FALSE;
432
433 // draft
434 if( ! $noDraft ){
435 $to = array( 'new', $calendarId, $shiftTypeId, $dateString, $employeeString, 'draft' );
436 $to = join( '/', $to );
437 $btnDraft = $this->ui->makeInputSubmit( '__Create Draft__')
438 ->tag('secondary')
439 ->setFormAction( $to )
440 ;
441 $ret['draft'] = $btnDraft;
442 }
443
444 // publish
445 $to = array( 'new', $calendarId, $shiftTypeId, $dateString, $employeeString, 'publish' );
446 $to = join( '/', $to );
447 $label = $noDraft ? '__Post Shift__' : '__Create Published__';
448
449 $btnPublish = $this->ui->makeInputSubmit( $label )
450 ->tag('primary')
451 ->setFormAction( $to )
452 ;
453 $ret['publish'] = $btnPublish;
454
455 return $ret;
456 }
457
458 public function header()
459 {
460 $out = '__Confirm__';
461 return $out;
462 }
463 }