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 / view / date.php

date.php in ShiftController Employee Shift Scheduling 4.9.26, at sh4/new/view/date.php

452 lines 11.0 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_New_View_IDate
3 {
4 public function render();
5 public function ajaxRender();
6 public function ajaxRenderHours();
7 public function renderHours();
8 public function renderStartDate();
9 public function renderEndDate( $startDate );
10 public function buttons( $calendarId, $shiftTypeId );
11 }
12
13 class SH4_New_View_Date implements SH4_New_View_IDate
14 {
15 public function __construct(
16 HC3_Hooks $hooks,
17 HC3_Request $request,
18 HC3_Ui $ui,
19 HC3_Time $t,
20 HC3_Ui_Layout1 $layout,
21 HC3_Settings $settings,
22
23 SH4_New_View_Common $common,
24
25 SH4_Calendars_Query $calendarsQuery,
26 SH4_ShiftTypes_Query $shiftTypesQuery
27 )
28 {
29 $this->request = $request;
30 $this->ui = $ui;
31 $this->t = $t;
32 $this->layout = $layout;
33
34 $this->settings = $hooks->wrap( $settings );
35
36 $this->calendarsQuery = $hooks->wrap( $calendarsQuery );
37 $this->shiftTypesQuery = $hooks->wrap( $shiftTypesQuery );
38 $this->common = $hooks->wrap($common);
39
40 $this->self = $hooks->wrap($this);
41 }
42
43 public function render()
44 {
45 $params = $this->request->getParams();
46
47 $shiftTypeId = $params['shifttype'];
48 $calendarId = $params['calendar'];
49
50 $shiftType = $this->shiftTypesQuery->findByid( $shiftTypeId );
51 $range = $shiftType->getRange();
52
53 switch( $range ){
54 case SH4_ShiftTypes_Model::RANGE_DAYS:
55 if( array_key_exists('start', $params) && $params['start'] ){
56 $out = $this->self->renderEndDate( $params['start'] );
57 $pageHeader = '__Select End Date__';
58 }
59 else {
60 $out = $this->self->renderStartDate();
61 $pageHeader = '__Select Start Date__';
62 }
63 break;
64
65 case SH4_ShiftTypes_Model::RANGE_HOURS:
66 $out = $this->self->renderHours();
67 $pageHeader = '__Select Date__';
68 break;
69 }
70
71 $disabledWeekdays = $this->settings->get( 'skip_weekdays', TRUE );
72
73 // $startDate = array_key_exists('date', $params) ? $params['date'] : $this->t->setNow()->formatDateDb();
74 // $this->t->setDateDb( $startDate);
75
76 $this->t->setStartWeek();
77 $header = array();
78 for( $ii = 0; $ii <= 6; $ii++ ){
79 if( $disabledWeekdays ){
80 $wkd = $this->t->getWeekday();
81 if( in_array($wkd, $disabledWeekdays) ){
82 $this->t->modify('+1 day');
83 continue;
84 }
85 }
86
87 $thisHeader = $this->t->getWeekdayName();
88 $thisHeader = $this->ui->makeBlock( $thisHeader )
89 // ->tag('font-size', 1)
90 ->tag('align', 'center')
91 ;
92 $header[] = $thisHeader;
93 $this->t->modify('+1 day');
94 }
95
96 $header = $this->ui->makeGrid( $header );
97
98 $out = $this->ui->makeList( array($header, $out) );
99
100 $this->layout
101 ->setContent( $out )
102 ->setBreadcrumb( $this->common->breadcrumb($calendarId, $shiftTypeId) )
103 ->setHeader( $pageHeader )
104 ;
105 $out = $this->layout->render();
106
107 return $out;
108 }
109
110 public function ajaxRender()
111 {
112 $params = $this->request->getParams();
113
114 $shiftTypeId = $params['shifttype'];
115 $calendarId = $params['calendar'];
116
117 $shiftType = $this->shiftTypesQuery->findByid( $shiftTypeId );
118 $range = $shiftType->getRange();
119
120 switch( $range ){
121 case SH4_ShiftTypes_Model::RANGE_DAYS:
122 if( array_key_exists('start', $params) && $params['start'] ){
123 $out = $this->self->renderEndDate( $params['start'] );
124 }
125 else {
126 $out = $this->self->renderStartDate();
127 }
128 break;
129
130 case SH4_ShiftTypes_Model::RANGE_HOURS:
131 $out = $this->self->renderHours();
132 break;
133 }
134
135 return $out;
136 }
137
138 public function ajaxRenderHours()
139 {
140 $out = $this->self->renderDates( $calendarId, $shiftTypeId, $employeeId );
141 return $out;
142 }
143
144 public function renderHours()
145 {
146 $disabledWeekdays = $this->settings->get( 'skip_weekdays', TRUE );
147
148 $params = $this->request->getParams();
149
150 $shiftTypeId = $params['shifttype'];
151 $calendarId = $params['calendar'];
152
153 $shiftType = $this->shiftTypesQuery->findByid( $shiftTypeId );
154 $calendar = $this->calendarsQuery->findByid( $calendarId );
155
156 $timeStart = $shiftType->getStart();
157 $timeEnd = $shiftType->getEnd();
158
159 $weeksToShow = 4;
160 $startDate = array_key_exists('date', $params) ? $params['date'] : $this->t->setNow()->formatDateDb();
161
162 $out = array();
163 $this->t->setDateDb( $startDate );
164 $this->t->setStartWeek();
165
166 for( $ww = 1; $ww <= $weeksToShow; $ww++ ){
167 $thisWeekView = array();
168
169 for( $dd = 0; $dd <= 6; $dd++ ){
170 $date = $this->t->formatDateDb();
171
172 if( $disabledWeekdays ){
173 $wkd = $this->t->getWeekday();
174 if( in_array($wkd, $disabledWeekdays) ){
175 $this->t->modify('+1 day');
176 continue;
177 }
178 }
179
180 $thisOn = FALSE;
181
182 $label = $this->t->formatDate();
183
184 $to = 'new';
185 $toParams = $params;
186 $toParams['date'] = $date;
187 $to = array( $to, $toParams );
188
189 $thisView = $this->ui->makeAhref( $to, $label )
190 ->tag('secondary')
191 ->tag('block')
192 ->tag('align', 'center')
193 ;
194
195 $thisWeekView[] = $thisView;
196
197 $this->t->setDateDb( $date );
198 $this->t->modify('+1 day');
199 }
200
201 $thisWeekView = $this->ui->makeGrid( $thisWeekView );
202 $out[] = $thisWeekView;
203
204 $lastDate = $date;
205 }
206
207 $out = $this->ui->makeList( $out );
208
209 $this->t->setDateDb( $lastDate );
210 $this->t->modify('+1 day');
211 $nextDate = $this->t->formatDateDb();
212
213 $nextTo = 'ajax/new/date';
214 $nextToParams = $params;
215 $nextToParams['date'] = $nextDate;
216 $nextTo = array( $nextTo, $nextToParams );
217
218 $nextLink = $this->ui->makeAhref( $nextTo, '&darr;' )
219 ->tag('ajax')
220 ->tag('secondary')
221 ->tag('block')
222 ->tag('padding', 2)
223 ;
224
225 $out = $this->ui->makeList( array($out, $nextLink) );
226 return $out;
227 }
228
229 public function renderStartDate()
230 {
231 $disabledWeekdays = $this->settings->get( 'skip_weekdays', TRUE );
232
233 $params = $this->request->getParams();
234
235 $shiftTypeId = $params['shifttype'];
236 $calendarId = $params['calendar'];
237
238 $shiftType = $this->shiftTypesQuery->findByid( $shiftTypeId );
239 $calendar = $this->calendarsQuery->findByid( $calendarId );
240
241 $weeksToShow = 4;
242 $startDate = array_key_exists('date', $params) ? $params['date'] : $this->t->setNow()->formatDateDb();
243
244 $out = array();
245 $this->t->setDateDb( $startDate );
246 $this->t->setStartWeek();
247
248 for( $ww = 1; $ww <= $weeksToShow; $ww++ ){
249 $thisWeekView = array();
250
251 for( $dd = 0; $dd <= 6; $dd++ ){
252 $date = $this->t->formatDateDb();
253
254 if( $disabledWeekdays ){
255 $wkd = $this->t->getWeekday();
256 if( in_array($wkd, $disabledWeekdays) ){
257 $this->t->modify('+1 day');
258 continue;
259 }
260 }
261
262 $thisOn = FALSE;
263
264 $label = $this->t->formatDate();
265
266 $to = 'new';
267 $toParams = $params;
268 $toParams['start'] = $date;
269 unset( $toParams['date'] );
270 $to = array( $to, $toParams );
271
272 $thisView = $this->ui->makeAhref( $to, $label )
273 ->tag('secondary')
274 ->tag('block')
275 ->tag('align', 'center')
276 ;
277
278 $thisWeekView[] = $thisView;
279
280 $this->t->setDateDb( $date );
281 $this->t->modify('+1 day');
282 }
283
284 $thisWeekView = $this->ui->makeGrid( $thisWeekView );
285 $out[] = $thisWeekView;
286
287 $lastDate = $date;
288 }
289
290 $out = $this->ui->makeList( $out );
291
292 $this->t->setDateDb( $lastDate );
293 $this->t->modify('+1 day');
294 $nextDate = $this->t->formatDateDb();
295
296 $nextTo = 'ajax/new/date';
297 $nextToParams = $params;
298 $nextToParams['date'] = $nextDate;
299 $nextTo = array( $nextTo, $nextToParams );
300
301 $nextLink = $this->ui->makeAhref( $nextTo, '&darr;' )
302 ->tag('ajax')
303 ->tag('secondary')
304 ->tag('block')
305 ->tag('padding', 2)
306 ;
307
308 $out = $this->ui->makeList( array($out, $nextLink) );
309 return $out;
310 }
311
312 public function renderEndDate( $startDate )
313 {
314 $disabledWeekdays = $this->settings->get( 'skip_weekdays', TRUE );
315
316 $params = $this->request->getParams();
317
318 $shiftTypeId = $params['shifttype'];
319 $calendarId = $params['calendar'];
320
321 $shiftType = $this->shiftTypesQuery->findByid( $shiftTypeId );
322 $calendar = $this->calendarsQuery->findByid( $calendarId );
323
324 $minDays = $shiftType->getStart();
325 $maxDays = $shiftType->getEnd();
326
327 $weeksToShow = 4;
328
329 $this->t->setDateDb( $startDate );
330
331 if( array_key_exists('from', $params) ){
332 $minDate = $params['from'];
333 }
334 else {
335 $minDate = $this->t->setDateDb( $startDate )
336 ->modify( '+' . $minDays . ' days' )
337 ->modify('-1 day')
338 ->formatDateDb()
339 ;
340 }
341
342 $maxDate = $this->t->setDateDb( $startDate )
343 ->modify( '+' . $maxDays . ' days' )
344 ->modify('-1 day')
345 ->formatDateDb()
346 ;
347
348 $out = array();
349 $this->t->setDateDb( $minDate );
350 $this->t->setStartWeek();
351
352 for( $ww = 1; $ww <= $weeksToShow; $ww++ ){
353 $thisWeekView = array();
354
355 for( $dd = 0; $dd <= 6; $dd++ ){
356 $date = $this->t->formatDateDb();
357
358 if( $disabledWeekdays ){
359 $wkd = $this->t->getWeekday();
360 if( in_array($wkd, $disabledWeekdays) ){
361 $this->t->modify('+1 day');
362 continue;
363 }
364 }
365
366 // $thisOn = ( $startDate == $date ) ? TRUE : FALSE;
367 $thisOn = FALSE;
368
369 $label = $this->t->formatDate();
370 if( ($date >= $minDate) && ($date <= $maxDate) ){
371 $dateString = HC3_Functions::glueArray( array($startDate, $date) );
372
373 $to = 'new';
374 $toParams = $params;
375 $toParams['date'] = $dateString;
376 $to = array( $to, $toParams );
377
378 $thisView = $this->ui->makeAhref( $to, $label )
379 ->tag('secondary')
380 ->tag('block')
381 ->tag('align', 'center')
382 ;
383 }
384 else {
385 if( $date == $startDate ){
386 $arrow = '&rarr;';
387 $label = $this->ui->makeListInline( array($label, $arrow) );
388 }
389 elseif( ($date < $startDate) OR ($date > $maxDate)){
390 $label = $this->ui->makeBlock( $label )
391 // ->tag('font-size', 2)
392 ->tag('muted', 3)
393 ;
394 }
395 $thisView = $this->ui->makeBlock( $label )
396 ->tag('border')
397 ->tag('padding', 1)
398 ->tag('block')
399 ->tag('align', 'center')
400 // ->tag('border-color', 'gray')
401 ;
402 }
403
404 $thisWeekView[] = $thisView;
405
406 $this->t->setDateDb( $date );
407 $this->t->modify('+1 day');
408 }
409
410 $thisWeekView = $this->ui->makeGrid( $thisWeekView );
411 $out[] = $thisWeekView;
412
413 $lastDate = $date;
414 if( $date >= $maxDate ){
415 break;
416 }
417 }
418
419 $out = $this->ui->makeList( $out );
420
421 if( $lastDate < $maxDate ){
422 $this->t->setDateDb( $lastDate );
423 $this->t->modify('+1 day');
424 $nextDate = $this->t->formatDateDb();
425
426 $nextTo = 'ajax/new/date';
427 $nextToParams = $params;
428 $nextToParams['from'] = $nextDate;
429 $nextTo = array( $nextTo, $nextToParams );
430
431 $nextLink = $this->ui->makeAhref( $nextTo, '&darr;' )
432 ->tag('ajax')
433 ->tag('secondary')
434 ->tag('block')
435 ->tag('padding', 2)
436 ;
437
438 $out = $this->ui->makeList( array($out, $nextLink) );
439 }
440 return $out;
441 }
442
443 public function buttons( $calendarId, $shiftTypeId, $employeeId = NULL )
444 {
445 $btn = $this->ui->makeInputSubmit( '__Continue__')
446 ->tag('primary')
447 ;
448
449 $return = array('continue' => $btn);
450 return $return;
451 }
452 }