PluginProbe
ShiftController Employee Shift Scheduling / 4.9.85
ShiftController Employee Shift Scheduling v4.9.85
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 / calendar.php

calendar.php in ShiftController Employee Shift Scheduling 4.9.85, at sh4/new/view/calendar.php

369 lines 9.2 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 interface SH4_New_View_ICalendar
3 {
4 public function render();
5
6 public function renderShift();
7 public function renderTimeoff();
8 public function renderAvailability();
9
10 public function finalize( $entries );
11 public function header();
12 public function renderShiftTypes( $calendar );
13 }
14
15 #[AllowDynamicProperties]
16 class SH4_New_View_Calendar implements SH4_New_View_ICalendar
17 {
18 public function __construct(
19 HC3_Hooks $hooks,
20
21 HC3_Settings $settings,
22 HC3_Request $request,
23 HC3_Ui $ui,
24 HC3_Time $t,
25 HC3_Ui_Layout1 $layout,
26 SH4_New_View_Common $common,
27
28 SH4_App_Query $appQuery,
29 SH4_New_Query $newQuery,
30 SH4_Calendars_Presenter $calendarsPresenter,
31
32 SH4_ShiftTypes_Presenter $shiftTypesPresenter
33 )
34 {
35 $this->request = $request;
36 $this->ui = $ui;
37 $this->t = $t;
38 $this->layout = $layout;
39 $this->common = $hooks->wrap($common);
40 $this->settings = $hooks->wrap($settings);
41
42 $this->appQuery = $hooks->wrap( $appQuery );
43 $this->newQuery = $hooks->wrap( $newQuery );
44 $this->calendarsPresenter = $hooks->wrap( $calendarsPresenter );
45 $this->shiftTypesPresenter = $hooks->wrap( $shiftTypesPresenter );
46
47 $this->self = $hooks->wrap($this);
48 }
49
50 protected function _findAll()
51 {
52 $params = $this->request->getParams();
53
54 $entries = $this->newQuery->findAllCalendars();
55
56 // check if all of them have shift types
57 $ids = array_keys($entries);
58 foreach( $ids as $id ){
59 $shiftTypes = $this->appQuery->findShiftTypesForCalendar( $entries[$id] );
60 if( ! $shiftTypes ){
61 unset( $entries[$id] );
62 }
63 }
64
65 $employee = NULL;
66 if( array_key_exists('employee', $params) ){
67 $employeeId = $params['employee'];
68 $allEmployees = $this->newQuery->findAllEmployees();
69 if( isset($allEmployees[$employeeId]) ){
70 $employee = $allEmployees[$employeeId];
71 }
72 }
73
74 if( $employee ){
75 $filter = $this->appQuery->findCalendarsForEmployee( $employee );
76 $filterIds = array_keys( $filter );
77 $ids = array_keys($entries);
78 foreach( $ids as $id ){
79 if( ! in_array($id, $filterIds) ){
80 unset( $entries[$id] );
81 }
82 }
83 }
84
85 return $entries;
86 }
87
88 public function render()
89 {
90 $entries = $this->_findAll();
91
92 $params = $this->request->getParams();
93
94 if( array_key_exists('calendar', $params) ){
95 $calendarIds = is_array( $params['calendar'] ) ? $params['calendar'] : array( $params['calendar'] );
96 $calendarIds = array_intersect( $calendarIds, array_keys($entries) );
97 if( $calendarIds ){
98 $newEntries = array();
99 foreach( $calendarIds as $calendarId ){
100 $newEntries[ $calendarId ] = $entries[ $calendarId ];
101 }
102 $entries = $newEntries;
103 }
104 }
105
106 $out = $this->finalize( $entries );
107 return $out;
108 }
109
110 public function renderShift()
111 {
112 $entries = $this->_findAll();
113
114 $ids = array_keys($entries);
115 foreach( $ids as $id ){
116 if( ! $entries[$id]->isShift() ){
117 unset( $entries[$id] );
118 }
119 }
120
121 $out = $this->finalize( $entries );
122 return $out;
123 }
124
125 public function renderTimeoff()
126 {
127 $entries = $this->_findAll();
128
129 $ids = array_keys($entries);
130 foreach( $ids as $id ){
131 if( ! $entries[$id]->isTimeoff() ){
132 unset( $entries[$id] );
133 }
134 }
135
136 $out = $this->finalize( $entries );
137 return $out;
138 }
139
140 public function renderAvailability()
141 {
142 $entries = $this->_findAll();
143
144 $ids = array_keys($entries);
145 foreach( $ids as $id ){
146 if( ! $entries[$id]->isAvailability() ){
147 unset( $entries[$id] );
148 }
149 }
150
151 $out = $this->finalize( $entries );
152 return $out;
153 }
154
155 public function finalize( $entries )
156 {
157 $params = $this->request->getParams();
158
159 $out = array();
160 foreach( $entries as $e ){
161 $thisId = $e->getId();
162
163 // $thisLabel = $e->getTitle();
164 // $color = $this->ui->makeBlockInline('&nbsp;')->paddingX(1)->tag('bgcolor', $e->getColor() );
165 // $thisLabel = $this->ui->makeListInline( array($color, $thisLabel) );
166 // $thisLabel = $this->ui->makeBlock( $thisLabel )
167 // ->tag('font-size', 4)
168 // ;
169 $thisLabel = $this->calendarsPresenter->presentTitle( $e );
170
171 $description = $this->calendarsPresenter->presentDescription( $e );
172 if( strlen($description) ){
173 $thisLabel = $this->ui->makeList( array($thisLabel, $description) );
174 }
175
176 // if( strlen($description) ){
177 // $len = 100;
178 // if( strlen($description) > $len ){
179 // $descriptionSummary = substr( $description, 0, $len ) . '...';
180 // $descriptionSummary = $this->ui->makeElement( 'summary', $descriptionSummary );
181 // $descriptionView = $this->ui->makeCollection( array($descriptionSummary, $description) );
182 // $descriptionView = $this->ui->makeElement( 'details', $descriptionView );
183 // }
184 // else {
185 // $descriptionView = $description;
186 // }
187
188 // $thisLabel = $this->ui->makeList( array($thisLabel, $descriptionView) )
189 // ->gutter(0)
190 // ;
191 // }
192
193 $thisView = $this->self->renderShiftTypes( $e );
194 if( $thisView ){
195 $thisView = $this->ui->makeList( array($thisLabel, $thisView) );
196
197 $thisView = $this->ui->makeBlock( $thisView )
198 ->tag('padding', 2)
199 ->tag('border')
200 ->tag('border-color', 'gray')
201 ;
202
203 $out[] = $thisView;
204 }
205 }
206
207 if( isset($params['date']) ){
208 $dateView = $this->t->setDateDb( $params['date'] )->formatDateWithWeekday();
209 $dateView = $this->ui->makeBlock( $dateView )
210 ->tag('font-size', 4)
211 ->tag('paddingX', 2 )
212 ;
213 array_unshift( $out, $dateView );
214 }
215
216 $out = $this->ui->makeList( $out )
217 ->gutter(3)
218 ;
219
220 $this->layout
221 ->setContent( $out )
222 ->setHeader( $this->self->header() )
223 ;
224
225 $out = $this->layout->render();
226 return $out;
227 }
228
229 public function header()
230 {
231 $out = '__Calendar & Time__';
232 return $out;
233 }
234
235 public function renderShiftTypes( $calendar )
236 {
237 $calendarId = $calendar->getId();
238 $params = $this->request->getParams();
239
240 $entries = $this->appQuery->findShiftTypesForCalendar( $calendar );
241 $customTime = NULL;
242 if( array_key_exists(0, $entries) ){
243 $customTime = $entries[0];
244 unset( $entries[0] );
245 }
246
247 $out = array();
248
249 $templatesOut = array();
250 foreach( $entries as $e ){
251 $thisId = $e->getId();
252
253 $thisView = $this->shiftTypesPresenter->presentTitle( $e );
254 $timeView = $this->shiftTypesPresenter->presentTime( $e );
255 $timeView = $this->ui->makeSpan($timeView)
256 ->tag('font-size', 2)
257 ;
258 $thisView = $this->ui->makeList( array($thisView, $timeView) )->gutter(1);
259
260 $to = 'new';
261 $toParams = $params;
262 $toParams['calendar'] = $calendarId;
263 $toParams['shifttype'] = $thisId;
264
265 if( SH4_ShiftTypes_Model::RANGE_DAYS == $e->getRange() ){
266 if( isset($toParams['date']) ){
267 $toParams['start'] = $toParams['date'];
268 unset( $toParams['date'] );
269 }
270 }
271
272 $to = array( $to, $toParams );
273
274 $thisView = $this->ui->makeAhref( $to, $thisView )
275 ->tag('tab-link')
276 ->addAttr( 'class', 'hc-underline' );
277 // ->tag('underline')
278 // ->tag('border')
279 ;
280
281 if( $thisView ){
282 $templatesOut[] = $thisView;
283 }
284 }
285
286 // if we have custom time
287 $out = array();
288
289 if( $customTime ){
290 $thisView = $this->shiftTypesPresenter->presentTitle( $customTime );
291 $thisView = $this->ui->makeBlock( $thisView )
292 ->tag('tab-link')
293 ;
294
295 $to = 'new/customtime/' . $calendarId;
296 $to = array( $to, $params );
297
298 $thisFormInputs = array();
299
300 $value = array();
301 $minTime = $this->settings->get('datetime_min_time');
302 $defaultDuration = $this->settings->get('shifttypes_default_duration');
303 if( (NULL !== $minTime) && (NULL !== $defaultDuration) ){
304 $value = array( $minTime, $minTime + $defaultDuration );
305 }
306 $thisFormInputs[] = $this->ui->makeInputTimeRange( 'time', NULL, $value );
307
308 $noBreak = $this->settings->get( 'shifttypes_nobreak' );
309 if( ! $noBreak ){
310 $thisFormInputs[] = $this->ui->makeCollapseCheckbox(
311 'break_on',
312 '__Lunch Break__' . '?',
313 $this->ui->makeInputTimeRange( 'break', NULL)
314 );
315 }
316
317 $thisFormInputs[] = $this->ui->makeInputSubmit( '__Continue__')->tag('secondary');
318
319 // $thisFormInputs = $this->ui->makeList( $thisFormInputs );
320 $thisFormInputs = $this->ui->makeListInline( $thisFormInputs );
321
322 $thisForm = $this->ui->makeForm( $to, $thisFormInputs );
323
324 $thisForm = $this->ui->makeBlock( $thisForm )
325 // ->tag('border')
326 ->tag('padding', 2)
327 ;
328
329 $out[] = '<h2>__Custom Time__</h2>';
330 $out[] = $thisForm;
331 }
332
333 if( $templatesOut ){
334 foreach( $templatesOut as $to ){
335 $out[] = $to;
336 }
337 }
338
339 if( $out ){
340 $out = $this->ui->makeGrid( $out, 4 );
341 }
342
343 $out2 = array();
344
345 if( $templatesOut ){
346 $templatesOut = $this->ui->makeListInline( $templatesOut );
347
348 $templatesOut = array( $templatesOut );
349 // if( $customTime ){
350 array_unshift( $templatesOut, '<strong>__Select Shift Time__</strong>' );
351 // }
352
353 $templatesOut = $this->ui->makeList( $templatesOut );
354 $out2[] = $templatesOut;
355 }
356
357 if( $customTime ){
358 if( $templatesOut ){
359 $out2[] = '<strong>__Custom Time__</strong>';
360 }
361 $out2[] = $thisForm;
362 }
363
364 $out2 = $this->ui->makeList( $out2 );
365 return $out2;
366
367 return $out;
368 }
369 }