PluginProbe
ShiftController Employee Shift Scheduling / 4.9.59
ShiftController Employee Shift Scheduling v4.9.59
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.59, at hc3/ui.php

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