PluginProbe
ShiftController Employee Shift Scheduling / 4.9.85
ShiftController Employee Shift Scheduling v4.9.85
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 / schedule / html / view / controldates.php

controldates.php in ShiftController Employee Shift Scheduling 4.9.85, at sh4/schedule/html/view/controldates.php

403 lines 11.4 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_Schedule_Html_View_ControlDates
4 {
5 public function __construct(
6 HC3_Hooks $hooks,
7 HC3_Ui $ui,
8 HC3_Request $request,
9 HC3_Time $t,
10 HC3_Settings $settings
11 )
12 {
13 $this->self = $hooks->wrap( $this );
14
15 $this->ui = $ui;
16 $this->request = $request;
17 $this->t = $t;
18
19 $this->settings = $hooks->wrap( $settings );
20 }
21
22 public function render()
23 {
24 $out = NULL;
25
26 $params = $this->request->getParams();
27 $type = $params['type'];
28
29 switch( $type ){
30 case 'month':
31 $out = $this->self->renderMonth();
32 break;
33 case '4weeks':
34 $out = $this->self->renderFourWeeks();
35 break;
36 case '2weeks':
37 $out = $this->self->renderTwoWeeks();
38 break;
39 case 'week':
40 $out = $this->self->renderWeek();
41 break;
42 case 'day':
43 $out = $this->self->renderDay();
44 break;
45 default:
46 $out = $this->self->renderCustom();
47 break;
48 }
49
50 return $out;
51 }
52
53 public function renderCustom()
54 {
55 $slug = $this->request->getRealSlug();
56 $params = $this->request->getParams();
57 if( isset($params['time']) && ('now' == $params['time']) ){
58 $params['time'] = $this->t->setNow()->formatDateTimeDb();
59 }
60
61 // date selection
62 $timeInDay = 0;
63 $exactStartDate = NULL;
64 if( array_key_exists('time', $params) ){
65 $time = $params['time'];
66 $startDate = $this->t->setDateTimeDb( $params['time'] )->formatDateDb();
67 $timeInDay = $this->t->getTimeInDay();
68 $exactStartDate = $startDate;
69 }
70 elseif( array_key_exists('start', $params) ){
71 $startDate = $params['start'];
72 }
73 else {
74 $startDate = $this->t->setNow()->setStartDay()->formatDateDb();
75 }
76
77 if( 'start-week' == $startDate ){
78 $this->t->setNow()->setStartWeek();
79 $startDate = $this->t->formatDateDb();
80 }
81 elseif( 'start-month' == $startDate ){
82 $this->t->setNow()->setStartMonth();
83 $startDate = $this->t->formatDateDb();
84 }
85 elseif( 'start-year' == $startDate ){
86 $this->t->setNow()->setStartYear();
87 $startDate = $this->t->formatDateDb();
88 }
89 else {
90 if( (FALSE !== strpos($startDate, '+')) OR (FALSE !== strpos($startDate, '-')) ){
91 $this->t->setNow()->setStartDay()->modify($startDate);
92 $startDate = $this->t->formatDateDb();
93 }
94 }
95
96 if( ! $timeInDay ){
97 $timeInDay = $this->t->setNow()->getTimeInDay();
98 $exactStartDate = $this->t->setNow()->formatDateDb();
99 }
100
101 if( array_key_exists('time', $params) ){
102 $endDate = $startDate;
103 }
104 elseif( array_key_exists('end', $params) ){
105 $endDate = $params['end'];
106 }
107 else {
108 $endDate = $this->t->modify('+1 week')->modify('-1 day')->formatDateDb();
109 }
110
111 if( FALSE !== strpos($endDate, '+') ){
112 $this->t->setDateDb($startDate)->modify($endDate)->modify('-1 day')->setEndDay();
113 $endDate = $this->t->formatDateDb();
114 }
115
116 if( isset($params['time']) ){
117 $this->t->setDateTimeDb( $params['time'] );
118 $label = $this->t->formatDateWithWeekday() . ' ' . $this->t->formatTime();
119 }
120 else {
121 $label = $this->t->formatDateRange( $startDate, $endDate );
122 }
123
124 $label = $this->ui->makeBlock( $label )
125 ->tag('font-size', 5)
126 ;
127
128 $hideui = isset( $params['hideui'] ) ? $params['hideui'] : array();
129 if( ! array_intersect(array('date-nav', 'all'), $hideui) ){
130 $quickJumpForm = $this->ui->makeForm(
131 $slug . '/dates',
132 $this->ui->makeListInline()
133 ->add( $this->ui->makeInputDatepicker( 'start', NULL, $startDate ) )
134 ->add( '-' )
135 ->add( $this->ui->makeInputDatepicker( 'end', NULL, $endDate ) )
136 ->add( $this->ui->makeInputSubmit( '&rarr;')->tag('primary') )
137 );
138
139 $exactTimeForm = $this->ui->makeForm(
140 $slug . '/exacttime',
141 $this->ui->makeListInline()
142 ->add( $this->ui->makeInputDatepicker( 'date', NULL, $exactStartDate ) )
143 ->add( $this->ui->makeInputTime( 'time', NULL, $timeInDay ) )
144 ->add( $this->ui->makeInputSubmit( '&rarr;')->tag('primary') )
145 );
146
147 $quickJumpForm = $this->ui->makeList( array('__Date Range__', $quickJumpForm, '__Exact Time__', $exactTimeForm) );
148
149 $quickJumpForm = $this->ui->makeCollapse( $label, $quickJumpForm );
150 $out = $quickJumpForm;
151 }
152 else {
153 $out = $label;
154 }
155
156 return $out;
157 }
158
159 public function renderWeek()
160 {
161 $slug = $this->request->getRealSlug();
162
163 $params = $this->request->getParams('withoutDefault');
164 $params['end'] = NULL;
165
166 $startDate = $params['start'];
167
168 $this->t->setDateDb($startDate)->setStartWeek();
169 $next = $this->t->modify('+1 week')->formatDateDb();
170 $prev = $this->t->modify('-2 weeks')->formatDateDb();
171
172 $thisParams = $params;
173 $thisParams['start'] = $next;
174 $nextLink = $this->ui->makeAhref( array($slug, $thisParams), '__Next__' . '&nbsp;&raquo;' )
175 ->tag('secondary')
176 ->tag('block')
177 ->tag('align', 'center')
178 ;
179
180 $thisParams = $params;
181 $thisParams['start'] = $prev;
182 $prevLink = $this->ui->makeAhref( array($slug, $thisParams), '&laquo;&nbsp;' . '__Previous__' )
183 ->tag('secondary')
184 ->tag('block')
185 ->tag('align', 'center')
186 ;
187
188 // label
189 $this->t->setDateDb( $startDate );
190 $this->t->modify('+1 week')->modify('-1 day');
191 $endDate = $this->t->formatDateDb();
192 $label = $this->t->formatDateRange( $startDate, $endDate );
193
194 $weekNo = $this->t->getWeekNo();
195 $label .= ' [' . '__Week__' . ' #' . $weekNo . ']';
196 $out = $this->self->finalizeLabel( $label, $startDate, $prevLink, $nextLink );
197
198 return $out;
199 }
200
201 public function renderDay()
202 {
203 $slug = $this->request->getRealSlug();
204 $params = $this->request->getParams('withoutDefault');
205
206 $params['end'] = NULL;
207
208 $startDate = $params['start'];
209
210 $this->t->setDateDb($startDate);
211
212 $daysToShow = isset( SH4_Schedule_Html_View_Day::$daysToShow ) ? SH4_Schedule_Html_View_Day::$daysToShow : 7;
213
214 $next = $this->t->modify( '+' . $daysToShow . ' days' )->formatDateDb();
215 $prev = $this->t->modify( '-' . 2 * $daysToShow . ' days' )->formatDateDb();
216
217 $thisParams = $params;
218 $thisParams['start'] = $next;
219 $nextLink = $this->ui->makeAhref( array($slug, $thisParams), '__Next__' . '&nbsp;&raquo;' )
220 ->tag('secondary')
221 ->tag('block')
222 ->tag('align', 'center')
223 ;
224
225 $thisParams = $params;
226 $thisParams['start'] = $prev;
227 $prevLink = $this->ui->makeAhref( array($slug, $thisParams), '&laquo;&nbsp;' . '__Previous__' )
228 ->tag('secondary')
229 ->tag('block')
230 ->tag('align', 'center')
231 ;
232
233 // label
234 // $this->t->setDateDb( $startDate );
235 // $label = $this->t->getWeekdayName() . ', ' . $this->t->formatDate();
236
237 $this->t->setDateDb( $startDate );
238 $this->t->modify( '+' . $daysToShow . ' days' )->modify('-1 day');
239
240 $endDate = $this->t->formatDateDb();
241 $label = $this->t->formatDateRange( $startDate, $endDate );
242 $out = $this->self->finalizeLabel( $label, $startDate, $prevLink, $nextLink );
243
244 return $out;
245 }
246
247 public function renderMonth()
248 {
249 $slug = $this->request->getRealSlug();
250 $params = $this->request->getParams('withoutDefault');
251
252 $params['end'] = NULL;
253
254 $startDate = $params['start'];
255
256 $this->t->setDateDb($startDate)->setStartMonth();
257 $next = $this->t->modify('+1 month')->formatDateDb();
258 $prev = $this->t->modify('-2 months')->formatDateDb();
259
260 $thisParams = $params;
261 $thisParams['start'] = $next;
262 $nextLink = $this->ui->makeAhref( array($slug, $thisParams), '__Next__' . '&nbsp;&raquo;' )
263 ->tag('secondary')
264 ->tag('block')
265 ->tag('align', 'center')
266 ;
267
268 $thisParams = $params;
269 $thisParams['start'] = $prev;
270 $prevLink = $this->ui->makeAhref( array($slug, $thisParams), '&laquo;&nbsp;' . '__Previous__' )
271 ->tag('secondary')
272 ->tag('block')
273 ->tag('align', 'center')
274 ;
275
276 // label
277
278 $this->t->setDateDb( $startDate );
279 $label = array();
280 $label[] = $this->t->getMonthName();
281 $label[] = $this->t->getYear();
282 $label = join(' ', $label);
283 $out = $this->self->finalizeLabel( $label, $startDate, $prevLink, $nextLink );
284
285 return $out;
286 }
287
288 public function renderFourWeeks()
289 {
290 $slug = $this->request->getRealSlug();
291 $params = $this->request->getParams('withoutDefault');
292 $nWeeks = $this->settings->get( 'datetime_n_weeks' );
293 if( ! $nWeeks ) $nWeeks = 4;
294
295 $params['end'] = NULL;
296
297 $startDate = $params['start'];
298 $endDate = $this->t->setDateDb($startDate)->setStartWeek()->modify('+' . $nWeeks . ' weeks')->modify('-1 day')->formatDateDb();
299
300 $this->t->setDateDb($startDate)->setStartWeek();
301 $next = $this->t->modify('+' . $nWeeks . ' weeks')->formatDateDb();
302 $prev = $this->t->modify('-' . 2 * $nWeeks . ' weeks')->formatDateDb();
303
304 $thisParams = $params;
305 $thisParams['start'] = $next;
306 $nextLink = $this->ui->makeAhref( array($slug, $thisParams), '__Next__' . '&nbsp;&raquo;' )
307 ->tag('secondary')
308 ->tag('block')
309 ->tag('align', 'center')
310 ;
311
312 $thisParams = $params;
313 $thisParams['start'] = $prev;
314 $prevLink = $this->ui->makeAhref( array($slug, $thisParams), '&laquo;&nbsp;' . '__Previous__' )
315 ->tag('secondary')
316 ->tag('block')
317 ->tag('align', 'center')
318 ;
319
320 // label
321 $this->t->setDateDb( $startDate );
322 $label = $this->t->formatDateRange( $startDate, $endDate );
323 $out = $this->self->finalizeLabel( $label, $startDate, $prevLink, $nextLink );
324
325 return $out;
326 }
327
328 public function renderTwoWeeks()
329 {
330 $slug = $this->request->getRealSlug();
331 $params = $this->request->getParams('withoutDefault');
332
333 $params['end'] = NULL;
334
335 $startDate = $params['start'];
336 $endDate = $this->t->setDateDb($startDate)->setStartWeek()->modify('+2 weeks')->modify('-1 day')->formatDateDb();
337
338 $this->t->setDateDb($startDate)->setStartWeek();
339 $next = $this->t->modify('+2 weeks')->formatDateDb();
340 $prev = $this->t->modify('-4 weeks')->formatDateDb();
341
342 $thisParams = $params;
343 $thisParams['start'] = $next;
344 $nextLink = $this->ui->makeAhref( array($slug, $thisParams), '__Next__' . '&nbsp;&raquo;' )
345 ->tag('secondary')
346 ->tag('block')
347 ->tag('align', 'center')
348 ;
349
350 $thisParams = $params;
351 $thisParams['start'] = $prev;
352 $prevLink = $this->ui->makeAhref( array($slug, $thisParams), '&laquo;&nbsp;' . '__Previous__' )
353 ->tag('secondary')
354 ->tag('block')
355 ->tag('align', 'center')
356 ;
357
358 // label
359 $this->t->setDateDb( $startDate );
360 $label = $this->t->formatDateRange( $startDate, $endDate );
361 $out = $this->self->finalizeLabel( $label, $startDate, $prevLink, $nextLink );
362
363 return $out;
364 }
365
366 public function finalizeLabel( $label, $startDate, $prevLink, $nextLink )
367 {
368 $params = $this->request->getParams();
369 $slug = $this->request->getRealSlug();
370
371 $label = $this->ui->makeBlock( $label )
372 ->tag('font-size', 5)
373 ;
374
375 $hideui = isset( $params['hideui'] ) ? $params['hideui'] : array();
376 if( ! array_intersect(array('date-nav', 'all'), $hideui) ){
377 $quickJumpForm = $this->ui->makeForm(
378 $slug . '/dates',
379 $this->ui->makeListInline()
380 ->add( $this->ui->makeInputDatepicker( 'start', NULL, $startDate ) )
381 ->add(
382 $this->ui->makeInputSubmit( '&rarr;' )
383 ->tag('primary')
384 ->tag('block')
385 )
386 ->gutter(1)
387 );
388
389 $quickJumpForm = $this->ui->makeCollapse( $label, $quickJumpForm );
390 $controls = $this->ui->makeGrid( array($prevLink, $nextLink) );
391
392 $ret = $this->ui->makeGrid()
393 ->add( $quickJumpForm, 8, 12 )
394 ->add( $controls, 4, 12 )
395 ;
396 }
397 else {
398 $ret = $label;
399 }
400
401 return $ret;
402 }
403 }