| 1 |
<?php if (! defined('ABSPATH')) exit; // Exit if accessed directly |
| 2 |
class SH4_ShiftTypes_Presenter |
| 3 |
{ |
| 4 |
public $settings, $ui, $t; |
| 5 |
|
| 6 |
public function __construct( |
| 7 |
HC3_Hooks $hooks, |
| 8 |
HC3_Settings $settings, |
| 9 |
HC3_Time $t, |
| 10 |
HC3_Ui $ui |
| 11 |
) |
| 12 |
{ |
| 13 |
$this->settings = $hooks->wrap($settings); |
| 14 |
$this->ui = $ui; |
| 15 |
$this->t = $t; |
| 16 |
} |
| 17 |
|
| 18 |
public function presentTitleTime( SH4_ShiftTypes_Model $model ) |
| 19 |
{ |
| 20 |
if( $model->getId() ){ |
| 21 |
$titleView = $this->presentTitle( $model ); |
| 22 |
$timeView = $this->presentTime( $model ); |
| 23 |
$timeView = $this->ui->makeSpan($timeView) |
| 24 |
->tag('font-size', 2) |
| 25 |
; |
| 26 |
$return = $this->ui->makeList( array($titleView, $timeView) ) |
| 27 |
->gutter(0) |
| 28 |
; |
| 29 |
} |
| 30 |
else { |
| 31 |
$return = $this->presentTime( $model ); |
| 32 |
} |
| 33 |
return $return; |
| 34 |
} |
| 35 |
|
| 36 |
public function presentTitle( SH4_ShiftTypes_Model $model ) |
| 37 |
{ |
| 38 |
$ret = $model->getTitle(); |
| 39 |
$ret = esc_html( $ret ); |
| 40 |
return $ret; |
| 41 |
} |
| 42 |
|
| 43 |
public function presentDuration( $duration ) |
| 44 |
{ |
| 45 |
$return = $duration; |
| 46 |
$return = HC3_Time::formatPeriodInHours( $return ); |
| 47 |
return $return; |
| 48 |
} |
| 49 |
|
| 50 |
public function presentTime( SH4_ShiftTypes_Model $e, $start = NULL, $end = NULL ) |
| 51 |
{ |
| 52 |
$return = NULL; |
| 53 |
|
| 54 |
$noBreak = $this->settings->get( 'shifttypes_nobreak' ); |
| 55 |
|
| 56 |
$start = (NULL === $start) ? $e->getStart() : $start; |
| 57 |
$end = (NULL === $end) ? $e->getEnd() : $end; |
| 58 |
$breakStart = $e->getBreakStart(); |
| 59 |
$breakEnd = $e->getBreakEnd(); |
| 60 |
|
| 61 |
$range = $e->getRange(); |
| 62 |
|
| 63 |
switch( $range ){ |
| 64 |
case SH4_ShiftTypes_Model::RANGE_DAYS: |
| 65 |
if( $start != $end ){ |
| 66 |
$return = $start . ' - ' . $end . ' (' . '__Days__' . ')'; |
| 67 |
} |
| 68 |
else { |
| 69 |
$return = $start . ' (' . '__Days__' . ')'; |
| 70 |
} |
| 71 |
|
| 72 |
break; |
| 73 |
|
| 74 |
case SH4_ShiftTypes_Model::RANGE_HOURS: |
| 75 |
if( (NULL === $start) && (NULL === $end) ){ |
| 76 |
$return = NULL; |
| 77 |
// $return = '__Custom Time__'; |
| 78 |
} |
| 79 |
elseif( (0 == $start) && (24*60*60 == $end) ){ |
| 80 |
$return = '__All Day__'; |
| 81 |
} |
| 82 |
else { |
| 83 |
$this->t->setDateDb( 20180102 ); |
| 84 |
$this->t->modify('+' . $start . ' seconds'); |
| 85 |
$startView = $this->t->formatTime(); |
| 86 |
|
| 87 |
$this->t->setDateDb( 20180102 ); |
| 88 |
$this->t->modify('+' . $end . ' seconds'); |
| 89 |
$endView = $this->t->formatTime(); |
| 90 |
if( $end > 24 * 60 * 60 ){ |
| 91 |
$endView = '>' . $endView; |
| 92 |
} |
| 93 |
|
| 94 |
$return = $this->ui->makeListInline( array($startView, '-', $endView) )->gutter(1); |
| 95 |
|
| 96 |
if( ! $noBreak ){ |
| 97 |
if( ! ((NULL === $breakStart) && (NULL === $breakEnd)) ){ |
| 98 |
if( $breakStart OR $breakEnd ){ |
| 99 |
$this->t->setDateDb( 20180102 ); |
| 100 |
if( $breakStart ){ |
| 101 |
$this->t->modify('+' . $breakStart . ' seconds'); |
| 102 |
} |
| 103 |
$breakStartView = $this->t->formatTime(); |
| 104 |
|
| 105 |
$this->t->setDateDb( 20180102 ); |
| 106 |
if( $breakEnd ){ |
| 107 |
$this->t->modify('+' . $breakEnd . ' seconds'); |
| 108 |
} |
| 109 |
$breakEndView = $this->t->formatTime(); |
| 110 |
|
| 111 |
$breakView = $this->ui->makeListInline( array('__Break__', $breakStartView, '-', $breakEndView) ) |
| 112 |
->gutter(1) |
| 113 |
; |
| 114 |
$breakView = $this->ui->makeSpan( $breakView ) |
| 115 |
->tag('font-size', 2) |
| 116 |
->tag('muted', 2) |
| 117 |
; |
| 118 |
$return = $this->ui->makeList( array($return, $breakView) )->gutter(0); |
| 119 |
} |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
// $return = $startView . ' - ' . $endView; |
| 124 |
} |
| 125 |
break; |
| 126 |
} |
| 127 |
|
| 128 |
return $return; |
| 129 |
} |
| 130 |
} |