PluginProbe
ShiftController Employee Shift Scheduling / 4.9.26
ShiftController Employee Shift Scheduling v4.9.26
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.26, at hc3/ui.php

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