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 / shifts / presenter.php

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

277 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 $ret = null;
123
124 $breakStart = (string) $model->getBreakStart();
125 if( ! strlen($breakStart) ){
126 return $ret;
127 }
128
129 $this->t->setDateTimeDb( $breakStart );
130 $start = $this->t->formatTime();
131
132 $breakEnd = (string) $model->getBreakEnd();
133 $this->t->setDateTimeDb( $breakEnd );
134 $end = $this->t->formatTime();
135
136 $ret = $start . ' - ' . $end;
137 return $ret;
138 }
139
140 public function presentTime( SH4_Shifts_Model $model )
141 {
142 $ret = $this->self->presentRawTime( $model );
143
144 $start = $model->getStart();
145 $end = $model->getEnd();
146
147 $startInDay = $this->t->setDateTimeDb( $start )->getTimeInDay();
148 $startDate = $this->t->setDateTimeDb( $start )->formatDateDb();
149 $endInDay = $this->t->setDateTimeDb( $end )->getTimeInDay();
150 $endDate = $this->t->setDateTimeDb( $end )->formatDateDb();
151 if( $endDate > $startDate ){
152 $endInDay = 24*60*60 + $endInDay;
153 }
154
155 $breakStartInDay = null;
156 $breakEndInDay = null;
157 $breakStart = $model->getBreakStart();
158 $breakEnd = $model->getBreakEnd();
159 if( $breakStart && $breakEnd ){
160 $breakStartInDay = $this->t->setDateTimeDb( $breakStart )->getTimeInDay();
161 $breatStartDate = $this->t->setDateTimeDb( $breakStart )->formatDateDb();
162 $breakEndInDay = $this->t->setDateTimeDb( $breakEnd )->getTimeInDay();
163 $breakEndDate = $this->t->setDateTimeDb( $breakEnd )->formatDateDb();
164 if( $breakEndDate > $breatStartDate ){
165 $breakEndInDay = 24*60*60 + $breakEndInDay;
166 }
167 }
168
169 $timeInDay = $startInDay . '-' . $endInDay;
170 $shiftKey = $startInDay . '-' . $endInDay . '-' . $breakStartInDay . '-' . $breakEndInDay;
171
172 // if we have a matching shifttype
173 reset( $this->shiftTypes );
174 foreach( $this->shiftTypes as $shiftType ){
175 $thisKey = $shiftType->getStart() . '-' . $shiftType->getEnd() . '-' . $shiftType->getBreakStart() . '-' . $shiftType->getBreakEnd();
176 if( $thisKey == $shiftKey ){
177 // $ret = $shiftType->getTitle();
178 $ret = $this->shiftTypesPresenter->presentTitle( $shiftType );
179 break;
180 }
181 }
182
183 return $ret;
184 }
185
186 public function presentStartDate( SH4_Shifts_Model $model )
187 {
188 $this->t->setDateTimeDb( $model->getStart() );
189 $return = $this->t->formatDate();
190 return $return;
191 }
192
193 public function presentStartTime( SH4_Shifts_Model $model )
194 {
195 $this->t->setDateTimeDb( $model->getStart() );
196 $return = $this->t->formatTime();
197 return $return;
198 }
199
200 public function presentEndDate( SH4_Shifts_Model $model )
201 {
202 $this->t->setDateTimeDb( $model->getEnd() );
203 $return = $this->t->formatDate();
204 return $return;
205 }
206
207 public function presentEndTime( SH4_Shifts_Model $model )
208 {
209 $this->t->setDateTimeDb( $model->getEnd() );
210 $return = $this->t->formatTime();
211 return $return;
212 }
213
214 public function presentStatus( SH4_Shifts_Model $model )
215 {
216 $return = $model->isPublished() ? '__Published__' : '__Draft__';
217 return $return;
218 }
219
220 public function export( SH4_Shifts_Model $model, $withContacts = FALSE, $forUser = null )
221 {
222 $return = array();
223
224 $return['id'] = $model->getId();
225
226 $return['start_date'] = $this->presentStartDate( $model );
227 $return['start_time'] = $this->presentStartTime( $model );
228 $return['end_date'] = $this->presentEndDate( $model );
229 $return['end_time'] = $this->presentEndTime( $model );
230
231 $return['start'] = $model->getStart();
232 $return['end'] = $model->getEnd();
233
234 $breakStart = $model->getBreakStart();
235 $breakEnd = $model->getBreakEnd();
236 if( null !== $breakStart ){
237 $return['break_start'] = $breakStart;
238 $return['break_end'] = $breakEnd;
239 }
240
241 $this->shiftsDuration->reset();
242 $this->shiftsDuration->add( $model );
243 $duration = $this->shiftsDuration->getDurationHours();
244 $return['duration'] = $duration;
245
246 $calendar = $model->getCalendar();
247 $return['calendar'] = $calendar->getTitle();
248 $return['calendar_id'] = $calendar->getId();
249
250 $employee = $model->getEmployee();
251 $return['employee'] = $employee->getTitle();
252 $return['employee_id'] = $employee->getId();
253
254 $showUserEmployee = $this->settings->get('shifts_show_employee_user');
255 if( $showUserEmployee ){
256 $user = $this->appQuery->findUserByEmployee( $employee );
257 $return['employee_username'] = $user ? $user->getUsername() : NULL;
258 }
259
260 if( $withContacts ){
261 $email = NULL;
262 $user = $this->appQuery->findUserByEmployee( $employee );
263 if( $user ){
264 $email = $user->getEmail();
265 }
266 $return['employee_email'] = $email;
267 }
268
269 $return['status'] = $this->presentStatus( $model );
270 $return['status_id'] = $model->getStatus();
271
272 // $return['start'] = $model->getStart();
273 // $return['end'] = $model->getEnd();
274
275 return $return;
276 }
277 }