PluginProbe
ShiftController Employee Shift Scheduling / 4.9.84
ShiftController Employee Shift Scheduling v4.9.84
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 / hc3 / ui.php

ui.php in ShiftController Employee Shift Scheduling 4.9.84, at hc3/ui.php

589 lines 15.5 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 HC3_Ui_
3 {
4 public function helperActionsFromArray( array $menu, $hidden = FALSE );
5
6 public function makeBlock( $content = NULL );
7 public function makeBlockInline( $content = NULL );
8 public function makeLongText( $content, $length = 40 );
9 public function makePager( $toSlug, $totalCount, $perPage, $currentPage = 1 );
10 public function makeSpan( $content = NULL );
11 public function makeList( array $items = array() );
12 public function makeListInline( array $items = array() );
13 public function makeGrid( array $items = array(), $itemWidth = NULL );
14 public function makeH( $level, $content );
15 public function makeTable( $header = NULL, array $rows = array(), $striped = TRUE );
16 public function makeAhref( $to, $label = NULL );
17 public function makeCollapse( $label, $content, $expand = FALSE );
18 public function makeCollapseCheckbox( $name, $label, $content, $expand = FALSE );
19 public function makeLabelled( $label, $content, $labelFor = NULL );
20 public function makeLabelledInline( $label, $content, $labelFor = NULL );
21 public function makeLabelledHori( $label, $content, $labelFor = NULL );
22
23 public function makeHeadered( $header, $content );
24
25 public function makeNumber( $number, $digits = 2 );
26 public function makePercent( $number, $digits = 0 );
27
28 public function makeForm( $action, $content = NULL );
29 public function makeInputText( $name, $label = NULL, $value = NULL );
30 public function makeInputPassword( $name, $label = NULL );
31 public function makeInputTextarea( $name, $label = NULL, $value = NULL );
32 public function makeInputRichTextarea( $name, $label = NULL, $value = NULL );
33 public function makeInputCheckbox( $name, $label = NULL, $value = NULL, $checked = FALSE );
34 public function makeInputRadio( $name, $label = NULL, $value = NULL, $checked = FALSE );
35 public function makeInputHidden( $name, $value = NULL );
36 public function makeInputColorpicker( $name, $label, $value = NULL );
37 public function makeInputDatepicker( $name, $label = NULL, $value = NULL );
38 public function makeInputTime( $name, $label = NULL, $value = NULL );
39 public function makeInputTimerange( $name, $label, $value = array() );
40 public function makeInputSelect( $name, $label, $options = array(), $value = NULL );
41 public function makeInputRadioSet( $name, $label, $options = array(), $value = NULL );
42 public function makeInputCheckboxSet( $name, $label = NULL, $options = array(), $value = array() );
43 public function makeInputSubmit( $label, $alt = NULL );
44 public function makeInputButton( $label, $alt = NULL );
45 }
46
47 class HC3_Ui implements HC3_Ui_
48 {
49 public $t, $settings, $request, $enqueuer;
50
51 public function __construct(
52 HC3_Request $request,
53 HC3_Enqueuer $enqueuer,
54 HC3_Time $t,
55 HC3_Settings $settings
56 )
57 {
58 $this->t = $t;
59 $this->settings = $settings;
60 $this->request = $request;
61 $this->enqueuer = $enqueuer;
62 }
63
64 public function helperActionsFromArray( array $menu, $hidden = FALSE )
65 {
66 $return = array();
67
68 foreach( $menu as $k => $item ){
69 // form
70 if( count($item) >= 3 ){
71 $href = $item[0];
72 $formContent = $item[1];
73 $btnLabel = $item[2];
74
75 $confirm = ( isset($item[3]) && $item[3] ) ? true : false;
76
77 if( ! $hidden ){
78 $btn = $this->makeInputSubmit($btnLabel)
79 ->tag('nice-link')
80 // ->tag('secondary')
81 // ->tag('align', 'left')
82 ;
83
84 if( $confirm ){
85 $btn->addAttr( 'onclick', ' return confirm(\'' . $btnLabel . '?\')' );
86 }
87
88 $formContent = $formContent ? $this->makeListInline( array($formContent, $btn) ) : $btn;
89 }
90
91 $item = $this->makeForm( $href, $formContent );
92 if( ! $item ){
93 continue;
94 }
95 }
96 // link
97 else {
98 // if( $hidden ){
99 // continue;
100 // }
101 list( $href, $btnLabel ) = $item;
102
103 if( is_array($href) ){
104 $finalHref = str_replace( '--ID--', $href[1], $href[0] );
105 }
106 else {
107 $finalHref = $href;
108 }
109
110 $item = $this->makeAhref( $finalHref, $btnLabel );
111 if( ! $item ){
112 continue;
113 }
114
115 // for bulk actions
116 if( $hidden ){
117 if( ! is_array($href) ){
118 continue;
119 }
120
121 $item
122 ->addAttr('style', 'display:none;')
123 ->addAttr('data-href', $href[0])
124 ->addAttr('data-href-id', $href[1])
125 ;
126 }
127 else {
128 $item
129 ->tag('nice-link')
130 // ->tag('tab-link')
131 ->tag('align', 'left')
132 ;
133 }
134 }
135
136 $item
137 ->addAttr( 'data-action-key', $k )
138 ->addAttr( 'data-action-label', $btnLabel )
139 ;
140
141 $return[ $k ] = $item;
142 }
143
144 return $return;
145 }
146
147 public function makePercent( $number, $digits = 2, $arrowChange = FALSE )
148 {
149 $return = $number * 100;
150 if( $arrowChange && ($number < 0) ){
151 $return = - $return;
152 }
153
154 $return = number_format( $return, $digits );
155
156 if( $arrowChange ){
157 if( $number > 0 ){
158 $return = '&uarr;' . $return;
159 }
160 else {
161 $return = '&darr;' . $return;
162 }
163 }
164 else {
165 if( $number > 0 ){
166 $return = '+' . $return;
167 }
168 }
169
170 $return .= '%';
171
172 $return = $this->makeSpan( $return );
173 if( $number > 0 ){
174 $return->tag('color', 'olive');
175 }
176 elseif( $number < 0 ) {
177 $return->tag('color', 'maroon');
178 }
179
180 return $return;
181 }
182
183 public function makeNumber( $number, $digits = 2, $arrowChange = FALSE )
184 {
185 $return = $number;
186 if( $arrowChange && ($number < 0) ){
187 $return = - $return;
188 }
189
190 $return = number_format( $return, $digits );
191
192 if( $arrowChange ){
193 if( $number > 0 ){
194 $return = '&uarr;' . $return;
195 }
196 else {
197 $return = '&darr;' . $return;
198 }
199 }
200 else {
201 if( $number > 0 ){
202 $return = '+' . $return;
203 }
204 }
205
206 $return = $this->makeSpan( $return );
207 if( $number > 0 ){
208 $return->tag('color', 'olive');
209 }
210 elseif( $number < 0 ) {
211 $return->tag('color', 'maroon');
212 }
213
214 return $return;
215 }
216
217 public function makePager( $toSlug, $totalCount, $perPage, $currentPage = 1 )
218 {
219 $return = new HC3_Ui_Element_Pager( $this, $toSlug, $totalCount, $perPage, $currentPage );
220 return $return;
221 }
222
223 public function makeElement( $el, $content = NULL )
224 {
225 $return = new HC3_Ui_Element_Element( $el, $content );
226 return $return;
227 }
228
229 public function makeLongText( $content = '', $length = 40 )
230 {
231 if( null === $content ) $content = '';
232 $contentView = $content;
233
234 $shortContentView = $contentView;
235 if( strlen($contentView) > $length ){
236 $shortContentView = substr($contentView, 0, $length) . '...';
237 }
238
239 if( strlen($contentView) > $length ){
240 $contentView = $this->makeCollapse( $shortContentView, $contentView )
241 ->arrow( NULL )
242 ->hideToggle()
243 ;
244 }
245
246 $contentView = $this->makeBlock( $contentView )
247 ->tag('font-style', 'italic')
248 ->tag('font-size', 2)
249 ;
250
251 return $contentView;
252 }
253
254 public function makeBlock( $content = NULL )
255 {
256 $return = $this->makeElement('div', $content);
257 return $return;
258 }
259
260 public function makeSpan( $content = NULL )
261 {
262 $return = $this->makeElement('span', $content);
263 return $return;
264 }
265
266 public function makeCollapse( $label, $content, $expand = FALSE )
267 {
268 $return = new HC3_Ui_Element_Collapse( $this, $label, $content, $expand );
269 return $return;
270 }
271
272 public function makeCollapseCheckbox( $name, $label, $content, $expand = FALSE )
273 {
274 $return = new HC3_Ui_Element_CollapseCheckbox( $this, $name, $label, $content, $expand );
275 return $return;
276 }
277
278 public function makeLabelled( $label, $content, $labelFor = NULL )
279 {
280 $return = new HC3_Ui_Element_Labelled( $this, $label, $content, $labelFor );
281 return $return;
282 }
283
284 public function makeHeadered( $header, $content )
285 {
286 $header = $this->makeBlock( $header )
287 ->tag('font-size', 4)
288 ->tag('padding', 'b1')
289 ->tag('border', 'bottom')
290 ->tag('border-color', 'lightgray')
291 ;
292
293 $out = $this->makeList( array($header, $content) )
294 ->gutter(2)
295 ;
296
297 return $out;
298 }
299
300 public function makeLabelledInline( $label, $content, $labelFor = NULL )
301 {
302 $return = new HC3_Ui_Element_LabelledInline( $this, $label, $content, $labelFor );
303 return $return;
304 }
305
306 public function makeLabelledHori( $label, $content, $labelFor = NULL )
307 {
308 $return = new HC3_Ui_Element_LabelledHori( $this, $label, $content, $labelFor );
309 return $return;
310 }
311
312 public function makeBlockInline( $content = NULL )
313 {
314 $return = $this->makeElement('div', $content)
315 ->addAttr('class', 'hc-inline-block')
316 ;
317 return $return;
318 }
319
320 public function makeList( array $items = array() )
321 {
322 $return = new HC3_Ui_Element_List( $this, $items );
323 return $return;
324 }
325
326 public function makeCollection( array $items = array() )
327 {
328 $return = new HC3_Ui_Element_Collection( $items );
329 return $return;
330 }
331
332 public function makeListInline( array $items = array() )
333 {
334 $return = new HC3_Ui_Element_ListInline( $this, $items );
335 return $return;
336 }
337
338 public function makeGrid( array $items = array(), $itemWidth = NULL )
339 {
340 $return = new HC3_Ui_Element_Grid( $this, $items, $itemWidth );
341 return $return;
342 }
343
344 public function makeH( $level, $content )
345 {
346 $return = new HC3_Ui_Element_H( $level, $content );
347 return $return;
348 }
349
350 public function makeTable( $header = NULL, array $rows = array(), $striped = TRUE )
351 {
352 $return = new HC3_Ui_Element_Table( $this, $header, $rows );
353 if( ! $striped ){
354 $return->setStriped( FALSE );
355 }
356 return $return;
357 }
358
359 public function makeForm( $action, $content = NULL )
360 {
361 $return = new HC3_Ui_Element_Form( $this, $action, $content );
362 return $return;
363 }
364
365 public function makeInputText( $name, $label = NULL, $value = NULL )
366 {
367 $return = new HC3_Ui_Element_Input_Text( $this, $name, $label, $value );
368 return $return;
369 }
370
371 public function makeInputNumber( $name, $label = NULL, $value = NULL )
372 {
373 $return = new HC3_Ui_Element_Input_Number( $this, $name, $label, $value );
374 return $return;
375 }
376
377 public function makeInputPassword( $name, $label = NULL )
378 {
379 $return = new HC3_Ui_Element_Input_Password( $this, $name, $label );
380 return $return;
381 }
382
383 public function makeInputRichtextarea( $name, $label = NULL, $value = NULL )
384 {
385 $return = new HC3_Ui_Element_Input_RichTextarea( $this, $name, $label, $value );
386 return $return;
387 }
388
389 public function makeInputTextarea( $name, $label = NULL, $value = NULL )
390 {
391 $return = new HC3_Ui_Element_Input_Textarea( $this, $name, $label, $value );
392 return $return;
393 }
394
395 public function makeInputCheckbox( $name, $label = NULL, $value = NULL, $checked = FALSE )
396 {
397 $return = new HC3_Ui_Element_Input_Checkbox( $this, $name, $label, $value, $checked );
398 return $return;
399 }
400
401 public function makeInputRadio( $name, $label = NULL, $value = NULL, $checked = FALSE )
402 {
403 $return = new HC3_Ui_Element_Input_Radio( $this, $name, $label, $value, $checked );
404 return $return;
405 }
406
407 public function makeInputHidden( $name, $value = NULL )
408 {
409 $return = new HC3_Ui_Element_Input_Hidden( $this, $name, $value );
410 return $return;
411 }
412
413 public function makeInputColorpicker( $name, $label, $value = NULL )
414 {
415 if( ! $this->request->isPrintView() ){
416 $this->enqueuer
417 ->addScript('colorpicker', 'hc3/ui/element/input/colorpicker/assets/input.js?hcver=' . SH4_VERSION);
418 ;
419 }
420 $return = new HC3_Ui_Element_Input_Colorpicker( $this, $name, $label, $value );
421 return $return;
422 }
423
424 public function makeInputDatepicker( $name, $label = NULL, $value = NULL )
425 {
426 if( ! $this->request->isPrintView() ){
427 $this->enqueuer
428 ->addScript('datepicker', 'hc3/ui/element/input/datepicker/assets/input.js?hcver=' . SH4_VERSION)
429 ->addStyle('datepicker', 'hc3/ui/element/input/datepicker/assets/input.css?hcver=' . SH4_VERSION)
430 ;
431 }
432
433 if( $value === NULL ){
434 $this->t->setNow();
435 $value = $this->t->formatDateDb();
436 }
437 else {
438 $this->t->setDateDb( $value );
439 }
440
441 $date_format = $this->t->formatToDatepicker();
442 $value_formatted = $this->t->formatDate();
443 $week_starts_on = $this->t->weekStartsOn;
444
445 $return = new HC3_Ui_Element_Input_Datepicker(
446 $this,
447 $name,
448 $label,
449 $value,
450 $value_formatted,
451 $date_format,
452 $week_starts_on
453 );
454 return $return;
455 }
456
457 public function makeInputSubmit( $label, $name = NULL, $alt = NULL )
458 {
459 $return = new HC3_Ui_Element_Input_Submit( $this, $label, $name, $alt );
460 return $return;
461 }
462
463 public function makeInputButton( $label, $name = NULL, $alt = NULL )
464 {
465 $return = new HC3_Ui_Element_Input_Button( $label, $name, $alt );
466 return $return;
467 }
468
469 public function makeAhref( $to, $label = NULL )
470 {
471 $return = new HC3_Ui_Element_Ahref( $to, $label );
472 return $return;
473 }
474
475 public function makeInputSelect( $name, $label, $options = array(), $value = NULL )
476 {
477 $return = new HC3_Ui_Element_Input_Select( $this, $name, $label, $options, $value );
478 return $return;
479 }
480
481 public function makeInputRadioSet( $name, $label, $options = array(), $value = NULL )
482 {
483 $return = new HC3_Ui_Element_Input_RadioSet( $this, $name, $label, $options, $value );
484 return $return;
485 }
486
487 public function makeInputCheckboxSet( $name, $label = NULL, $options = array(), $value = array() )
488 {
489 $return = new HC3_Ui_Element_Input_CheckboxSet( $this, $name, $label, $options, $value );
490 return $return;
491 }
492
493 public function makeInputTimeRange( $name, $label, $value = array(), $noLimit = FALSE )
494 {
495 $timeFormatOptions = array();
496
497 $startWith = 0;
498 $endWith = 24 * 60 * 60;
499
500 // $noLimit = TRUE;
501 if( ! $noLimit ){
502 $minTime = $this->settings->get('datetime_min_time');
503 if( $minTime ){
504 $startWith = $minTime;
505 }
506 }
507
508 if( ! $noLimit ){
509 $maxTime = $this->settings->get('datetime_max_time');
510 if( $maxTime ){
511 $endWith = $maxTime;
512 }
513 }
514
515 if( $endWith < $startWith ){
516 $endWith = $startWith;
517 }
518
519 $this->t->setDateDb( 20180102 );
520 if( $startWith ){
521 $this->t->modify( '+' . $startWith . ' seconds' );
522 }
523
524 $step = $this->settings->get('datetime_step');
525 if( ! $step ){
526 $step = 5 * 60;
527 }
528
529 $noOfSteps = ( $endWith - $startWith) / $step;
530 for( $ii = 0; $ii <= $noOfSteps; $ii++ ){
531 $sec = $startWith + $ii * $step;
532 $timeFormatOptions[ $sec ] = $this->t->formatTime();
533 $this->t->modify( '+' . $step . ' seconds' );
534 }
535
536 $return = new HC3_Ui_Element_Input_TimeRange( $this, $name, $label, $timeFormatOptions, $value );
537 return $return;
538 }
539
540 public function makeInputTime( $name, $label = NULL, $value = 0, $noLimit = FALSE )
541 {
542 $timeFormatOptions = array();
543
544 $startWith = 0;
545 $endWith = 24 * 60 * 60;
546
547 if( ! $noLimit ){
548 $minTime = $this->settings->get('datetime_min_time');
549 if( $minTime ){
550 $startWith = $minTime;
551 }
552 }
553
554 if( ! $noLimit ){
555 $maxTime = $this->settings->get('datetime_max_time');
556 if( $maxTime ){
557 $endWith = $maxTime;
558 }
559 }
560
561 if( $endWith < $startWith ){
562 $endWith = $startWith;
563 }
564
565 $this->t->setDateDb( 20180102 );
566 if( $startWith ){
567 $this->t->modify( '+' . $startWith . ' seconds' );
568 }
569
570 $step = $this->settings->get('datetime_step');
571 if( ! $step ){
572 $step = 5 * 60;
573 }
574
575 // value to nearest step
576 $value = ceil( $value / $step ) * $step;
577
578 $noOfSteps = ( $endWith - $startWith) / $step;
579 for( $ii = 0; $ii <= $noOfSteps; $ii++ ){
580 $sec = $startWith + $ii * $step;
581 $timeFormatOptions[ $sec ] = $this->t->formatTime();
582 $this->t->modify( '+' . $step . ' seconds' );
583 }
584
585 $return = new HC3_Ui_Element_Input_Select( $this, $name, $label, $timeFormatOptions, $value );
586 return $return;
587 }
588 }
589