| 1 |
<?php if (! defined('ABSPATH')) exit; // Exit if accessed directly |
| 2 |
#[AllowDynamicProperties] |
| 3 |
class SH4_Shifts_View_Zoom |
| 4 |
{ |
| 5 |
public function __construct( |
| 6 |
HC3_Hooks $hooks, |
| 7 |
|
| 8 |
HC3_Ui $ui, |
| 9 |
HC3_Ui_Layout1 $layout, |
| 10 |
HC3_Request $request, |
| 11 |
|
| 12 |
SH4_App_Query $appQuery, |
| 13 |
SH4_Calendars_Presenter $calendarsPresenter, |
| 14 |
SH4_Employees_Presenter $employeesPresenter, |
| 15 |
SH4_Shifts_Presenter $shiftsPresenter, |
| 16 |
|
| 17 |
SH4_Shifts_View_Common $common, |
| 18 |
SH4_Shifts_Query $query, |
| 19 |
SH4_Shifts_Conflicts $conflicts |
| 20 |
) |
| 21 |
{ |
| 22 |
$this->ui = $ui; |
| 23 |
$this->layout = $layout; |
| 24 |
$this->request = $request; |
| 25 |
|
| 26 |
$this->query = $hooks->wrap( $query ); |
| 27 |
|
| 28 |
$this->calendarsPresenter = $hooks->wrap( $calendarsPresenter ); |
| 29 |
$this->employeesPresenter = $hooks->wrap( $employeesPresenter ); |
| 30 |
$this->shiftsPresenter = $hooks->wrap( $shiftsPresenter ); |
| 31 |
|
| 32 |
$this->appQuery = $hooks->wrap( $appQuery ); |
| 33 |
$this->conflicts = $hooks->wrap($conflicts); |
| 34 |
$this->common = $hooks->wrap($common); |
| 35 |
$this->self = $hooks->wrap($this); |
| 36 |
} |
| 37 |
|
| 38 |
public function render( $id ) |
| 39 |
{ |
| 40 |
// model |
| 41 |
$model = $this->query->findById($id); |
| 42 |
|
| 43 |
$rows = $this->self->rows( $model ); |
| 44 |
|
| 45 |
// compile |
| 46 |
$out = array(); |
| 47 |
|
| 48 |
foreach( $rows as $row ){ |
| 49 |
if( is_array($row) ){ |
| 50 |
$row = $this->ui->makeGrid() |
| 51 |
->add( $row['label'], 3, 12 ) |
| 52 |
->add( $row['view'], 9, 12 ) |
| 53 |
; |
| 54 |
} |
| 55 |
$out[] = $row; |
| 56 |
} |
| 57 |
|
| 58 |
$out = $this->ui->makeList( $out ) |
| 59 |
->setStriped( TRUE ) |
| 60 |
; |
| 61 |
|
| 62 |
$this->layout |
| 63 |
->setContent( $out ) |
| 64 |
->setHeader( $this->self->header($model) ) |
| 65 |
; |
| 66 |
|
| 67 |
if( ! $this->request->isAjax() ){ |
| 68 |
$this->layout |
| 69 |
->setBreadcrumb( $this->common->breadcrumb($model) ) |
| 70 |
; |
| 71 |
} |
| 72 |
|
| 73 |
$out = $this->layout->render(); |
| 74 |
|
| 75 |
return $out; |
| 76 |
} |
| 77 |
|
| 78 |
public function rows( ?SH4_Shifts_Model $model = NULL ) |
| 79 |
{ |
| 80 |
$rows = array(); |
| 81 |
if( ! $model ){ |
| 82 |
return $rows; |
| 83 |
} |
| 84 |
|
| 85 |
$menu = $this->common->menu( $model ); |
| 86 |
$icons = $this->common->icons( $model ); |
| 87 |
|
| 88 |
$id = $model->getId(); |
| 89 |
|
| 90 |
// find if we have alternative calendars |
| 91 |
// temp disable |
| 92 |
// $calendars = $this->appQuery->findCalendarsForChange( $model ); |
| 93 |
// if( $calendars ){ |
| 94 |
// $menu['calendar']['change'] = array( 'shifts/' . $id . '/calendar', '__Change__' ); |
| 95 |
// } |
| 96 |
|
| 97 |
// datetime |
| 98 |
$thisLabel = '__Date and Time__'; |
| 99 |
|
| 100 |
if( $model->isMultiDay() ){ |
| 101 |
$thisView = $this->shiftsPresenter->presentFullTime( $model ); |
| 102 |
$thisView = $this->ui->makeBlock( $thisView ) |
| 103 |
->tag('font-size', 4) |
| 104 |
; |
| 105 |
} |
| 106 |
else { |
| 107 |
$thisView = array(); |
| 108 |
$dateView = $this->shiftsPresenter->presentDate( $model ); |
| 109 |
|
| 110 |
$timeView = $this->shiftsPresenter->presentTime( $model ); |
| 111 |
$rawTimeView = $this->shiftsPresenter->presentRawTime( $model ); |
| 112 |
|
| 113 |
if( $rawTimeView != $timeView ){ |
| 114 |
$timeView = $this->ui->makeBlock( $timeView ) |
| 115 |
->tag('font-size', 4) |
| 116 |
; |
| 117 |
$rawTimeView = $this->ui->makeBlock( $rawTimeView ) |
| 118 |
->tag('muted') |
| 119 |
; |
| 120 |
$timeView = $this->ui->makeListInline( array($timeView, $rawTimeView) ) |
| 121 |
// ->gutter(0) |
| 122 |
; |
| 123 |
} |
| 124 |
else { |
| 125 |
$timeView = $this->ui->makeBlock( $timeView ) |
| 126 |
->tag('font-size', 4) |
| 127 |
; |
| 128 |
} |
| 129 |
|
| 130 |
// if we have lunch timebreak |
| 131 |
$breakView = $this->shiftsPresenter->presentBreak( $model ); |
| 132 |
if( $breakView ){ |
| 133 |
$breakView = $this->ui->makeListInline( array('__Break__', $breakView) ) |
| 134 |
->gutter(1) |
| 135 |
; |
| 136 |
$breakView = $this->ui->makeBlock( $breakView ) |
| 137 |
->tag('muted') |
| 138 |
->tag('font-size', 2) |
| 139 |
// ->tag('font-style', 'line-through') |
| 140 |
// ->addAttr('title', '__Lunch Break__') |
| 141 |
; |
| 142 |
|
| 143 |
$timeView = $this->ui->makeListInline( array($timeView, $breakView) ); |
| 144 |
} |
| 145 |
|
| 146 |
$thisView[] = $dateView; |
| 147 |
$thisView[] = $timeView; |
| 148 |
|
| 149 |
$thisView = $this->ui->makeList( $thisView )->gutter(0); |
| 150 |
} |
| 151 |
|
| 152 |
if( isset($icons['datetime']) ){ |
| 153 |
$thisIcons = $this->ui->makeListInline( $icons['datetime'] )->gutter(1); |
| 154 |
$thisLabel = $this->ui->makeBlock( $this->ui->makeListInline(array($thisLabel, $thisIcons))->gutter(1) ) |
| 155 |
->addAttr('style', 'position: relative;') |
| 156 |
; |
| 157 |
} |
| 158 |
|
| 159 |
if( isset($menu['datetime']) ){ |
| 160 |
$thisMenu = $this->ui->helperActionsFromArray( $menu['datetime'] ); |
| 161 |
$thisMenu = $this->ui->makeListInline( $thisMenu ); |
| 162 |
unset( $menu['datetime'] ); |
| 163 |
$thisView = $this->ui->makeList( array($thisView, $thisMenu) ) |
| 164 |
->gutter(1) |
| 165 |
; |
| 166 |
} |
| 167 |
|
| 168 |
$thisRow = array( |
| 169 |
'label' => $thisLabel, |
| 170 |
'view' => $thisView |
| 171 |
); |
| 172 |
|
| 173 |
$rows[] = $thisRow; |
| 174 |
|
| 175 |
// calendar |
| 176 |
$calendar = $model->getCalendar(); |
| 177 |
$thisLabel = '__Calendar__'; |
| 178 |
$thisView = $this->calendarsPresenter->presentTitle( $calendar ); |
| 179 |
if( isset($icons['calendar']) ){ |
| 180 |
$thisIcons = $this->ui->makeListInline( $icons['calendar'] )->gutter(1); |
| 181 |
$thisLabel = $this->ui->makeBlock( $this->ui->makeListInline(array($thisLabel, $thisIcons))->gutter(1) ) |
| 182 |
->addAttr('style', 'position: relative;') |
| 183 |
; |
| 184 |
} |
| 185 |
$thisView = $this->ui->makeBlock( $thisView ) |
| 186 |
->tag('font-size', 4) |
| 187 |
; |
| 188 |
|
| 189 |
// $calendarDescription = $calendar->getDescription(); |
| 190 |
$calendarDescription = $this->calendarsPresenter->presentDescription( $calendar ); |
| 191 |
if( (null !== $calendarDescription) && strlen($calendarDescription) ){ |
| 192 |
$thisView = $this->ui->makeList( array($thisView, $calendarDescription) ) |
| 193 |
->gutter(2) |
| 194 |
; |
| 195 |
} |
| 196 |
|
| 197 |
if( isset($menu['calendar']) ){ |
| 198 |
$thisMenu = $this->ui->helperActionsFromArray( $menu['calendar'] ); |
| 199 |
$thisMenu = $this->ui->makeListInline($thisMenu); |
| 200 |
unset( $menu['calendar'] ); |
| 201 |
$thisView = $this->ui->makeList( array($thisView, $thisMenu) ) |
| 202 |
->gutter(1) |
| 203 |
; |
| 204 |
} |
| 205 |
$thisRow = array( |
| 206 |
'label' => $thisLabel, |
| 207 |
'view' => $thisView |
| 208 |
); |
| 209 |
$rows[] = $thisRow; |
| 210 |
|
| 211 |
// employee |
| 212 |
$employee = $model->getEmployee(); |
| 213 |
$thisLabel = '__Employee__'; |
| 214 |
$thisView = $this->employeesPresenter->presentTitle( $employee ); |
| 215 |
|
| 216 |
if( isset($icons['employee']) ){ |
| 217 |
$thisIcons = $this->ui->makeListInline( $icons['employee'] )->gutter(1); |
| 218 |
$thisLabel = $this->ui->makeBlock( $this->ui->makeListInline(array($thisLabel, $thisIcons))->gutter(1) ) |
| 219 |
->addAttr('style', 'position: relative;') |
| 220 |
; |
| 221 |
} |
| 222 |
|
| 223 |
$thisView = $this->ui->makeBlock( $thisView ) |
| 224 |
->tag('font-size', 4) |
| 225 |
; |
| 226 |
|
| 227 |
$employeeDescription = $this->employeesPresenter->presentDescription( $employee ); |
| 228 |
if( (null !== $employeeDescription) && strlen($employeeDescription) ){ |
| 229 |
$thisView = $this->ui->makeList( array($thisView, $employeeDescription) ) |
| 230 |
->gutter(2) |
| 231 |
; |
| 232 |
} |
| 233 |
|
| 234 |
if( isset($menu['employee']) ){ |
| 235 |
$thisMenu = $this->ui->helperActionsFromArray( $menu['employee'] ); |
| 236 |
|
| 237 |
$thisMenu = $this->ui->makeListInline($thisMenu)->gutter(1); |
| 238 |
unset( $menu['employee'] ); |
| 239 |
$thisView = $this->ui->makeList( array($thisView, $thisMenu) ) |
| 240 |
->gutter(1) |
| 241 |
; |
| 242 |
} |
| 243 |
$thisRow = array( |
| 244 |
'label' => $thisLabel, |
| 245 |
'view' => $thisView |
| 246 |
); |
| 247 |
$rows[] = $thisRow; |
| 248 |
|
| 249 |
// status |
| 250 |
$thisLabel = '__Status__'; |
| 251 |
$thisView = $this->shiftsPresenter->presentStatus( $model ); |
| 252 |
if( isset($icons['status']) ){ |
| 253 |
$thisIcons = $this->ui->makeListInline( $icons['status'] )->gutter(1); |
| 254 |
$thisLabel = $this->ui->makeBlock( $this->ui->makeListInline(array($thisLabel, $thisIcons))->gutter(1) ) |
| 255 |
->addAttr('style', 'position: relative;') |
| 256 |
; |
| 257 |
} |
| 258 |
|
| 259 |
$thisView = $this->ui->makeBlock( $thisView ) |
| 260 |
->tag('font-size', 4) |
| 261 |
; |
| 262 |
|
| 263 |
if( isset($menu['status']) ){ |
| 264 |
$thisMenu = $this->ui->helperActionsFromArray( $menu['status'] ); |
| 265 |
$thisMenu = $this->ui->makeListInline($thisMenu); |
| 266 |
unset( $menu['status'] ); |
| 267 |
|
| 268 |
$thisView = $this->ui->makeList( array($thisView, $thisMenu) ) |
| 269 |
->gutter(1) |
| 270 |
; |
| 271 |
} |
| 272 |
|
| 273 |
$thisRow = array( |
| 274 |
'label' => $thisLabel, |
| 275 |
'view' => $thisView, |
| 276 |
); |
| 277 |
$rows[] = $thisRow; |
| 278 |
|
| 279 |
return $rows; |
| 280 |
} |
| 281 |
|
| 282 |
public function header( SH4_Shifts_Model $shift ) |
| 283 |
{ |
| 284 |
$out = array(); |
| 285 |
$out[] = '__Shift__'; |
| 286 |
$out[] = '#' . $shift->getId(); |
| 287 |
|
| 288 |
$out = join( ' ', $out ); |
| 289 |
|
| 290 |
return $out; |
| 291 |
} |
| 292 |
} |