PluginProbe
ShiftController Employee Shift Scheduling / 4.9.66
ShiftController Employee Shift Scheduling v4.9.66
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.66, at hc3/ui.php

583 lines 15.3 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 makeInputPassword( $name, $label = NULL )
372 {
373 $return = new HC3_Ui_Element_Input_Password( $this, $name, $label );
374 return $return;
375 }
376
377 public function makeInputRichtextarea( $name, $label = NULL, $value = NULL )
378 {
379 $return = new HC3_Ui_Element_Input_RichTextarea( $this, $name, $label, $value );
380 return $return;
381 }
382
383 public function makeInputTextarea( $name, $label = NULL, $value = NULL )
384 {
385 $return = new HC3_Ui_Element_Input_Textarea( $this, $name, $label, $value );
386 return $return;
387 }
388
389 public function makeInputCheckbox( $name, $label = NULL, $value = NULL, $checked = FALSE )
390 {
391 $return = new HC3_Ui_Element_Input_Checkbox( $this, $name, $label, $value, $checked );
392 return $return;
393 }
394
395 public function makeInputRadio( $name, $label = NULL, $value = NULL, $checked = FALSE )
396 {
397 $return = new HC3_Ui_Element_Input_Radio( $this, $name, $label, $value, $checked );
398 return $return;
399 }
400
401 public function makeInputHidden( $name, $value = NULL )
402 {
403 $return = new HC3_Ui_Element_Input_Hidden( $this, $name, $value );
404 return $return;
405 }
406
407 public function makeInputColorpicker( $name, $label, $value = NULL )
408 {
409 if( ! $this->request->isPrintView() ){
410 $this->enqueuer
411 ->addScript('colorpicker', 'hc3/ui/element/input/colorpicker/assets/input.js?hcver=' . SH4_VERSION);
412 ;
413 }
414 $return = new HC3_Ui_Element_Input_Colorpicker( $this, $name, $label, $value );
415 return $return;
416 }
417
418 public function makeInputDatepicker( $name, $label = NULL, $value = NULL )
419 {
420 if( ! $this->request->isPrintView() ){
421 $this->enqueuer
422 ->addScript('datepicker', 'hc3/ui/element/input/datepicker/assets/input.js?hcver=' . SH4_VERSION)
423 ->addStyle('datepicker', 'hc3/ui/element/input/datepicker/assets/input.css?hcver=' . SH4_VERSION)
424 ;
425 }
426
427 if( $value === NULL ){
428 $this->t->setNow();
429 $value = $this->t->formatDateDb();
430 }
431 else {
432 $this->t->setDateDb( $value );
433 }
434
435 $date_format = $this->t->formatToDatepicker();
436 $value_formatted = $this->t->formatDate();
437 $week_starts_on = $this->t->weekStartsOn;
438
439 $return = new HC3_Ui_Element_Input_Datepicker(
440 $this,
441 $name,
442 $label,
443 $value,
444 $value_formatted,
445 $date_format,
446 $week_starts_on
447 );
448 return $return;
449 }
450
451 public function makeInputSubmit( $label, $name = NULL, $alt = NULL )
452 {
453 $return = new HC3_Ui_Element_Input_Submit( $this, $label, $name, $alt );
454 return $return;
455 }
456
457 public function makeInputButton( $label, $name = NULL, $alt = NULL )
458 {
459 $return = new HC3_Ui_Element_Input_Button( $label, $name, $alt );
460 return $return;
461 }
462
463 public function makeAhref( $to, $label = NULL )
464 {
465 $return = new HC3_Ui_Element_Ahref( $to, $label );
466 return $return;
467 }
468
469 public function makeInputSelect( $name, $label, $options = array(), $value = NULL )
470 {
471 $return = new HC3_Ui_Element_Input_Select( $this, $name, $label, $options, $value );
472 return $return;
473 }
474
475 public function makeInputRadioSet( $name, $label, $options = array(), $value = NULL )
476 {
477 $return = new HC3_Ui_Element_Input_RadioSet( $this, $name, $label, $options, $value );
478 return $return;
479 }
480
481 public function makeInputCheckboxSet( $name, $label = NULL, $options = array(), $value = array() )
482 {
483 $return = new HC3_Ui_Element_Input_CheckboxSet( $this, $name, $label, $options, $value );
484 return $return;
485 }
486
487 public function makeInputTimeRange( $name, $label, $value = array(), $noLimit = FALSE )
488 {
489 $timeFormatOptions = array();
490
491 $startWith = 0;
492 $endWith = 24 * 60 * 60;
493
494 // $noLimit = TRUE;
495 if( ! $noLimit ){
496 $minTime = $this->settings->get('datetime_min_time');
497 if( $minTime ){
498 $startWith = $minTime;
499 }
500 }
501
502 if( ! $noLimit ){
503 $maxTime = $this->settings->get('datetime_max_time');
504 if( $maxTime ){
505 $endWith = $maxTime;
506 }
507 }
508
509 if( $endWith < $startWith ){
510 $endWith = $startWith;
511 }
512
513 $this->t->setDateDb( 20180102 );
514 if( $startWith ){
515 $this->t->modify( '+' . $startWith . ' seconds' );
516 }
517
518 $step = $this->settings->get('datetime_step');
519 if( ! $step ){
520 $step = 5 * 60;
521 }
522
523 $noOfSteps = ( $endWith - $startWith) / $step;
524 for( $ii = 0; $ii <= $noOfSteps; $ii++ ){
525 $sec = $startWith + $ii * $step;
526 $timeFormatOptions[ $sec ] = $this->t->formatTime();
527 $this->t->modify( '+' . $step . ' seconds' );
528 }
529
530 $return = new HC3_Ui_Element_Input_TimeRange( $this, $name, $label, $timeFormatOptions, $value );
531 return $return;
532 }
533
534 public function makeInputTime( $name, $label = NULL, $value = 0, $noLimit = FALSE )
535 {
536 $timeFormatOptions = array();
537
538 $startWith = 0;
539 $endWith = 24 * 60 * 60;
540
541 if( ! $noLimit ){
542 $minTime = $this->settings->get('datetime_min_time');
543 if( $minTime ){
544 $startWith = $minTime;
545 }
546 }
547
548 if( ! $noLimit ){
549 $maxTime = $this->settings->get('datetime_max_time');
550 if( $maxTime ){
551 $endWith = $maxTime;
552 }
553 }
554
555 if( $endWith < $startWith ){
556 $endWith = $startWith;
557 }
558
559 $this->t->setDateDb( 20180102 );
560 if( $startWith ){
561 $this->t->modify( '+' . $startWith . ' seconds' );
562 }
563
564 $step = $this->settings->get('datetime_step');
565 if( ! $step ){
566 $step = 5 * 60;
567 }
568
569 // value to nearest step
570 $value = ceil( $value / $step ) * $step;
571
572 $noOfSteps = ( $endWith - $startWith) / $step;
573 for( $ii = 0; $ii <= $noOfSteps; $ii++ ){
574 $sec = $startWith + $ii * $step;
575 $timeFormatOptions[ $sec ] = $this->t->formatTime();
576 $this->t->modify( '+' . $step . ' seconds' );
577 }
578
579 $return = new HC3_Ui_Element_Input_Select( $this, $name, $label, $timeFormatOptions, $value );
580 return $return;
581 }
582 }
583