This repository has been archived by the owner on Oct 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
/
booking.php
executable file
·299 lines (265 loc) · 8.18 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
<?php
use CRM_Booking_ExtensionUtil as E;
require_once 'booking.civix.php';
/**
* Implements hook_civicrm_tabset().
*
* Display a booking tab listing booking belong to that contact.
*/
function booking_civicrm_tabset($tabsetName, &$tabs, $context) {
if ($tabsetName === 'civicrm/contact/view' && !empty($context['contact_id'])) {
$cid = $context['contact_id'];
$count = CRM_Booking_BAO_Booking::getBookingContactCount($cid); //TODO Count number of booking and show on the tab
$tab = [
'id' => 'booking',
'count' => $count,
'title' => 'Bookings',
'icon' => 'crm-i fa-book',
'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) {
// enable use of number_format php function in smarty templates when
// security on(on by default for emails)
$smarty = CRM_Core_Smarty::singleton();
$smarty->security_settings['MODIFIER_FUNCS'][] = "number_format";
_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'
);
}
/**
* Implementation of hook_civicrm_merge
*/
function booking_civicrm_merge ( $type, &$data, $mainId = NULL, $otherId = NULL, $tables = NULL ){
if (!empty($mainId) && !empty($otherId) && $type == 'sqls'){
$query1 = "
UPDATE civicrm_booking
SET primary_contact_id=$mainId
WHERE primary_contact_id=$otherId;
";
$query2 = "
UPDATE civicrm_booking
SET secondary_contact_id=$mainId
WHERE secondary_contact_id=$otherId;
";
require_once('CRM/Core/DAO.php');
$dao = CRM_Core_DAO::executeQuery( $query1 );
$dao = CRM_Core_DAO::executeQuery( $query2 );
}
}
function civibooking_getMenuKeyMax($menuArray) {
$max = array(max(array_keys($menuArray)));
foreach($menuArray as $v) {
if (!empty($v['child'])) {
$max[] = civibooking_getMenuKeyMax($v['child']);
}
}
return max($max);
}
function booking_civicrm_permission(&$permissions){
$prefix = E::ts('CiviBooking') . ': ';
$permissions['administer CiviBooking'] = $prefix . E::ts('administer CiviBooking');
$permissions['create and update bookings'] = $prefix . E::ts('create and update bookings');
$permissions['view all bookings'] = $prefix . E::ts('view all bookings');
}
/*
* Implements hook_civicrm_alterAPIPermissions
* @see function _civicrm_api3_permissions for mentioned uppercase issue
*/
function booking_civicrm_alterAPIPermissions($entity, $action, &$params, &$permissions) {
$commonBookingAPIPermissions = array(
'create' => array(
'administer CiviBooking',
),
'delete' => array(
'administer CiviBooking',
),
'get' => array(
array(
'administer CiviBooking',
'create and update bookings',
'view all bookings',
)
),
'update' => array(
'administer CiviBooking',
),
);
$bookingEntities = array(
'BookingPayment',
'Booking',
'Cancellation',
'Slot',
'SubSlot'
);
$configEntities = array(
'AdhocChargesItem',
'AdhocCharges',
'ResourceConfigOption',
'ResourceConfigSet',
'Resource',
);
// set common permissions
foreach (array_merge($bookingEntities, $configEntities) as $entityName) {
// permissions implementation needs lowercase entities
$permissions[_civicrm_api_get_entity_name_from_camel($entityName)] = $commonBookingAPIPermissions;
}
//add custom permissions for create/update role
foreach ($bookingEntities as $entityName) {
$permissionArray = array(array('administer CiviBooking', 'create and update bookings'));
// permissions implementation needs lowercase entities
$entityName = _civicrm_api_get_entity_name_from_camel($entityName);
$permissions[$entityName]['create'] = $permissionArray;
$permissions[$entityName]['update'] = $permissionArray;
}
}
/**
* Implements hook_civicrm_apiWrappers()
*
* @param array $wrappers
* @param array $apiRequest
*/
function booking_civicrm_apiWrappers(&$wrappers, $apiRequest) {
if ($apiRequest['entity'] == 'Resource' && $apiRequest['action'] == 'get') {
$wrappers[] = new CRM_Booking_APIWrapper();
}
}