PluginProbe
ShiftController Employee Shift Scheduling / 4.9.95
ShiftController Employee Shift Scheduling v4.9.95
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 / model.php

model.php in ShiftController Employee Shift Scheduling 4.9.95, at sh4/shifts/model.php

320 lines 6.8 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_Model_
3 {
4 public function getId();
5 public function setId( $id );
6 public function getTitle();
7 public function getCalendar();
8 public function getEmployee();
9
10 public function getStart();
11 public function getEnd();
12 public function setStart( $start );
13 public function setEnd( $end );
14
15 public function getBreakStart();
16 public function getBreakEnd();
17
18 public function getStartInDay();
19 public function getEndInDay();
20 public function getBreakStartInDay();
21 public function getBreakEndInDay();
22
23 public function getDateStart();
24 public function getDateEnd();
25
26 public function isMultiDay();
27
28 public function isPublished();
29 public function isDraft();
30 public function isOpen();
31
32 public function setRawData( $data );
33 public function setRawDataByKey( $key, $value );
34 public function getRawData( $key );
35 public function getRawDataKeys();
36
37 public function getGroupingId();
38 }
39
40 class SH4_Shifts_Model implements SH4_Shifts_Model_
41 {
42 const STATUS_PUBLISH = 'publish';
43 const STATUS_DRAFT = 'draft';
44
45 public $id = NULL;
46 public $calendar = NULL;
47
48 public $start = NULL;
49 public $end = NULL;
50 public $breakStart = NULL;
51 public $breakEnd = NULL;
52
53 public $employee = NULL;
54 public $status = self::STATUS_DRAFT;
55
56 public $raw = array();
57
58 public function __construct( $id, SH4_Calendars_Model $calendar, $start, $end, SH4_Employees_Model $employee, $breakStart = NULL, $breakEnd = NULL, $status = self::STATUS_DRAFT )
59 {
60 $this->id = $id;
61 $this->calendar = $calendar;
62 $this->start = $start;
63 $this->end = $end;
64 $this->breakStart = $breakStart;
65 $this->breakEnd = $breakEnd;
66 $this->employee = $employee;
67 $this->status = $status;
68 }
69
70 public function getGroupingId()
71 {
72 $ret = array();
73
74 $ret[] = $this->getStart();
75 $ret[] = $this->getEnd();
76 $ret[] = $this->getCalendar()->getId();
77 $ret[] = $this->isPublished() ? 1 : 0;
78
79 $moreKeys = $this->getRawDataKeys();
80 $moreKeys = array_filter( $moreKeys, function($e){ return ('meta_' === substr($e, 0, strlen('meta_'))); } );
81
82 foreach( $moreKeys as $k ){
83 $v = $this->getRawData( $k );
84 if( is_string($v) ){
85 $ret[] = $v;
86 }
87 }
88
89 $ret = join( '-', $ret );
90 return $ret;
91 }
92
93 public function setRawData( $data )
94 {
95 $this->raw = $data;
96 return $this;
97 }
98
99 public function setRawDataByKey( $key, $value )
100 {
101 $this->raw[$key] = $value;
102 return $this;
103 }
104
105 public function getRawData( $key )
106 {
107 $return = array_key_exists( $key, $this->raw ) ? $this->raw[$key] : NULL;
108 return $return;
109 }
110
111 public function getRawDataKeys()
112 {
113 return array_keys( $this->raw );
114 }
115
116 public function getId()
117 {
118 return $this->id;
119 }
120
121 public function setId( $id )
122 {
123 $this->id = $id;
124 return $this;
125 }
126
127 public function getStatus()
128 {
129 return $this->status;
130 }
131
132 public function isPublished()
133 {
134 return ($this->status == self::STATUS_PUBLISH);
135 }
136
137 public function isDraft()
138 {
139 return ($this->status == self::STATUS_DRAFT);
140 }
141
142 public function getTitle()
143 {
144 $return = array();
145 $return[] = $this->getStart();
146 $return[] = $this->getEnd();
147 $return = join('-', $return);
148 return $return;
149 }
150
151 public function getCalendar()
152 {
153 return $this->calendar;
154 }
155
156 public function getEmployee()
157 {
158 return $this->employee;
159 }
160
161 public function isOpen()
162 {
163 $employee = $this->getEmployee();
164 $employeeId = $employee->getId();
165
166 $return = ( $employeeId == 0 ) ? TRUE : FALSE;
167 return $return;
168 }
169
170 public function getStart()
171 {
172 return $this->start;
173 }
174
175 public function getEnd()
176 {
177 return $this->end;
178 }
179
180 public function setStart( $start )
181 {
182 $this->start = $start;
183 return $this;
184 }
185
186 public function setEnd( $end )
187 {
188 $this->end = $end;
189 return $this;
190 }
191
192 public function getBreakStart()
193 {
194 return $this->breakStart;
195 }
196
197 public function getBreakEnd()
198 {
199 return $this->breakEnd;
200 }
201
202 public function getStartInDay()
203 {
204 $full = $this->getStart();
205
206 $hour = substr( $full, 8, 2 );
207 $minute = substr( $full, 10, 2 );
208 $return = $hour * 60 * 60 + $minute * 60;
209
210 return $return;
211 }
212
213 public function getEndInDay()
214 {
215 $start = $this->getStart();
216 $end = $this->getEnd();
217
218 $full = $this->getEnd();
219
220 $hour = substr( $full, 8, 2 );
221 $minute = substr( $full, 10, 2 );
222 $return = $hour * 60 * 60 + $minute * 60;
223
224 if( $return ){
225 $d1 = substr( $start, 0, 8 );
226 $d2 = substr( $end, 0, 8 );
227
228 // overnight shifts
229 if( $d2 > $d1 ){
230 if (function_exists('gregoriantojd')) {
231 $days = gregoriantojd((int) substr($end, 4, 2), (int) substr($end, 6, 2), (int) substr($end, 0, 4)) - gregoriantojd((int) substr($start, 4, 2), (int) substr($start, 6, 2), (int) substr($start, 0, 4));
232 $return = $return + $days * 24*60*60;
233 } else {
234 $string1 = substr($start, 0, 4) . '-' . substr($start, 4, 2) . '-' . substr($start, 6, 2) . ' ' . '00:00:00';
235 $string2 = substr($end, 0, 4) . '-' . substr($end, 4, 2) . '-' . substr($end, 6, 2) . ' ' . substr($end, 8, 2) . ':' . substr($end, 10, 2) . ':00';
236 $date = new DateTime( $string1 );
237 $date2 = new DateTime( $string2 );
238 $return = $date2->getTimestamp() - $date->getTimestamp();
239 }
240 }
241
242 // overnight shifts
243 /*
244 $startInDay = $this->getStartInDay();
245 if( $return <= $startInDay ){
246 $return = 24*60*60 + $return;
247 }
248 */
249 }
250
251 if( 0 == $return ){
252 $return = 24*60*60;
253 }
254
255 return $return;
256 }
257
258 public function getBreakStartInDay()
259 {
260 $ret = null;
261
262 $full = (string) $this->getBreakStart();
263 if( ! $full ){
264 return $ret;
265 }
266
267 $hour = (int) substr( $full, 8, 2 );
268 $minute = (int) substr( $full, 10, 2 );
269 $ret = $hour * 60 * 60 + $minute * 60;
270
271 return $ret;
272 }
273
274 public function getBreakEndInDay()
275 {
276 $ret = null;
277
278 $full = (string) $this->getBreakEnd();
279 if( ! $full ){
280 return $ret;
281 }
282
283 $hour = (int) substr( $full, 8, 2 );
284 $minute = (int) substr( $full, 10, 2 );
285 $ret = $hour * 60 * 60 + $minute * 60;
286
287 if( 0 == $ret ){
288 $ret = 24*60*60;
289 }
290
291 return $ret;
292 }
293
294 public function getDateStart()
295 {
296 $full = $this->getStart();
297 $return = substr( $full, 0, 8 );
298 return $return;
299 }
300
301 public function getDateEnd()
302 {
303 $full = $this->getEnd();
304 $return = substr( $full, 0, 8 );
305 return $return;
306 }
307
308 public function isMultiDay()
309 {
310 $startInDay = $this->getStartInDay();
311 $endInDay = $this->getEndInDay();
312
313 $return = FALSE;
314 if( (0 == $startInDay) && ((24*60*60 == $endInDay) OR (0 == $endInDay)) ){
315 $return = TRUE;
316 }
317
318 return $return;
319 }
320 }