PluginProbe
ShiftController Employee Shift Scheduling / 4.9.60
ShiftController Employee Shift Scheduling v4.9.60
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 / new / view / employee.php

employee.php in ShiftController Employee Shift Scheduling 4.9.60, at sh4/new/view/employee.php

385 lines 10.0 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_New_View_Employee
4 {
5 public function __construct(
6 HC3_Hooks $hooks,
7
8 HC3_Request $request,
9 HC3_Ui $ui,
10 HC3_Ui_Layout1 $layout,
11 HC3_Settings $settings,
12
13 SH4_New_View_Common $common,
14
15 SH4_Shifts_Conflicts $conflicts,
16 SH4_Shifts_Availability $availability,
17
18 SH4_Calendars_Query $calendars,
19 SH4_Employees_Query $employees,
20
21 SH4_ShiftTypes_Query $shiftTypesQuery,
22 SH4_Employees_Presenter $employeesPresenter,
23 SH4_App_Query $appQuery,
24 SH4_New_Query $newQuery,
25
26 HC3_Time $t
27 )
28 {
29 $this->self = $hooks->wrap( $this );
30
31 $this->request = $request;
32 $this->ui = $ui;
33 $this->layout = $layout;
34 $this->common = $hooks->wrap($common);
35
36 $this->t = $t;
37
38 $this->settings = $hooks->wrap( $settings );
39
40 $this->conflicts = $hooks->wrap($conflicts);
41 $this->availability = $hooks->wrap( $availability );
42
43 $this->calendars = $hooks->wrap($calendars);
44 $this->employees = $hooks->wrap($employees);
45
46 $this->shiftTypesQuery = $hooks->wrap( $shiftTypesQuery );
47 $this->employeesPresenter = $hooks->wrap( $employeesPresenter );
48 $this->appQuery = $hooks->wrap( $appQuery );
49 $this->newQuery = $hooks->wrap( $newQuery );
50 }
51
52 public function render()
53 {
54 $params = $this->request->getParams();
55
56 $dateString = $params['date'];
57 $shiftTypeId = $params['shifttype'];
58 $calendarId = $params['calendar'];
59
60 $dates = HC3_Functions::unglueArray( $dateString );
61 $datesView = array();
62 foreach( $dates as $date ){
63 $this->t->setDateDb( $date );
64 $dateView = $this->t->getWeekdayName() . ', ' . $this->t->formatDate();
65 $datesView[] = $dateView;
66 }
67
68 $shiftType = $this->shiftTypesQuery->findById( $shiftTypeId );
69 $range = $shiftType->getRange();
70
71 switch( $range ){
72 case SH4_ShiftTypes_Model::RANGE_DAYS:
73 $datesView = $this->ui->makeListInline( $datesView )
74 ->separated( '&rarr;' )
75 ;
76 $datesView = array( $datesView );
77 break;
78 }
79
80 // employees
81 $calendars = $this->newQuery->findAllCalendars();
82 if( array_key_exists($calendarId, $calendars) ){
83 $calendar = $calendars[$calendarId];
84 }
85 else {
86 $calendar = NULL;
87 }
88
89 if( ! $calendar ){
90 return;
91 }
92
93 $isAvailability = $calendar->isAvailability();
94
95 $employees = $this->newQuery->findAllEmployees();
96 if( $calendar ){
97 $filter = $this->appQuery->findEmployeesForCalendar( $calendar );
98
99 $filterIds = array_keys( $filter );
100 $ids = array_keys( $employees );
101 foreach( $ids as $id ){
102 if( ! in_array($id, $filterIds) ){
103 unset( $employees[$id] );
104 }
105 }
106 }
107
108 if( ! $employees ){
109 return;
110 }
111
112 if( count($employees) == 1 ){
113 $params = $this->request->getParams();
114 $employee = current( $employees );
115 $employeeId = $employee->getId();
116
117 $to = 'new';
118 $toParams = array(
119 'calendar' => $calendarId,
120 'shifttype' => $shiftTypeId,
121 'date' => $dateString,
122 'employee' => $employeeId
123 );
124 $to = array( $to, $toParams );
125
126 $return = array( $to, NULL );
127 return $return;
128 }
129
130 $employeesView = array();
131 $employeesWithConflictsView = array();
132
133 foreach( $employees as $employee ){
134 $withConflicts = 0;
135 $withAvailability = 0;
136 $withNothing = 0;
137
138 $employeeId = $employee->getId();
139 $thisView = array();
140
141 if( $employeeId ){
142 $label = $this->employeesPresenter->presentTitle( $employee );
143 $input = $this->ui->makeInputCheckbox( 'employee[]', $label, $employeeId );
144
145 $descriptionView = $employee->getDescription();
146 if( strlen($descriptionView) ){
147 $descriptionView = $this->ui->makeLongText( $descriptionView );
148 $input = $this->ui->makeList( array($input, $descriptionView) )
149 ->gutter(1)
150 ;
151 }
152
153 $thisView[] = $input;
154 }
155 // open shift
156 else {
157 $label = $this->employeesPresenter->presentTitle( $employee );
158 $options = array();
159 $options[0] = $label;
160 for( $ii = 1; $ii <= 50; $ii++ ){
161 $options[ '0' . SH4_NEW_OPEN_SEPARATOR . $ii ] = $ii;
162 }
163 $input = $this->ui->makeInputSelect( 'employee[]', NULL, $options );
164 $thisView[] = $input;
165 }
166
167 // check conflicts
168 if( $employeeId && (! $isAvailability) ){
169 $testModels = array();
170
171 $range = $shiftType->getRange();
172 switch( $range ){
173 case SH4_ShiftTypes_Model::RANGE_DAYS:
174 $start = $this->t->setDateDb( $dates[0] )
175 ->formatDateTimeDb()
176 ;
177 $end = $this->t->setDateDb( $dates[1] )
178 ->modify('+1 day')
179 ->formatDateTimeDb()
180 ;
181
182 $testModel = new SH4_Shifts_Model( NULL, $calendar, $start, $end, $employee );
183 $testModels[] = $testModel;
184 break;
185
186 case SH4_ShiftTypes_Model::RANGE_HOURS:
187 $timeStart = $shiftType->getStart();
188 $timeEnd = $shiftType->getEnd();
189 reset( $dates );
190 foreach( $dates as $date ){
191 $start = $this->t->setDateDb( $date )
192 ->modify( '+' . $timeStart . ' seconds' )
193 ->formatDateTimeDb()
194 ;
195 $end = $this->t->setDateDb( $date )
196 ->modify( '+' . $timeEnd . ' seconds' )
197 ->formatDateTimeDb()
198 ;
199 $testModel = new SH4_Shifts_Model( NULL, $calendar, $start, $end, $employee );
200 $testModels[] = $testModel;
201 }
202 break;
203 }
204
205 reset( $testModels );
206 foreach( $testModels as $testModel ){
207 $conflicts = $this->conflicts->get( $testModel );
208 if( $conflicts ){
209 $withConflicts++;
210 }
211 else {
212 if( (! $this->availability->hasAvailability()) OR $this->availability->get($testModel) ){
213 $withAvailability++;
214 }
215 else {
216 $withNothing++;
217 }
218 }
219 }
220
221 $conflictsView = array();
222 if( $withAvailability ){
223 $sign = ( count($testModels) < 2 ) ? '&check;' : $withAvailability;
224 $sign = $this->ui->makeBlock( $sign )
225 ->tag('padding', 'x1')
226 ->tag('color', 'white')
227 ->tag('bgcolor', 'olive')
228 ->addAttr( 'title', '__Available__' )
229 ;
230 $conflictsView[] = $sign;
231 }
232
233 if( $withNothing ){
234 $sign = ( count($testModels) < 2 ) ? '&check;' : $withNothing;
235 $sign = $this->ui->makeBlock( $sign )
236 ->tag('padding', 'x1')
237 ->tag('color', 'white')
238 ->tag('bgcolor', 'gray')
239 ->addAttr( 'title', '__No Availability__' )
240 ;
241 $conflictsView[] = $sign;
242 }
243
244 if( $withConflicts ){
245 $sign = (count($testModels) < 2) ? '&nbsp;!&nbsp;' : $withConflicts;
246 $sign = $this->ui->makeBlock( $sign )
247 ->tag('padding', 'x1')
248 ->tag('color', 'white')
249 ->tag('bgcolor', 'maroon')
250 ->addAttr( 'title', '__Conflicts__' )
251 ;
252 $conflictsView[] = $sign;
253 }
254
255 $conflictsView = $this->ui->makeListInline( $conflictsView )
256 ->gutter(1)
257 ;
258 $thisView[] = $conflictsView;
259 }
260
261 $thisView = $this->ui->makeListInline( $thisView );
262 $thisView = $this->ui->makeBlock( $thisView )
263 ->addAttr('style', 'position: relative;')
264 ;
265
266 $thisView = $this->ui->makeBlock( $thisView )
267 ->tag('border')
268 ->tag('padding', 2)
269 ;
270
271 if( $withAvailability == count($dates) ){
272 $thisView
273 ->tag('border-color', 'green')
274 ;
275 }
276 elseif( $withConflicts ){
277 $thisView
278 ->tag('border-color', 'red')
279 ;
280 }
281 else {
282 $thisView
283 ->tag('border-color', 'gray')
284 ;
285 }
286
287 if( $withConflicts ){
288 $employeesWithConflictsView[] = $thisView;
289 }
290 else {
291 $employeesView[] = $thisView;
292 }
293 }
294
295 $employeesView = $this->ui->makeListInline( $employeesView );
296
297 $toggleAllLabel = '__Select All__';
298 $toggleAll = $this->ui->makeInputCheckbox( 'toggle', $toggleAllLabel, 1 )
299 ->addAttr( 'class', 'sh4-new-employee-toggler' )
300 ;
301
302 $employeesView = $this->ui->makeList( array($toggleAll, $employeesView) );
303
304 $js = <<<EOT
305
306 <script language="JavaScript">
307 jQuery('.sh4-new-employee-container').on( 'change', '.sh4-new-employee-toggler', function(event){
308 var \$checkers = jQuery(this).closest('.sh4-new-employee-container').find('input[type="checkbox"]');
309 var meOn = jQuery(this).prop('checked');
310 \$checkers.each( function(){
311 var \$checker = jQuery(this);
312 if ( ! \$checker.hasClass('sh4-new-employee-toggler') ){
313 // \$checker.prop( 'checked', ! \$checker.prop('checked') );
314 \$checker.prop( 'checked', meOn );
315 }
316 });
317 return false;
318 });
319 </script>
320
321 EOT;
322
323 $employeesView = $this->ui->makeCollection( array($js, $employeesView) );
324 $employeesView = $this->ui->makeBlock( $employeesView )
325 ->addAttr( 'class', 'sh4-new-employee-container' )
326 ;
327
328 $out = array();
329 $out[] = $employeesView;
330
331 if( $employeesWithConflictsView ){
332 $employeesWithConflictsView = $this->ui->makeListInline( $employeesWithConflictsView );
333 $employeesWithConflictsView = $this->ui->makeCollapse( '__Unavailable Employees__', $employeesWithConflictsView );
334 $out[] = $employeesWithConflictsView;
335 }
336
337 $btn = $this->self->buttons( $calendarId, $shiftTypeId );
338 $btn = $this->ui->makeListInline( $btn );
339
340 // open shift
341 // $inputs = $this->common->inputs( $calendarId, $shiftTypeId, $employeeId );
342 // $out = array_merge( $out, $inputs );
343
344 $out[] = $btn;
345
346 $out = $this->ui->makeList( $out )->gutter(3);
347
348
349
350 $to = 'new/employee';
351 $toParams = $params;
352 $to = array( $to, $toParams );
353
354 $out = $this->ui->makeForm( $to, $out );
355
356 $breadcrumb = array();
357 $breadcrumb[] = $this->common->breadcrumb($calendarId, $shiftTypeId);
358 $breadcrumb[] = $datesView;
359
360 $this->layout
361 ->setContent( $out )
362 ->setBreadcrumb( $breadcrumb, TRUE )
363 ->setHeader( $this->self->header() )
364 ;
365 $out = $this->layout->render();
366
367 return $out;
368 }
369
370 public function buttons( $calendarId, $shiftTypeId )
371 {
372 $btn = $this->ui->makeInputSubmit( '__Continue__')
373 ->tag('primary')
374 ;
375
376 $return = array( 'continue' => $btn );
377 return $return;
378 }
379
380 public function header()
381 {
382 $out = '__Employee__';
383 return $out;
384 }
385 }