forked from compucorp/civibooking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
booking.php
453 lines (416 loc) · 13.6 KB
/
booking.php
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
<?php
require_once 'booking.civix.php';
/**
* Implementation of hook_civicrm_tabs()
*
* Display a booking tab listing booking belong to that contact.
*/
function booking_civicrm_tabs(&$tabs, $cid) {
$count = CRM_Booking_BAO_Booking::getBookingContactCount($cid); //TODO Count number of booking and show on the tab
$tab = array(
'id' => 'booking',
'count' => $count,
'title' => 'Bookings',
'weight' => 0, //we are at first tab
);
$tab['url'] = CRM_Utils_System::url('civicrm/contact/view/booking', "reset=1&cid={$cid}&snippet=1&force=1", false, null, false);
$tabs[] = $tab;
}
/**
* Implementation of hook_civicrm_config
*/
function booking_civicrm_config(&$config) {
_booking_civix_civicrm_config($config);
}
/**
* Implementation of hook_civicrm_xmlMenu
*
* @param $files array(string)
*/
function booking_civicrm_xmlMenu(&$files) {
_booking_civix_civicrm_xmlMenu($files);
}
/**
* Implementation of hook_civicrm_install
*/
function booking_civicrm_install() {
require_once 'CRM/Utils/Migrate/Import.php';
$import = new CRM_Utils_Migrate_Import( );
$extRoot = dirname( __FILE__ ) . DIRECTORY_SEPARATOR;
$op = $extRoot . 'xml' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'OptionGroups.xml';
$import->run( $op );
return _booking_civix_civicrm_install();
}
/**
* Implementation of hook_civicrm_uninstall
*/
function booking_civicrm_uninstall() {
return _booking_civix_civicrm_uninstall();
}
/**
* Implementation of hook_civicrm_enable
*/
function booking_civicrm_enable() {
// rebuild the menu so our path is picked up
require_once 'CRM/Core/Invoke.php';
CRM_Core_Invoke::rebuildMenuAndCaches( );
return _booking_civix_civicrm_enable();
}
/**
* Implementation of hook_civicrm_disable
*/
function booking_civicrm_disable() {
return _booking_civix_civicrm_disable();
}
/**
* Implementation of hook_civicrm_upgrade
*
* @param $op string, the type of operation being performed; 'check' or 'enqueue'
* @param $queue CRM_Queue_Queue, (for 'enqueue') the modifiable list of pending up upgrade tasks
*
* @return mixed based on op. for 'check', returns array(boolean) (TRUE if upgrades are pending)
* for 'enqueue', returns void
*/
function booking_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
return _booking_civix_civicrm_upgrade($op, $queue);
}
/**
* Implementation of hook_civicrm_managed
*
* Generate a list of entities to create/deactivate/delete when this module
* is installed, disabled, uninstalled.
*/
function booking_civicrm_managed(&$entities) {
return _booking_civix_civicrm_managed($entities);
}
/**
* Implementation of hook_civicrm_queryObjects
*/
function booking_civicrm_queryObjects(&$queryObjects, $type) {
if ($type == 'Contact') {
$queryObjects[] = new CRM_Booking_BAO_Query();
}
elseif ($type == 'Report') {}
}
/**
* Implementation of hook_civicrm_postProcess
*/
function booking_civicrm_post( $op, $objectName, $objectId, &$objectRef ) {
if($objectName == 'Contribution'){
if($op == 'delete'){
CRM_Core_DAO::executeQuery("DELETE FROM civicrm_booking_payment WHERE contribution_id = $objectId");
}
}
}
/**
* Implementation of hook_civicrm_entityTypes
*/
function booking_civicrm_entityTypes(&$entityTypes) {
$entityTypes[] = array(
'name' => 'AdhocCharges',
'class' => 'CRM_Booking_DAO_AdhocCharges',
'table' => 'civicrm_booking_adhoc_charges',
);
$entityTypes[] = array(
'name' => 'AdhocChargesItem',
'class' => 'CRM_Booking_DAO_AdhocChargesItem',
'table' => 'civicrm_booking_adhoc_charges_item',
);
$entityTypes[] = array(
'name' => 'Booking',
'class' => 'CRM_Booking_DAO_Booking',
'table' => 'civicrm_booking',
);
$entityTypes[] = array(
'name' => 'BookingPayment',
'class' => 'CRM_Booking_DAO_Payment',
'table' => 'civicrm_booking_payment',
);
$entityTypes[] = array(
'name' => 'Resource',
'class' => 'CRM_Booking_DAO_Resource',
'table' => 'civicrm_booking_resource',
);
$entityTypes[] = array(
'name' => 'ResourceConfigOption',
'class' => 'CRM_Booking_DAO_ResourceConfigOption',
'table' => 'civicrm_booking_resource_config_option',
);
$entityTypes[] = array(
'name' => 'ResourceConfigSet',
'class' => 'CRM_Booking_DAO_ResourceConfigSet',
'table' => 'civicrm_booking_resource_config_set',
);
$entityTypes[] = array(
'name' => 'Slot',
'class' => 'CRM_Booking_DAO_Slot',
'table' => 'civicrm_booking_slot',
);
$entityTypes[] = array(
'name' => 'SubSlot',
'class' => 'CRM_Booking_DAO_SubSlot',
'table' => 'civicrm_booking_sub_slot',
);
$entityTypes[] = array(
'name' => 'Cancellation',
'class' => 'CRM_Booking_DAO_Cancellation',
'table' => 'civicrm_booking_cancellation'
);
}
/**
* Add navigation for booking under "Administer" menu
*
* @param $params associated array of navigation menus
*/
function booking_civicrm_navigationMenu( &$params ) {
$result = civicrm_api3('OptionGroup', 'getsingle', array('name' => CRM_Booking_Utils_Constants::OPTION_BOOKING_STATUS));
if($result['id']){
$bookingStatusGid = $result['id'];
}
$result = civicrm_api3('OptionGroup', 'getsingle', array('name' => CRM_Booking_Utils_Constants::OPTION_RESOURCE_TYPE));
if($result['id']){
$resourceTypeGid = $result['id'];
}
$result = civicrm_api3('OptionGroup', 'getsingle', array('name' => CRM_Booking_Utils_Constants::OPTION_RESOURCE_LOCATION));
if($result['id']){
$resourceLocationGId = $result['id'];
}
$result = civicrm_api3('OptionGroup', 'getsingle', array('name' => CRM_Booking_Utils_Constants::OPTION_RESOURCE_CRITERIA));
if($result['id']){
$resourceCriteriaGId = $result['id'];
}
$result = civicrm_api3('OptionGroup', 'getsingle', array('name' => CRM_Booking_Utils_Constants::OPTION_SIZE_UNIT));
if($result['id']){
$sizeUnitGid = $result['id'];
}
$result = civicrm_api3('OptionGroup', 'getsingle', array('name' => CRM_Booking_Utils_Constants::OPTION_CANCELLATION_CHARGES));
if($result['id']){
$cancellationChargesGid = $result['id'];
}
// get the id of Administer Menu
$administerMenuId = CRM_Core_DAO::getFieldValue('CRM_Core_BAO_Navigation', 'Administer', 'id', 'name');
// skip adding menu if there is no administer menu
if ($administerMenuId) {
// get the maximum key under administer menu
$maxAdminMenuKey = max( array_keys($params[$administerMenuId]['child']));
$nextAdminMenuKey = $maxAdminMenuKey+1;
$params[$administerMenuId]['child'][$nextAdminMenuKey] = array(
'attributes' => array(
'label' => ts('CiviBooking'),
'name' => 'admin_booking',
//'url' => '#',
'permission' => null,
'operator' => null,
'separator' => 1,
'parentID' => $administerMenuId,
'navID' => $nextAdminMenuKey,
'active' => 1
),
'child' => array(
1 => array(
'attributes' => array(
'label' => ts('Manage Resources'),
'name' => 'manage_resources',
'url' => 'civicrm/admin/resource&reset=1',
'permission' => null,
'operator' => null,
'separator' => 0,
'parentID' => $nextAdminMenuKey,
'navID' => 2,
'active' => 1
),
'child' => null
),
2 => array(
'attributes' => array(
'label' => ts('Resource Configuration Set'),
'name' => 'resource_config_set',
'url' => 'civicrm/admin/resource/config_set&reset=1',
'permission' => null,
'operator' => null,
'separator' => 0,
'parentID' => $nextAdminMenuKey,
'navID' => 2,
'active' => 1
),
'child' => null
),
3 => array(
'attributes' => array(
'label' => ts('Additional Charges Item'),
'name' => 'adhoc_charges_item',
'url' => 'civicrm/admin/adhoc_charges_item&reset=1',
'permission' => null,
'operator' => null,
'separator' => 0,
'parentID' => $nextAdminMenuKey,
'navID' => 2,
'active' => 1
),
'child' => null
),
4 => array(
'attributes' => array(
'label' => ts('Booking Status'),
'name' => 'booking_status',
'url' => 'civicrm/admin/optionValue?gid=' . $bookingStatusGid .'&reset=1',
'permission' => null,
'operator' => null,
'separator' => 0,
'parentID' => $nextAdminMenuKey,
'navID' => 3,
'active' => 1
),
'child' => null
),
5 => array(
'attributes' => array(
'label' => ts('Resource Type'),
'name' => 'resource_type',
'url' => 'civicrm/admin/optionValue?gid=' . $resourceTypeGid .'&reset=1',
'permission' => null,
'operator' => null,
'separator' => 0,
'parentID' => $nextAdminMenuKey,
'navID' => 4,
'active' => 1
),
'child' => null
),
6 => array(
'attributes' => array(
'label' => ts('Resource Criteria'),
'name' => 'resource_criteria',
'url' => 'civicrm/admin/optionValue?gid=' . $resourceCriteriaGId .'&reset=1',
'permission' => null,
'operator' => null,
'separator' => 0,
'parentID' => $nextAdminMenuKey,
'navID' => 5,
'active' => 1
),
'child' => null
),
7 => array(
'attributes' => array(
'label' => ts('Size Unit'),
'name' => 'size_unit',
'url' =>'civicrm/admin/optionValue?gid=' . $sizeUnitGid .'&reset=1',
'permission' => null,
'operator' => null,
'separator' => 0,
'parentID' => $nextAdminMenuKey,
'navID' => 6,
'active' => 1
),
'child' => null
),
8 => array(
'attributes' => array(
'label' => ts('Cancellation Charges'),
'name' => 'cancellation_charges',
'url' =>'civicrm/admin/optionValue?gid=' . $cancellationChargesGid .'&reset=1',
'permission' => null,
'operator' => null,
'separator' => 0,
'parentID' => $nextAdminMenuKey,
'navID' => 6,
'active' => 1
),
'child' => null
),
9 => array(
'attributes' => array(
'label' => ts('Booking Component Settings'),
'name' => 'booking_component_settings',
'url' =>'civicrm/admin/setting/preferences/booking?reset=1',
'permission' => null,
'operator' => null,
'separator' => 0,
'parentID' => $newbookingKey,
'navID' => 7,
'active' => 1
),
'child' => null
),
),
);
}
$findBooking = array(
'attributes' => array(
'label' => ts('Find Bookings'),
'name' => 'find_booking',
'url' => 'civicrm/booking/search&reset=1',
'permission' => null,
'operator' => null,
'separator' => 0,
'parentID' => null,
'navID' => 3,
'active' => 1
),
'child' => null
);
$bookingMenu = array(
'attributes' => array(
'label' => ts('Booking'),
'name' => 'booking',
'url' => null,
'permission' => null,
'operator' => null,
'separator' => null,
'parentID' => null,
'navID' => null,
'active' => 1
),
'child' => array(
1 => array(
'attributes' => array(
'label' => ts('New Booking'),
'name' => 'new_booking',
'url' => 'civicrm/booking/add&reset=1',
'permission' => null,
'operator' => null,
'separator' => 0,
'parentID' => null,
'navID' => 2 ,
'active' => 1
),
'child' => null
),
2 => $findBooking,
3 => array(
'attributes' => array(
'label' => ts('Day View'),
'name' => 'day_view',
'url' => 'civicrm/booking/day-view&reset=1',
'permission' => null,
'operator' => null,
'separator' => 0,
'parentID' => null,
'navID' => 2 ,
'active' => 1
)
),
)
);
array_unshift($params, $bookingMenu);
/*
$searchMenuId = CRM_Core_DAO::getFieldValue('CRM_Core_BAO_Navigation', 'Search...', 'id', 'name');
if ($searchMenuId) {
$maxSearchMenuKey = max( array_keys($params[$searchMenuId]['child']));
$nextSearchMenuKey = $maxSearchMenuKey + 1;
$beforeMaxSearchMenuKey = $maxSearchMenuKey - 1;
//remove lasted seperator for lasted Find
$params[$searchMenuId]['child'][$beforeMaxSearchMenuKey]['attributes']['separator'] = 0;
$lastSearchMenu = $params[$searchMenuId]['child'][$maxSearchMenuKey];
unset($params[$searchMenuId]['child'][$maxSearchMenuKey]);
$findBooking['attributes']['separator'] = 1;
$params[$searchMenuId]['child'][$maxSearchMenuKey] = $findBooking;
$params[$searchMenuId]['child'][$nextSearchMenuKey] = $lastSearchMenu;
//move search menu to be at the first of the array
$searchMenuTemp = $params[$searchMenuId];
unset($params[$searchMenuId]);
array_unshift($params, $searchMenuTemp);
}
*/
}