PluginProbe
ShiftController Employee Shift Scheduling / 4.9.95
ShiftController Employee Shift Scheduling v4.9.95
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 / sh4 / shifts / view / date.php

date.php in ShiftController Employee Shift Scheduling 4.9.95, at sh4/shifts/view/date.php

344 lines 8.3 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 #[AllowDynamicProperties]
3 class SH4_Shifts_View_Date
4 {
5 public function __construct(
6 HC3_Hooks $hooks,
7
8 HC3_Settings $settings,
9 HC3_Request $request,
10 HC3_Time $t,
11 HC3_Ui $ui,
12 HC3_Acl $acl,
13 HC3_Ui_Layout1 $layout,
14
15 SH4_Shifts_View_Common $common,
16 SH4_Shifts_Query $shiftsQuery,
17
18 SH4_Employees_Query $employees,
19 SH4_App_Query $appQuery,
20
21 SH4_Shifts_Conflicts $conflicts
22 )
23 {
24 $this->request = $request;
25 $this->ui = $ui;
26 $this->acl = $acl;
27 $this->t = $t;
28 $this->layout = $layout;
29 $this->settings = $hooks->wrap($settings);
30
31 $this->shiftsQuery = $hooks->wrap( $shiftsQuery );
32
33 $this->employees = $hooks->wrap($employees);
34 $this->appQuery = $hooks->wrap( $appQuery );
35
36 $this->common = $hooks->wrap($common);
37 $this->self = $hooks->wrap($this);
38 $this->conflicts = $hooks->wrap($conflicts);
39 }
40
41 public function ajaxRender( $shiftId )
42 {
43 $out = $this->self->renderDates( $shiftId );
44 return $out;
45 }
46
47 public function renderDates( $shiftId )
48 {
49 $disabledWeekdays = $this->settings->get( 'skip_weekdays', TRUE );
50
51 $params = $this->request->getParams();
52
53 $showPrev = ( isset( $params['prev'] ) && (! $params['prev']) ) ? FALSE : TRUE;
54 $showNext = ( isset( $params['next'] ) && (! $params['next']) ) ? FALSE : TRUE;
55
56 $shift = $this->shiftsQuery->findById( $shiftId );
57
58 $this->t->setDateTimeDb( $shift->getStart() );
59 $shiftDate = $this->t->formatDateDb();
60 $timeStart = $this->t->getTimestamp();
61 $dayStart = $this->t->setStartDay()->getTimestamp();
62 $timeStart = $timeStart - $dayStart;
63
64 $this->t->setDateTimeDb( $shift->getEnd() );
65 $timeEnd = $this->t->getTimestamp();
66 $timeEnd = $timeEnd - $dayStart;
67
68 $tsStart = $this->t->setDateTimeDb( $shift->getStart() )->getTimestamp();
69 $tsEnd = $this->t->setDateTimeDb( $shift->getEnd() )->getTimestamp();;
70 $duration = $tsEnd - $tsStart;
71 $durationInDays = ceil( $duration/(24*60*60) );
72
73 $calendar = $shift->getCalendar();
74 $calendarId = $calendar->getId();
75 $employee = $shift->getEmployee();
76 $employeeId = $employee->getId();
77
78 $weeksToShow = 4;
79 $startDate = array_key_exists('date', $params) ? $params['date'] : $shiftDate;
80
81 $out = array();
82 $this->t->setDateDb( $startDate );
83 $this->t->setStartWeek();
84
85 $startDate = $this->t->formatDateDb();
86 $displayedDays = 0;
87
88 for( $ww = 1; $ww <= $weeksToShow; $ww++ ){
89 $thisWeekView = array();
90
91 for( $dd = 0; $dd <= 6; $dd++ ){
92 $displayedDays++;
93 $date = $this->t->formatDateDb();
94
95 if( $disabledWeekdays ){
96 $wkd = $this->t->getWeekday();
97 if( in_array($wkd, $disabledWeekdays) ){
98 $this->t->modify('+1 day');
99 continue;
100 }
101 }
102
103 $suitable = TRUE;
104 // if( $date <= $shiftDate ){
105 // $suitable = FALSE;
106 // }
107
108 if( $date == $shiftDate ){
109 $suitable = FALSE;
110 }
111
112 $thisView = array();
113 $label = $this->t->formatDate();
114
115 if( $suitable ){
116 $checkParams = $params;
117 $checkParams['date'] = $date;
118 $suitable = $this->acl->check( 'get:new', $checkParams );
119 }
120
121 if( $suitable ){
122 $label = $this->ui->makeInputRadio( 'date', $label, $date )
123 ->setHtmlId( 'hc-date-' . $date )
124 ->asList()
125 ;
126 }
127 elseif( $date == $shiftDate ){
128 // $label = $this->ui->makeListInline( array('&#10003;', $label) )
129 // ->tag('nowrap')
130 // ;
131 $label = $this->ui->makeList( array('&#10003;', $label) )->gutter(0)
132 ->tag('align', 'center')
133 ;
134 }
135 else {
136 $label = $this->ui->makeBlock( $label )
137 ->tag('muted')
138 ->tag('align', 'center')
139 ;
140 }
141
142 $thisView[] = $label;
143
144 // check conflicts
145 $conflicts = array();
146 if( $suitable ){
147 $start = $this->t->setDateDb( $date )
148 ->modify( '+' . $timeStart . ' seconds' )
149 ->formatDateTimeDb()
150 ;
151 $this->t->setDateDb( $date );
152 if( $durationInDays > 1 ){
153 $this->t->modify( '+' . ($durationInDays - 1) . ' days' );
154 }
155 $end = $this->t
156 ->modify( '+' . $timeEnd . ' seconds' )
157 ->formatDateTimeDb()
158 ;
159
160 $testModel = new SH4_Shifts_Model( null, $calendar, $start, $end, $employee );
161 $conflicts = $this->conflicts->get( $testModel, array($shiftId) );
162 }
163
164 if( $conflicts ){
165 $conflictsLabel = '__Conflicts__';
166
167 $conflictsLink = array('conflicts', $shiftId, $calendarId, $start, $end, $employeeId);
168 $conflictsLink = join('/', $conflictsLink);
169
170 $conflictsView = $this->ui->makeAhref( $conflictsLink, $conflictsLabel )
171 ->newWindow()
172 ->tag('color', 'red')
173 ;
174 // $conflictsView = $this->ui->makeListInline( array($conflictsView, '&nearr;'))->gutter(1);
175
176 $thisView[] = $conflictsView;
177 }
178
179 $thisView = $this->ui->makeList( $thisView )->gutter(0);
180 $thisView = $this->ui->makeBlock( $thisView )
181 ->tag('border')
182 ->tag('padding', 2)
183 ;
184
185 if( $conflicts ){
186 $thisView
187 // ->tag('border-color', 'red')
188 // ->tag('color', 'red')
189 ;
190 }
191 else {
192 // if( $suitable OR ($date == $shiftDate) ){
193 if( $suitable ){
194 $thisView
195 ->tag('border-color', 'green')
196 // ->tag('color', 'olive')
197 ;
198 }
199 }
200
201 $thisWeekView[] = $thisView;
202
203 $this->t->setDateDb( $date );
204 $this->t->modify('+1 day');
205 }
206
207 $thisWeekView = $this->ui->makeGrid( $thisWeekView );
208
209 $out[] = $thisWeekView;
210
211 $lastDate = $date;
212 }
213
214 $out = $this->ui->makeList( $out );
215
216 $nextTo = 'ajax/shifts/' . $shiftId . '/date';
217
218 // next link
219 $this->t->setDateDb( $lastDate );
220 $this->t->modify('+1 day');
221 $nextDate = $this->t->formatDateDb();
222
223 $nextParams = $params;
224 $nextParams['date'] = $nextDate;
225 $nextParams['prev'] = 0;
226 $nextLink = $this->ui->makeAhref( array($nextTo, $nextParams), '&darr; __Next__' )
227 ->tag('ajax')
228 ->tag('secondary')
229 ->tag('block')
230 ->tag('padding', 2)
231 ;
232
233 // prev link
234 $prevDate = $this->t
235 ->setDateDb( $startDate )
236 ->modify( '-' . $displayedDays . ' days' )
237 ->formatDateDb()
238 ;
239
240 $prevParams = $params;
241 $prevParams['date'] = $prevDate;
242 $prevParams['next'] = 0;
243 $prevLink = $this->ui->makeAhref( array($nextTo, $prevParams), '&uarr; __Previous__' )
244 ->tag('ajax')
245 ->tag('secondary')
246 ->tag('block')
247 ->tag('padding', 2)
248 ;
249
250 $fullOut = array();
251
252 if( $showPrev ){
253 $fullOut[] = $prevLink;
254 }
255
256 $fullOut[] = $out;
257
258 if( $showNext ){
259 $fullOut[] = $nextLink;
260 }
261
262 $out = $this->ui->makeList( $fullOut );
263 return $out;
264 }
265
266 public function render( $shiftId )
267 {
268 $disabledWeekdays = $this->settings->get( 'skip_weekdays', TRUE );
269 $params = $this->request->getParams();
270
271 $shift = $this->shiftsQuery->findById( $shiftId );
272
273 $this->t->setStartWeek();
274 $header = array();
275
276 for( $ii = 0; $ii <= 6; $ii++ ){
277 if( $disabledWeekdays ){
278 $wkd = $this->t->getWeekday();
279 if( in_array($wkd, $disabledWeekdays) ){
280 $this->t->modify('+1 day');
281 continue;
282 }
283 }
284
285 $thisHeader = $this->t->getWeekdayName();
286 $thisHeader = $this->ui->makeBlock( $thisHeader )
287 // ->tag('font-size', 1)
288 ->tag('align', 'center')
289 ;
290 $header[] = $thisHeader;
291 $this->t->modify('+1 day');
292 }
293
294 $header = $this->ui->makeGrid( $header );
295
296 $datesView = $this->self->renderDates( $shiftId );
297
298 $out = $this->ui->makeList( array($header, $datesView) );
299
300 $buttons = $this->ui->makeInputSubmit( '__Save__')
301 ->tag('primary')
302 ;
303
304 $out = array( $out );
305
306 $calendar = $shift->getCalendar();
307 $calendarId = $calendar->getId();
308 $employee = $shift->getEmployee();
309 $employeeId = $employee->getId();
310 $shiftTypeId = 0;
311
312 $out[] = $buttons;
313
314 $out = $this->ui->makeList( $out )->gutter(3);
315
316 // schedule link
317 $scheduleLink = HC3_Session::instance()->getUserdata( 'scheduleLink' );
318 if( ! $scheduleLink ){
319 $scheduleLink = array( 'schedule', array() );
320 }
321 $scheduleLinkValue = json_encode( $scheduleLink );
322 $inputBackHidden = $this->ui->makeInputHidden( 'back', $scheduleLinkValue );
323 $out = $this->ui->makeCollection( array($out, $inputBackHidden) );
324
325 $to = array( 'shifts', $shiftId, 'date' );
326 $to = join( '/', $to );
327 $out = $this->ui->makeForm( $to, $out );
328
329 $this->layout
330 ->setContent( $out )
331 ->setBreadcrumb( $this->common->breadcrumb($shift) )
332 ->setHeader( $this->self->header() )
333 ;
334 $out = $this->layout->render();
335
336 return $out;
337 }
338
339 public function header()
340 {
341 $ret = '__Change Date__';
342 return $ret;
343 }
344 }