| 1 |
<?php |
| 2 |
class SFT_Html_Widget_Shift_View extends HC_Html_Element |
| 3 |
{ |
| 4 |
private $shift = NULL; |
| 5 |
private $iknow = array(); |
| 6 |
private $wide = TRUE; |
| 7 |
private $nolink = FALSE; |
| 8 |
private $new_window = FALSE; |
| 9 |
|
| 10 |
function init( $shift = NULL ) |
| 11 |
{ |
| 12 |
$this->set_shift( $shift ); |
| 13 |
} |
| 14 |
|
| 15 |
function set_shift( $shift ) |
| 16 |
{ |
| 17 |
$this->shift = $shift; |
| 18 |
return $this; |
| 19 |
} |
| 20 |
function shift() |
| 21 |
{ |
| 22 |
return $this->shift; |
| 23 |
} |
| 24 |
|
| 25 |
function set_nolink( $nolink = TRUE ) |
| 26 |
{ |
| 27 |
$this->nolink = $nolink; |
| 28 |
return $this; |
| 29 |
} |
| 30 |
function nolink() |
| 31 |
{ |
| 32 |
return $this->nolink; |
| 33 |
} |
| 34 |
|
| 35 |
function set_new_window( $new_window = TRUE ) |
| 36 |
{ |
| 37 |
$this->new_window = $new_window; |
| 38 |
return $this; |
| 39 |
} |
| 40 |
function new_window() |
| 41 |
{ |
| 42 |
return $this->new_window; |
| 43 |
} |
| 44 |
|
| 45 |
function set_wide( $wide = TRUE ) |
| 46 |
{ |
| 47 |
$this->wide = $wide; |
| 48 |
return $this; |
| 49 |
} |
| 50 |
function wide() |
| 51 |
{ |
| 52 |
return $this->wide; |
| 53 |
} |
| 54 |
|
| 55 |
function set_iknow( $iknow ) |
| 56 |
{ |
| 57 |
$this->iknow = $iknow; |
| 58 |
return $this; |
| 59 |
} |
| 60 |
function iknow() |
| 61 |
{ |
| 62 |
return $this->iknow; |
| 63 |
} |
| 64 |
|
| 65 |
function render() |
| 66 |
{ |
| 67 |
$sh = $this->shift(); |
| 68 |
$t = HC_Lib::time(); |
| 69 |
|
| 70 |
$titles = array(); |
| 71 |
|
| 72 |
$iknow = $this->iknow(); |
| 73 |
$wide = $this->wide(); |
| 74 |
|
| 75 |
$use_color = FALSE; |
| 76 |
$use_color = TRUE; |
| 77 |
if( $wide && ($wide === 'mini') ){ |
| 78 |
$use_color = TRUE; |
| 79 |
} |
| 80 |
|
| 81 |
if( in_array($sh->type, array($sh->_const("TYPE_TIMEOFF"))) ){ |
| 82 |
$display = array( 'date', 'time', 'user', 'location' ); |
| 83 |
} |
| 84 |
else { |
| 85 |
if( (! $wide) OR ($wide === 'mini') ){ |
| 86 |
$display = array( 'date', 'time', 'location', 'user' ); |
| 87 |
} |
| 88 |
elseif( $wide ){ |
| 89 |
$display = array( 'date', 'time', 'user', 'location' ); |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
foreach( $iknow as $ik ){ |
| 94 |
$display = HC_Lib::remove_from_array($display, $ik); |
| 95 |
} |
| 96 |
|
| 97 |
foreach( $display as $ds ){ |
| 98 |
$title_view = ''; |
| 99 |
|
| 100 |
switch( $ds ){ |
| 101 |
case 'date': |
| 102 |
$title_view = $sh->present_date(HC_PRESENTER::VIEW_RAW); |
| 103 |
break; |
| 104 |
|
| 105 |
case 'time': |
| 106 |
$title_view = $sh->present_time(); |
| 107 |
break; |
| 108 |
|
| 109 |
case 'location': |
| 110 |
if( in_array($sh->type, array($sh->_const("TYPE_TIMEOFF"))) ){ |
| 111 |
$title_view = ''; |
| 112 |
// $title_view = HCM::__('Timeoff'); |
| 113 |
// $title_view = $sh->present_location(); |
| 114 |
} |
| 115 |
else { |
| 116 |
$title_view = $sh->present_location(); |
| 117 |
} |
| 118 |
break; |
| 119 |
|
| 120 |
case 'user': |
| 121 |
if( ($sh->type == $sh->_const('TYPE_TIMEOFF')) && (! in_array('time', $display)) ){ |
| 122 |
$title_view = $sh->present_type(HC_PRESENTER::VIEW_HTML_ICON) . $sh->present_user(HC_PRESENTER::VIEW_RAW); |
| 123 |
} |
| 124 |
else { |
| 125 |
if( $sh->user_id ){ |
| 126 |
$title_view = $sh->present_user(); |
| 127 |
} |
| 128 |
else { |
| 129 |
if( count($display) == 1 ){ |
| 130 |
$title_view = HC_Html_Factory::element('span') |
| 131 |
->add_child(' ') |
| 132 |
->add_style('display', 'block') |
| 133 |
->add_attr('title', HCM::__('Open Shift')) |
| 134 |
; |
| 135 |
} |
| 136 |
} |
| 137 |
} |
| 138 |
break; |
| 139 |
} |
| 140 |
|
| 141 |
if( $title_view ){ |
| 142 |
$titles[ $ds ] = $title_view; |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
$wrap = HC_Html_Factory::element('div') |
| 147 |
->add_style('padding', 1) |
| 148 |
->add_style('nowrap') |
| 149 |
; |
| 150 |
|
| 151 |
if( ! $sh->user_id ){ |
| 152 |
$wrap |
| 153 |
->add_style('border') |
| 154 |
->add_style('border-color', 'orange') |
| 155 |
; |
| 156 |
} |
| 157 |
|
| 158 |
// echo $color; |
| 159 |
|
| 160 |
/* ID */ |
| 161 |
if( in_array('id', $iknow) ){ |
| 162 |
$wrap->add_child($sh->present_id()); |
| 163 |
} |
| 164 |
|
| 165 |
$final_display = HC_Html_Factory::widget('list') |
| 166 |
// ->add_children_style('margin', 'b1') |
| 167 |
// ->add_children_style('border') |
| 168 |
// ->add_children_style('border-color', 'blue') |
| 169 |
; |
| 170 |
|
| 171 |
/* final wrap */ |
| 172 |
$final_wrap = HC_Html_Factory::element('div') |
| 173 |
->add_style('border') |
| 174 |
->add_style('rounded') |
| 175 |
->add_style('padding', 0) |
| 176 |
->add_style('nowrap') |
| 177 |
; |
| 178 |
|
| 179 |
$extensions = HC_App::extensions(); |
| 180 |
|
| 181 |
/* QUICK ICONS */ |
| 182 |
$quick_icons = array(); |
| 183 |
if( ! $sh->user_id ){ |
| 184 |
$quick_icons['open'] = HC_Html::icon(HC_App::icon_for('user')) |
| 185 |
->add_attr('title', HCM::__('Open Shift')) |
| 186 |
->add_style('bg-color', 'orange') |
| 187 |
->add_style('color', 'white') |
| 188 |
->add_style('rounded') |
| 189 |
; |
| 190 |
} |
| 191 |
|
| 192 |
$more_quick_icons = $extensions |
| 193 |
->set_skip($iknow) |
| 194 |
->run( |
| 195 |
'shifts/quickicons', |
| 196 |
$sh, |
| 197 |
$final_wrap |
| 198 |
); |
| 199 |
|
| 200 |
$quick_icons = array_merge( $quick_icons, $more_quick_icons ); |
| 201 |
|
| 202 |
if( $quick_icons ){ |
| 203 |
$more_wrap = HC_Html_Factory::widget('list') |
| 204 |
->add_children_style('display', 'inline-block') |
| 205 |
->add_children_style('margin', 'l1') |
| 206 |
; |
| 207 |
$added = 0; |
| 208 |
foreach( $quick_icons as $mck => $mc ){ |
| 209 |
if( $mck && in_array($mck, $iknow) ){ |
| 210 |
continue; |
| 211 |
} |
| 212 |
|
| 213 |
$more_wrap->add_child($mc); |
| 214 |
$added++; |
| 215 |
} |
| 216 |
|
| 217 |
if( $added ){ |
| 218 |
$final_wrap |
| 219 |
->add_attr('style', 'position: relative;') |
| 220 |
; |
| 221 |
$more_wrap |
| 222 |
->add_attr('style', 'position: absolute; right: .125em; top: .125em; z-index: 100;') |
| 223 |
; |
| 224 |
$final_wrap->add_child($more_wrap); |
| 225 |
} |
| 226 |
} |
| 227 |
|
| 228 |
/* build link title */ |
| 229 |
$nolink = $this->nolink(); |
| 230 |
$new_window = $this->new_window(); |
| 231 |
|
| 232 |
$a_link = HC_Html_Factory::widget('titled', 'a'); |
| 233 |
$link_to = 'shifts/zoom/index/id/' . $sh->id; |
| 234 |
$a_link->add_attr('href', HC_Lib::link($link_to)->url()); |
| 235 |
if( ! $new_window ){ |
| 236 |
$a_link->add_attr('class', 'hcj-flatmodal-loader'); |
| 237 |
} |
| 238 |
else { |
| 239 |
$a_link->add_attr('target', '_blank'); |
| 240 |
$a_link->add_attr('class', 'hcj-parent-loader'); |
| 241 |
} |
| 242 |
|
| 243 |
$a_link |
| 244 |
->add_style('btn') |
| 245 |
->add_style('padding', 0) |
| 246 |
->add_style('margin', 0) |
| 247 |
; |
| 248 |
|
| 249 |
// $a_title = HC_Html_Factory::widget('titled', 'span') |
| 250 |
$a_title = HC_Html_Factory::widget('titled', 'div') |
| 251 |
->add_style('nowrap') |
| 252 |
; |
| 253 |
// $a_title->add_attr('style', 'border: red 1px solid;'); |
| 254 |
// $a_title->add_attr('style', 'border-color: ' . $sh->location->present_color()); |
| 255 |
|
| 256 |
if( count($display) > 1 ){ |
| 257 |
if( $wide ){ |
| 258 |
$titles2 = HC_Html_Factory::widget('grid'); |
| 259 |
$grid_width = array( |
| 260 |
2 => 6, |
| 261 |
3 => 4, |
| 262 |
4 => 3, |
| 263 |
5 => 2, |
| 264 |
6 => 2 |
| 265 |
); |
| 266 |
$grid_width = isset($grid_width[count($display)]) ? $grid_width[count($display)] : 2; |
| 267 |
|
| 268 |
$ti = -1; |
| 269 |
$ttis = array_keys($titles); |
| 270 |
foreach( $titles as $tti => $ttl ){ |
| 271 |
$ti++; |
| 272 |
if( $ti >= count($titles) ){ |
| 273 |
continue; |
| 274 |
} |
| 275 |
|
| 276 |
// next title is empty? |
| 277 |
if( ($ti < count($titles)-1) && (! strlen($titles[$ttis[$ti+1]])) ){ |
| 278 |
$ti++; |
| 279 |
$grid_width += $grid_width; |
| 280 |
} |
| 281 |
|
| 282 |
$final_ttl = $ttl; |
| 283 |
if( ! $nolink ){ |
| 284 |
$final_ttl = clone $a_link; |
| 285 |
$final_ttl |
| 286 |
->add_child( $ttl ) |
| 287 |
->add_attr('class', 'sfc-shift-view-' . $tti) |
| 288 |
; |
| 289 |
} |
| 290 |
$titles2->add_child( |
| 291 |
$final_ttl, |
| 292 |
$grid_width |
| 293 |
); |
| 294 |
} |
| 295 |
} |
| 296 |
else { |
| 297 |
$titles2 = HC_Html_Factory::widget('list') |
| 298 |
// ->add_children_style('margin', 'b1') |
| 299 |
// ->add_children_style('border') |
| 300 |
// ->add_children_style('border-color', 'blue') |
| 301 |
; |
| 302 |
$this_index = 0; |
| 303 |
|
| 304 |
foreach( $titles as $tti => $ttl ){ |
| 305 |
if( ! strlen($ttl) ){ |
| 306 |
continue; |
| 307 |
} |
| 308 |
|
| 309 |
$final_ttl = $ttl; |
| 310 |
if( ! $nolink ){ |
| 311 |
$final_ttl = clone $a_link; |
| 312 |
$final_ttl->add_child( $ttl ); |
| 313 |
} |
| 314 |
|
| 315 |
$final_ttl |
| 316 |
->add_style('display', 'block') |
| 317 |
->add_attr('class', 'sfc-shift-view-' . $tti) |
| 318 |
; |
| 319 |
|
| 320 |
$titles2->add_child( $this_index, $final_ttl ); |
| 321 |
$titles2->add_child_style( $this_index, 'nowrap'); |
| 322 |
$this_index++; |
| 323 |
} |
| 324 |
} |
| 325 |
$a_title->add_attr('title', join(' ', $titles)); |
| 326 |
$a_title->add_child( $titles2 ); |
| 327 |
} |
| 328 |
else { |
| 329 |
$final_ttl = $titles; |
| 330 |
if( ! $nolink ){ |
| 331 |
$final_ttl = clone $a_link; |
| 332 |
$final_ttl->add_child( $titles ); |
| 333 |
} |
| 334 |
$final_ttl |
| 335 |
->add_attr('title', join(' ', $titles)) |
| 336 |
->add_style('display', 'block') |
| 337 |
; |
| 338 |
|
| 339 |
$a_title->add_child( $final_ttl ); |
| 340 |
} |
| 341 |
|
| 342 |
/* main view */ |
| 343 |
$final_display->add_child($a_title); |
| 344 |
|
| 345 |
/* EXTENSIONS */ |
| 346 |
$more_content = $extensions |
| 347 |
->set_skip($iknow) |
| 348 |
->run( |
| 349 |
'shifts/quickview', |
| 350 |
$sh, |
| 351 |
// $wrap |
| 352 |
$final_wrap |
| 353 |
); |
| 354 |
|
| 355 |
if( $more_content ){ |
| 356 |
$more_wrap = HC_Html_Factory::widget('list') |
| 357 |
->add_children_style('font-size', -1) |
| 358 |
; |
| 359 |
$added = 0; |
| 360 |
foreach($more_content as $mck => $mc ){ |
| 361 |
if( $mck && in_array($mck, $iknow) ){ |
| 362 |
continue; |
| 363 |
} |
| 364 |
|
| 365 |
$more_wrap->add_child($mc); |
| 366 |
$added++; |
| 367 |
} |
| 368 |
if( $added ){ |
| 369 |
// $wrap->add_child($more_wrap); |
| 370 |
$final_display->add_child($more_wrap); |
| 371 |
} |
| 372 |
} |
| 373 |
|
| 374 |
/* THIS CHILDREN */ |
| 375 |
$children = $this->children(); |
| 376 |
foreach( $children as $child ){ |
| 377 |
// $wrap->add_child($child); |
| 378 |
$final_display->add_child($child); |
| 379 |
} |
| 380 |
|
| 381 |
/* add summary for mini displays in month calendars */ |
| 382 |
if( $wide === 'mini' ){ |
| 383 |
$a_title = HC_Html_Factory::widget('titled', 'span') |
| 384 |
->add_style('nowrap') |
| 385 |
; |
| 386 |
if( ! $nolink ){ |
| 387 |
$final_ttl = clone $a_link; |
| 388 |
$final_ttl |
| 389 |
->add_child(' ') |
| 390 |
->add_style('display', 'block') |
| 391 |
->add_attr('style', 'position: relative; z-index: 200;') |
| 392 |
; |
| 393 |
$final_ttl->add_attr('title', join(' ', $titles)); |
| 394 |
} |
| 395 |
$a_title->add_child( $final_ttl ); |
| 396 |
|
| 397 |
$final_display = HC_Html_Factory::widget('list') |
| 398 |
->add_child('summary', $a_title ) |
| 399 |
->add_child_attr('summary', 'class', 'schecal-cell-summary' ) |
| 400 |
->add_child('full', $final_display ) |
| 401 |
->add_child_attr('full', 'class', 'schecal-cell-details' ) |
| 402 |
; |
| 403 |
} |
| 404 |
$wrap->add_child( $final_display ); |
| 405 |
|
| 406 |
|
| 407 |
/* background color depends on location */ |
| 408 |
if( $use_color ){ |
| 409 |
$color = $sh->location->present_color(); |
| 410 |
} |
| 411 |
else { |
| 412 |
$type = $sh->type; |
| 413 |
switch( $type ){ |
| 414 |
case $sh->_const('TYPE_TIMEOFF'): |
| 415 |
$final_wrap->add_style('bg-color', 'silver'); |
| 416 |
$color = '#ddd'; |
| 417 |
break; |
| 418 |
default: |
| 419 |
$final_wrap->add_style('border-color', 'olive'); |
| 420 |
$color = '#dff0d8'; |
| 421 |
break; |
| 422 |
} |
| 423 |
} |
| 424 |
|
| 425 |
// if( ! $sh->user_id ){ |
| 426 |
// $color = ''; |
| 427 |
// } |
| 428 |
|
| 429 |
if( $color ){ |
| 430 |
if( $sh->status == $sh->_const('STATUS_DRAFT') ){ |
| 431 |
$color1 = HC_Lib::adjust_color_brightness( $color, 0 ); |
| 432 |
$color2 = HC_Lib::adjust_color_brightness( $color, 20 ); |
| 433 |
|
| 434 |
// $color1 = '#fff'; |
| 435 |
// $color2 = '#eee'; |
| 436 |
|
| 437 |
$final_wrap->add_attr('style', |
| 438 |
"background: repeating-linear-gradient( |
| 439 |
-45deg, |
| 440 |
$color1, |
| 441 |
$color1 6px, |
| 442 |
$color2 6px, |
| 443 |
$color2 12px |
| 444 |
); |
| 445 |
" |
| 446 |
); |
| 447 |
} |
| 448 |
else { |
| 449 |
$final_wrap->add_attr('style', 'background-color: ' . $color . ';'); |
| 450 |
} |
| 451 |
$wrap->add_style('bg-lighten', 2); |
| 452 |
} |
| 453 |
|
| 454 |
$wrap->add_attr( 'class', 'hcj-common-link-parent' ); |
| 455 |
$wrap->add_attr( 'class', 'hcj-target' ); |
| 456 |
// $final_wrap->add_attr( 'class', 'hcj-common-link-parent' ); |
| 457 |
// $final_wrap->add_attr( 'class', 'hcj-target' ); |
| 458 |
$final_wrap->add_child( $wrap ); |
| 459 |
|
| 460 |
/* |
| 461 |
$final_wrap = HC_Html_Factory::widget('table') |
| 462 |
->set_cell( 0, 0, |
| 463 |
'<input type="checkbox" style="">' |
| 464 |
) |
| 465 |
->add_cell_attr(0, 0, array('style' => 'width: 1em;')) |
| 466 |
->set_cell( 0, 1, |
| 467 |
$final_wrap |
| 468 |
) |
| 469 |
; |
| 470 |
*/ |
| 471 |
return $final_wrap->render(); |
| 472 |
} |
| 473 |
} |