forked from ding2/ding_provider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ding_provider.reservation.inc
245 lines (211 loc) · 5.47 KB
/
ding_provider.reservation.inc
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<?php
/**
* @file
* Ding reservation related classes.
*/
/**
* Class representing a reservation.
*/
class DingProviderReservation extends DingEntityBase {
/**
* Value of DingProviderReservation::status if the reservation is active.
*/
const STATUS_ACTIVE = 1;
/**
* Value of DingProviderReservation::status if the reservation is ready for
* pickup.
*/
const STATUS_FECTHABLE = 2;
/**
* Id of the reservation. Used as identifier. No assumptions are made about
* it, however it should be a sting value suitable for values in forms and
* the like.
*/
protected $id = DingEntityBase::NULL;
/**
* Materials number, optional. Is shown to the user.
*/
protected $materials_number = DingEntityBase::NULL;
/**
* Id of the ding_entity.
*/
protected $ding_entity_id = DingEntityBase::NULL;
/**
* Boolean for if reservation is ready for pickup.
*/
protected $ready_for_pickup = DingEntityBase::NULL;
/**
* Pickup date
*/
protected $pickup_date = DingEntityBase::NULL;
/**
* Order Id
*/
protected $order_id = DingEntityBase::NULL;
/**
* Organisation Id
*/
protected $organisation_Id = DingEntityBase::NULL;
/**
* The ding_entity.
*/
protected $entity = DingEntityBase::NULL;
/**
* Fallback display if the reservation is an obscure material that is not
* known by the datawell.
*/
protected $display_name = DingEntityBase::NULL;
/**
* Status of the reservation, either DingProviderReservation::STATUS_ACTIVE
* or DingProviderReservation::STATUS_FECTHABLE.
*/
protected $status = DingEntityBase::NULL;
/**
* Delete status of the reservation, either yes or no
*/
protected $can_delete = DingEntityBase::NULL;
/**
* Id of pickup place.
*/
protected $pickup_branch_id = DingEntityBase::NULL;
/**
* Id of pickup place.
*/
protected $pickup_order_id = DingEntityBase::NULL;
/**
* Creation date of reservation. Format: YYYY-MM-DD.
*/
protected $created = DingEntityBase::NULL;
/**
* Reservation valid to. Format: YYYY-MM-DD.
*
* For DingProviderReservation::STATUS_ACTIVE this is when the reservation
* expires, for DingProviderReservation::STATUS_FECTHABLE it is the last
* pickup date.
*/
protected $expiry = DingEntityBase::NULL;
/**
* Queue number. optional. Only valid for
* DingProviderReservation::STATUS_ACTIVE reservations.
*/
protected $queue_number = DingEntityBase::NULL;
/**
* Pickup number. Only valid for DingProviderReservation::STATUS_FECTHABLE
* reservations.
*/
protected $pickup_number = DingEntityBase::NULL;
/**
* Notes - some additional information.
*/
protected $notes = DingEntityBase::NULL;
/*
titel
type
forfatter
sprog
materiale nr
*/
public function __construct($id, $data = array()) {
parent::__construct();
$this->properties['id'] = $id;
// Default display name.
$this->properties['display_name'] = t('Title not available');
$this->properties['ready_for_pickup'] = FALSE;
$properties = array(
'order_id',
'organisation_Id',
'materials_number',
'ding_entity_id',
'entity',
'display_name',
'status',
'can_delete',
'pickup_branch',
'pickup_order_id',
'pickup_branch_id',
'created',
'expiry',
'queue_number',
'pickup_number',
'pickup_date',
'notes',
'ready_for_pickup',
);
$this->_populate($properties, $data);
}
function getPickup_branch() {
return ding_provider_invoke('reservation', 'branch_name', $this->pickup_branch);
}
function getEntity() {
if (!isset($this->entity)) {
if (!empty($this->ding_entity_id)) {
$this->entity = ding_entity_load($this->ding_entity_id);
}
else {
$this->entity = NULL;
}
}
return $this->entity;
}
function getTitle() {
$this->getEntity();
if ($this->entity) {
return $this->title = $this->entity->title;
}
}
function getCreator() {
$this->getEntity();
if ($this->entity) {
return $this->creator = $this->entity->creator;
}
}
function getType() {
$this->getEntity();
if ($this->entity) {
return $this->type = $this->entity->type;
}
}
function getLanguage() {
$this->getEntity();
if ($this->entity) {
return $this->language = $this->entity->language;
}
}
}
/**
* Parent class for reservation errors.
*/
class DingProviderReservationUserError extends DingProviderUserException {}
/**
* Exception thrown when the item is already reserved.
*/
class DingProviderReservationExists extends DingProviderReservationUserError{
public function __construct($message = "", $code = 0) {
if (empty($message)) {
$message = t('"You have already reserved "@title".');
}
parent::__construct($message);
}
}
/**
* The item is not available for reservation.
*/
class DingProviderReservationNotAvailable extends DingProviderReservationUserError {
public function __construct($message = "", $code = 0) {
if (empty($message)) {
$message = t('"@title" is not available for reservation.');
}
parent::__construct($message);
}
}
/**
* Reservation is not allowed.
*/
class DingProviderReservationNotAllowed extends DingProviderReservationUserError{
public function __construct($message = "", $code = 0) {
if (empty($message)) {
$message = t("You're not allowed to reserve \"@title\".");
}
parent::__construct($message);
}
}