PluginProbe
ShiftController Employee Shift Scheduling / 4.9.68
ShiftController Employee Shift Scheduling v4.9.68
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 / presenter.php

presenter.php in ShiftController Employee Shift Scheduling 4.9.68, at sh4/shifts/presenter.php

275 lines 8.1 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_Shifts_Presenter_
3 {
4 public function presentTitle( SH4_Shifts_Model $model );
5 public function presentFullTime( SH4_Shifts_Model $model );
6 public function presentDate( SH4_Shifts_Model $model );
7 public function presentTime( SH4_Shifts_Model $model );
8 public function presentRawTime( SH4_Shifts_Model $model );
9 public function presentBreak( SH4_Shifts_Model $model );
10
11 public function presentStartDate( SH4_Shifts_Model $model );
12 public function presentStartTime( SH4_Shifts_Model $model );
13 public function presentEndDate( SH4_Shifts_Model $model );
14 public function presentEndTime( SH4_Shifts_Model $model );
15 public function presentStatus( SH4_Shifts_Model $model );
16
17 public function export( SH4_Shifts_Model $model, $withContacts = FALSE );
18 }
19
20 class SH4_Shifts_Presenter implements SH4_Shifts_Presenter_
21 {
22 protected $shiftTypes = array();
23 public $self, $t, $appQuery, $shiftsDuration, $shiftTypesPresenter, $settings;
24
25 public function __construct(
26 HC3_Hooks $hooks,
27 HC3_Time $t,
28
29 SH4_App_Query $appQuery,
30 HC3_Settings $settings,
31
32 SH4_Shifts_Duration $shiftsDuration,
33 SH4_ShiftTypes_Presenter $shiftTypesPresenter,
34 SH4_ShiftTypes_Query $shiftTypes
35 )
36 {
37 $this->t = $t;
38 $this->self = $hooks->wrap($this);
39
40 $this->appQuery = $hooks->wrap( $appQuery );
41 $this->shiftsDuration = $hooks->wrap( $shiftsDuration );
42 $this->shiftTypesPresenter = $hooks->wrap( $shiftTypesPresenter );
43
44 $this->shiftTypes = array();
45 if( $settings->get('shifttypes_show_title') ){
46 $this->shiftTypes = $hooks->wrap( $shiftTypes )->findAll();
47 }
48
49 $this->settings = $hooks->wrap( $settings );
50 }
51
52 public function presentFullTime( SH4_Shifts_Model $model )
53 {
54 $return = array();
55
56 $start = $model->getStart();
57 $end = $model->getEnd();
58
59 $this->t->setDateTimeDb($start);
60 $startDate = $this->t->formatDateDb();
61 $startTs = $this->t->getTimestamp();
62 $this->t->setStartDay();
63 $startDay = $this->t->getTimestamp();
64 $startInDay = $startTs - $startDay;
65
66 $this->t->setDateTimeDb($end);
67 $endTs = $this->t->getTimestamp();
68 $this->t->setStartDay();
69 $startEndDay = $this->t->getTimestamp();
70 $endInDay = $endTs - $startEndDay;
71
72 if( (0 == $startInDay) && (0 == $endInDay) ){
73 $endDate = $this->t->setDateTimeDb($end)->modify('-1 second')->formatDateDb();
74 $return = $this->t->formatDateRange( $startDate, $endDate );
75 }
76 else {
77 $return[] = $this->self->presentDate($model);
78 $return[] = $this->self->presentTime($model);
79 $return = join(' ', $return);
80 }
81
82 return $return;
83 }
84
85 public function presentTitle( SH4_Shifts_Model $model )
86 {
87 $ret = array();
88
89 $ret[] = esc_html( $model->getCalendar()->getTitle() );
90 $ret[] = $this->self->presentFullTime($model);
91 $ret[] = esc_html( $model->getEmployee()->getTitle() );
92
93 $ret = join(' &middot; ', $ret );
94 return $ret;
95 }
96
97 public function presentDate( SH4_Shifts_Model $model )
98 {
99 $this->t->setDateTimeDb( $model->getStart() );
100 $return = $this->t->formatDate();
101 return $return;
102 }
103
104 public function presentRawTime( SH4_Shifts_Model $model )
105 {
106 $this->t->setDateTimeDb( $model->getStart() );
107 $start = $this->t->formatTime();
108
109 $this->t->setDateTimeDb( $model->getEnd() );
110 $end = $this->t->formatTime();
111 $endInDay = $model->getEndInDay();
112 if( $endInDay > 24*60*60 ){
113 $end = '&gt;' . $end;
114 }
115
116 $return = $start . ' - ' . $end;
117 return $return;
118 }
119
120 public function presentBreak( SH4_Shifts_Model $model )
121 {
122 $return = NULL;
123 $breakStart = $model->getBreakStart();
124 if( NULL === $breakStart ){
125 return $return;
126 }
127
128 $this->t->setDateTimeDb( $model->getBreakStart() );
129 $start = $this->t->formatTime();
130
131 $this->t->setDateTimeDb( $model->getBreakEnd() );
132 $end = $this->t->formatTime();
133
134 $return = $start . ' - ' . $end;
135 return $return;
136 }
137
138 public function presentTime( SH4_Shifts_Model $model )
139 {
140 $ret = $this->self->presentRawTime( $model );
141
142 $start = $model->getStart();
143 $end = $model->getEnd();
144
145 $startInDay = $this->t->setDateTimeDb( $start )->getTimeInDay();
146 $startDate = $this->t->setDateTimeDb( $start )->formatDateDb();
147 $endInDay = $this->t->setDateTimeDb( $end )->getTimeInDay();
148 $endDate = $this->t->setDateTimeDb( $end )->formatDateDb();
149 if( $endDate > $startDate ){
150 $endInDay = 24*60*60 + $endInDay;
151 }
152
153 $breakStartInDay = null;
154 $breakEndInDay = null;
155 $breakStart = $model->getBreakStart();
156 $breakEnd = $model->getBreakEnd();
157 if( $breakStart && $breakEnd ){
158 $breakStartInDay = $this->t->setDateTimeDb( $breakStart )->getTimeInDay();
159 $breatStartDate = $this->t->setDateTimeDb( $breakStart )->formatDateDb();
160 $breakEndInDay = $this->t->setDateTimeDb( $breakEnd )->getTimeInDay();
161 $breakEndDate = $this->t->setDateTimeDb( $breakEnd )->formatDateDb();
162 if( $breakEndDate > $breatStartDate ){
163 $breakEndInDay = 24*60*60 + $breakEndInDay;
164 }
165 }
166
167 $timeInDay = $startInDay . '-' . $endInDay;
168 $shiftKey = $startInDay . '-' . $endInDay . '-' . $breakStartInDay . '-' . $breakEndInDay;
169
170 // if we have a matching shifttype
171 reset( $this->shiftTypes );
172 foreach( $this->shiftTypes as $shiftType ){
173 $thisKey = $shiftType->getStart() . '-' . $shiftType->getEnd() . '-' . $shiftType->getBreakStart() . '-' . $shiftType->getBreakEnd();
174 if( $thisKey == $shiftKey ){
175 // $ret = $shiftType->getTitle();
176 $ret = $this->shiftTypesPresenter->presentTitle( $shiftType );
177 break;
178 }
179 }
180
181 return $ret;
182 }
183
184 public function presentStartDate( SH4_Shifts_Model $model )
185 {
186 $this->t->setDateTimeDb( $model->getStart() );
187 $return = $this->t->formatDate();
188 return $return;
189 }
190
191 public function presentStartTime( SH4_Shifts_Model $model )
192 {
193 $this->t->setDateTimeDb( $model->getStart() );
194 $return = $this->t->formatTime();
195 return $return;
196 }
197
198 public function presentEndDate( SH4_Shifts_Model $model )
199 {
200 $this->t->setDateTimeDb( $model->getEnd() );
201 $return = $this->t->formatDate();
202 return $return;
203 }
204
205 public function presentEndTime( SH4_Shifts_Model $model )
206 {
207 $this->t->setDateTimeDb( $model->getEnd() );
208 $return = $this->t->formatTime();
209 return $return;
210 }
211
212 public function presentStatus( SH4_Shifts_Model $model )
213 {
214 $return = $model->isPublished() ? '__Published__' : '__Draft__';
215 return $return;
216 }
217
218 public function export( SH4_Shifts_Model $model, $withContacts = FALSE, $forUser = null )
219 {
220 $return = array();
221
222 $return['id'] = $model->getId();
223
224 $return['start_date'] = $this->presentStartDate( $model );
225 $return['start_time'] = $this->presentStartTime( $model );
226 $return['end_date'] = $this->presentEndDate( $model );
227 $return['end_time'] = $this->presentEndTime( $model );
228
229 $return['start'] = $model->getStart();
230 $return['end'] = $model->getEnd();
231
232 $breakStart = $model->getBreakStart();
233 $breakEnd = $model->getBreakEnd();
234 if( null !== $breakStart ){
235 $return['break_start'] = $breakStart;
236 $return['break_end'] = $breakEnd;
237 }
238
239 $this->shiftsDuration->reset();
240 $this->shiftsDuration->add( $model );
241 $duration = $this->shiftsDuration->getDurationHours();
242 $return['duration'] = $duration;
243
244 $calendar = $model->getCalendar();
245 $return['calendar'] = $calendar->getTitle();
246 $return['calendar_id'] = $calendar->getId();
247
248 $employee = $model->getEmployee();
249 $return['employee'] = $employee->getTitle();
250 $return['employee_id'] = $employee->getId();
251
252 $showUserEmployee = $this->settings->get('shifts_show_employee_user');
253 if( $showUserEmployee ){
254 $user = $this->appQuery->findUserByEmployee( $employee );
255 $return['employee_username'] = $user ? $user->getUsername() : NULL;
256 }
257
258 if( $withContacts ){
259 $email = NULL;
260 $user = $this->appQuery->findUserByEmployee( $employee );
261 if( $user ){
262 $email = $user->getEmail();
263 }
264 $return['employee_email'] = $email;
265 }
266
267 $return['status'] = $this->presentStatus( $model );
268 $return['status_id'] = $model->getStatus();
269
270 // $return['start'] = $model->getStart();
271 // $return['end'] = $model->getEnd();
272
273 return $return;
274 }
275 }