PluginProbe
ShiftController Employee Shift Scheduling / 4.9.95
ShiftController Employee Shift Scheduling v4.9.95
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.95, at sh4/new/view/date.php

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