PluginProbe
ShiftController Employee Shift Scheduling / 4.9.26
ShiftController Employee Shift Scheduling v4.9.26
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.26, at sh4/new/view/calendar.php

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