PluginProbe
ShiftController Employee Shift Scheduling / 4.9.69
ShiftController Employee Shift Scheduling v4.9.69
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.69, at sh4/shifts/model.php

298 lines 5.7 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 $full = $this->getEnd();
216
217 $hour = substr( $full, 8, 2 );
218 $minute = substr( $full, 10, 2 );
219 $return = $hour * 60 * 60 + $minute * 60;
220
221 if( $return ){
222 $startInDay = $this->getStartInDay();
223 // overnight shifts
224 if( $return <= $startInDay ){
225 $return = 24*60*60 + $return;
226 }
227 }
228
229 if( 0 == $return ){
230 $return = 24*60*60;
231 }
232
233 return $return;
234 }
235
236 public function getBreakStartInDay()
237 {
238 $return = NULL;
239
240 $full = $this->getBreakStart();
241 if( NULL === $full ){
242 return $return;
243 }
244
245 $hour = substr( $full, 8, 2 );
246 $minute = substr( $full, 10, 2 );
247 $return = $hour * 60 * 60 + $minute * 60;
248
249 return $return;
250 }
251
252 public function getBreakEndInDay()
253 {
254 $return = NULL;
255
256 $full = $this->getBreakEnd();
257 if( NULL === $full ){
258 return $return;
259 }
260
261 $hour = substr( $full, 8, 2 );
262 $minute = substr( $full, 10, 2 );
263 $return = $hour * 60 * 60 + $minute * 60;
264
265 if( 0 == $return ){
266 $return = 24*60*60;
267 }
268
269 return $return;
270 }
271
272 public function getDateStart()
273 {
274 $full = $this->getStart();
275 $return = substr( $full, 0, 8 );
276 return $return;
277 }
278
279 public function getDateEnd()
280 {
281 $full = $this->getEnd();
282 $return = substr( $full, 0, 8 );
283 return $return;
284 }
285
286 public function isMultiDay()
287 {
288 $startInDay = $this->getStartInDay();
289 $endInDay = $this->getEndInDay();
290
291 $return = FALSE;
292 if( (0 == $startInDay) && ((24*60*60 == $endInDay) OR (0 == $endInDay)) ){
293 $return = TRUE;
294 }
295
296 return $return;
297 }
298 }