| 1 |
<?php if (! defined('ABSPATH')) exit; // Exit if accessed directly |
| 2 |
#[AllowDynamicProperties] |
| 3 |
class SH4_Shifts_View_Calendar |
| 4 |
{ |
| 5 |
public function __construct( |
| 6 |
HC3_Hooks $hooks, |
| 7 |
|
| 8 |
HC3_Ui $ui, |
| 9 |
HC3_Ui_Layout1 $layout, |
| 10 |
|
| 11 |
SH4_Shifts_View_Common $common, |
| 12 |
SH4_Shifts_Query $shiftsQuery, |
| 13 |
|
| 14 |
SH4_Calendars_Presenter $calendarsPresenter, |
| 15 |
SH4_Employees_Query $employees, |
| 16 |
SH4_App_Query $appQuery, |
| 17 |
|
| 18 |
SH4_Shifts_Availability $availability, |
| 19 |
SH4_Shifts_Conflicts $conflicts, |
| 20 |
SH4_Shifts_View_Zoom $viewZoom |
| 21 |
) |
| 22 |
{ |
| 23 |
$this->self = $hooks->wrap( $this ); |
| 24 |
$this->ui = $ui; |
| 25 |
$this->layout = $layout; |
| 26 |
|
| 27 |
$this->calendarsPresenter = $hooks->wrap( $calendarsPresenter ); |
| 28 |
$this->shiftsQuery = $hooks->wrap( $shiftsQuery ); |
| 29 |
$this->common = $hooks->wrap( $common ); |
| 30 |
|
| 31 |
$this->employees = $hooks->wrap($employees); |
| 32 |
$this->appQuery = $hooks->wrap( $appQuery ); |
| 33 |
$this->conflicts = $hooks->wrap($conflicts); |
| 34 |
} |
| 35 |
|
| 36 |
public function render( $shiftId ) |
| 37 |
{ |
| 38 |
$model = $this->shiftsQuery->findById( $shiftId ); |
| 39 |
|
| 40 |
$employee = $model->getEmployee(); |
| 41 |
$employeeId = $employee->getId(); |
| 42 |
|
| 43 |
$calendar = $model->getCalendar(); |
| 44 |
$calendarId = $calendar->getId(); |
| 45 |
|
| 46 |
$calendars = $this->appQuery->findCalendarsForChange( $model ); |
| 47 |
|
| 48 |
$calendarsView = array(); |
| 49 |
$calendarsWithConflictsView = array(); |
| 50 |
|
| 51 |
foreach( $calendars as $calendar ){ |
| 52 |
$thisCalendarId = $calendar->getId(); |
| 53 |
|
| 54 |
$withConflicts = 0; |
| 55 |
|
| 56 |
$id = $model->getId(); |
| 57 |
$start = $model->getStart(); |
| 58 |
$end = $model->getEnd(); |
| 59 |
|
| 60 |
$testModel = new SH4_Shifts_Model( $shiftId, $calendar, $start, $end, $employee ); |
| 61 |
|
| 62 |
$conflicts = $this->conflicts->get($testModel); |
| 63 |
if( $conflicts ){ |
| 64 |
$withConflicts++; |
| 65 |
} |
| 66 |
|
| 67 |
$thisView = array(); |
| 68 |
$calendarView = $this->calendarsPresenter->presentTitle( $calendar ); |
| 69 |
$calendarView = $this->ui->makeSpan( $calendarView ) |
| 70 |
->tag('font-size', 4) |
| 71 |
->tag('font-style', 'bold') |
| 72 |
; |
| 73 |
|
| 74 |
$descriptionView = $calendar->getDescription(); |
| 75 |
if( strlen($descriptionView) ){ |
| 76 |
$descriptionView = $this->ui->makeLongText( $descriptionView ); |
| 77 |
$calendarView = $this->ui->makeList( array($calendarView, $descriptionView) ) |
| 78 |
->gutter(1) |
| 79 |
; |
| 80 |
} |
| 81 |
|
| 82 |
$thisView[] = $calendarView; |
| 83 |
|
| 84 |
$conflictsView = array(); |
| 85 |
|
| 86 |
if( $withConflicts ){ |
| 87 |
$sign = ' ! '; |
| 88 |
$sign = $this->ui->makeBlock( $sign ) |
| 89 |
->tag('padding', 'x1') |
| 90 |
->tag('color', 'white') |
| 91 |
->tag('bgcolor', 'maroon') |
| 92 |
->addAttr( 'title', '__Conflicts__' ) |
| 93 |
; |
| 94 |
|
| 95 |
$conflictsLink = array('conflicts', $shiftId, $thisCalendarId, $start, $end, $employeeId ); |
| 96 |
$conflictsLink = join('/', $conflictsLink); |
| 97 |
|
| 98 |
$sign = $this->ui->makeAhref( $conflictsLink, $sign ) |
| 99 |
->newWindow() |
| 100 |
; |
| 101 |
|
| 102 |
$conflictsView[] = $sign; |
| 103 |
} |
| 104 |
|
| 105 |
$conflictsView = $this->ui->makeListInline( $conflictsView ) |
| 106 |
->gutter(1) |
| 107 |
; |
| 108 |
$thisView[] = $conflictsView; |
| 109 |
|
| 110 |
$thisView = $this->ui->makeBlock( $this->ui->makeListInline($thisView) ) |
| 111 |
->addAttr('style', 'position: relative;') |
| 112 |
; |
| 113 |
|
| 114 |
$btn = $this->ui->makeInputSubmit('__Select__') |
| 115 |
->tag('secondary') |
| 116 |
; |
| 117 |
if( $withConflicts ){ |
| 118 |
$btn |
| 119 |
->tag('confirm') |
| 120 |
; |
| 121 |
} |
| 122 |
|
| 123 |
$to = array( 'shifts', $shiftId, 'calendar', $thisCalendarId ); |
| 124 |
$to = join('/', $to); |
| 125 |
|
| 126 |
$form = $this->ui->makeForm( $to, $btn ); |
| 127 |
|
| 128 |
$thisView = $this->ui->makeList( array($thisView, $form) )->gutter(2); |
| 129 |
|
| 130 |
$thisView = $this->ui->makeBlock( $thisView ) |
| 131 |
->tag('border') |
| 132 |
->tag('padding', 2) |
| 133 |
; |
| 134 |
|
| 135 |
if( $withConflicts ){ |
| 136 |
$thisView |
| 137 |
->tag('border-color', 'darkred') |
| 138 |
; |
| 139 |
} |
| 140 |
else { |
| 141 |
$thisView |
| 142 |
->tag('border-color', 'green') |
| 143 |
; |
| 144 |
} |
| 145 |
|
| 146 |
$calendarsView[] = $thisView; |
| 147 |
} |
| 148 |
|
| 149 |
if( $calendarsView OR $calendarsWithConflictsView ){ |
| 150 |
|
| 151 |
$out = $this->ui->makeGrid(); |
| 152 |
foreach( $calendarsView as $ev ){ |
| 153 |
$out->add( $ev, 3, 12 ); |
| 154 |
} |
| 155 |
} |
| 156 |
else { |
| 157 |
$out = array(); |
| 158 |
$out[] = '__No Available Calendars__'; |
| 159 |
$out = $this->ui->makeList( $out ); |
| 160 |
} |
| 161 |
|
| 162 |
$this->layout |
| 163 |
->setContent( $out ) |
| 164 |
->setHeader( $this->self->header($model) ) |
| 165 |
; |
| 166 |
|
| 167 |
$breadcrumb = $this->common->breadcrumb($model); |
| 168 |
$breadcrumbMultiline = FALSE; |
| 169 |
|
| 170 |
$this->layout |
| 171 |
->setBreadcrumb( $breadcrumb, $breadcrumbMultiline ) |
| 172 |
; |
| 173 |
|
| 174 |
$out = $this->layout->render(); |
| 175 |
return $out; |
| 176 |
} |
| 177 |
|
| 178 |
public function header( SH4_Shifts_Model $model ) |
| 179 |
{ |
| 180 |
$out = '__Change Calendar__'; |
| 181 |
return $out; |
| 182 |
} |
| 183 |
} |