blob: c3811977cb266bf0c42cb39d7b7e33d8efcb4978 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
<?php
namespace Engelsystem;
/**
* BO Class that stores all parameters used to filter shifts for users.
*
* @author msquare
*/
class ShiftsFilter
{
/**
* Shift is completely full.
*/
const FILLED_FILLED = 1;
/**
* Shift has some free slots.
*/
const FILLED_FREE = 0;
/**
* Has the user "user shifts admin" privilege?
*
* @var boolean
*/
private $userShiftsAdmin;
/** @var int[] */
private $filled = [];
/** @var int[] */
private $rooms = [];
/** @var int[] */
private $types = [];
/** @var int unix timestamp */
private $startTime = null;
/** @var int unix timestamp */
private $endTime = null;
/**
* ShiftsFilter constructor.
*
* @param bool $user_shifts_admin
* @param int[] $rooms
* @param int[] $types
*/
public function __construct($user_shifts_admin = false, $rooms = [], $types = [])
{
$this->rooms = $rooms;
$this->types = $types;
$this->filled = [
ShiftsFilter::FILLED_FREE
];
if ($user_shifts_admin) {
$this->filled[] = ShiftsFilter::FILLED_FILLED;
}
}
/**
* @return array
*/
public function sessionExport()
{
return [
'userShiftsAdmin' => $this->userShiftsAdmin,
'filled' => $this->filled,
'rooms' => $this->rooms,
'types' => $this->types,
'startTime' => $this->startTime,
'endTime' => $this->endTime,
];
}
/**
* @param array $data
*/
public function sessionImport($data)
{
$this->userShiftsAdmin = $data['userShiftsAdmin'];
$this->filled = $data['filled'];
$this->rooms = $data['rooms'];
$this->types = $data['types'];
$this->startTime = $data['startTime'];
$this->endTime = $data['endTime'];
}
/**
* @return int unix timestamp
*/
public function getStartTime()
{
return $this->startTime;
}
/**
* @param int $startTime unix timestamp
*/
public function setStartTime($startTime)
{
$this->startTime = $startTime;
}
/**
* @return int unix timestamp
*/
public function getEndTime()
{
return $this->endTime;
}
/**
* @param int $endTime unix timestamp
*/
public function setEndTime($endTime)
{
$filterMaxDuration = config('filter_max_duration') * 60 * 60;
if ($filterMaxDuration && ($endTime - $this->startTime > $filterMaxDuration)) {
$endTime = $this->startTime + $filterMaxDuration;
}
$this->endTime = $endTime;
}
/**
* @return int[]
*/
public function getTypes()
{
if (count($this->types) == 0) {
return [0];
}
return $this->types;
}
/**
* @param int[] $types
*/
public function setTypes($types)
{
$this->types = $types;
}
/**
* @return int[]
*/
public function getRooms()
{
if (count($this->rooms) == 0) {
return [0];
}
return $this->rooms;
}
/**
* @param int[] $rooms
*/
public function setRooms($rooms)
{
$this->rooms = $rooms;
}
/**
* @return bool
*/
public function isUserShiftsAdmin()
{
return $this->userShiftsAdmin;
}
/**
* @param bool $userShiftsAdmin
*/
public function setUserShiftsAdmin($userShiftsAdmin)
{
$this->userShiftsAdmin = $userShiftsAdmin;
}
/**
* @return int[]
*/
public function getFilled()
{
return $this->filled;
}
/**
* @param int[] $filled
*/
public function setFilled($filled)
{
$this->filled = $filled;
}
}
|