This repository has been archived by the owner on Sep 26, 2023. It is now read-only.
forked from compucorp/civibooking
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbooking.php
executable file
·234 lines (214 loc) · 6.38 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
<?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') {
$cid = $context['contact_id'];
$tabs[] = [
'id' => 'booking',
'count' => $cid ? CRM_Booking_BAO_Booking::getBookingContactCount($cid) : 0,
'title' => E::ts('Bookings'),
'icon' => 'crm-i fa-book',
// Show towards the end
'weight' => 99,
'url' => CRM_Utils_System::url('civicrm/contact/view/booking', "reset=1&cid={$cid}&snippet=1&force=1", FALSE, NULL, FALSE),
];
}
}
/**
* 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_install
*/
function booking_civicrm_install() {
_booking_civix_civicrm_install();
}
/**
* Implementation of hook_civicrm_enable
*/
function booking_civicrm_enable() {
_booking_civix_civicrm_enable();
}
/**
* Implementation of hook_civicrm_queryObjects
*/
function booking_civicrm_queryObjects(&$queryObjects, $type) {
if ($type == 'Contact') {
$queryObjects[] = new CRM_Booking_BAO_Query();
}
}
/**
* 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[] = [
'name' => 'AdhocCharges',
'class' => 'CRM_Booking_DAO_AdhocCharges',
'table' => 'civicrm_booking_adhoc_charges',
];
$entityTypes[] = [
'name' => 'AdhocChargesItem',
'class' => 'CRM_Booking_DAO_AdhocChargesItem',
'table' => 'civicrm_booking_adhoc_charges_item',
];
$entityTypes[] = [
'name' => 'Booking',
'class' => 'CRM_Booking_DAO_Booking',
'table' => 'civicrm_booking',
];
$entityTypes[] = [
'name' => 'BookingPayment',
'class' => 'CRM_Booking_DAO_Payment',
'table' => 'civicrm_booking_payment',
];
$entityTypes[] = [
'name' => 'Resource',
'class' => 'CRM_Booking_DAO_Resource',
'table' => 'civicrm_booking_resource',
];
$entityTypes[] = [
'name' => 'ResourceConfigOption',
'class' => 'CRM_Booking_DAO_ResourceConfigOption',
'table' => 'civicrm_booking_resource_config_option',
];
$entityTypes[] = [
'name' => 'ResourceConfigSet',
'class' => 'CRM_Booking_DAO_ResourceConfigSet',
'table' => 'civicrm_booking_resource_config_set',
];
$entityTypes[] = [
'name' => 'Slot',
'class' => 'CRM_Booking_DAO_Slot',
'table' => 'civicrm_booking_slot',
];
$entityTypes[] = [
'name' => 'SubSlot',
'class' => 'CRM_Booking_DAO_SubSlot',
'table' => 'civicrm_booking_sub_slot',
];
$entityTypes[] = [
'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;
";
$dao = CRM_Core_DAO::executeQuery($query1);
$dao = CRM_Core_DAO::executeQuery($query2);
}
}
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 = [
'create' => [
'administer CiviBooking',
],
'delete' => [
'administer CiviBooking',
],
'get' => [
[
'administer CiviBooking',
'create and update bookings',
'view all bookings',
]
],
'update' => [
'administer CiviBooking',
],
];
$bookingEntities = [
'BookingPayment',
'Booking',
'Cancellation',
'Slot',
'SubSlot'
];
$configEntities = [
'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 = [['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();
}
}
/**
* Implements hook_civicrm_navigationMenu().
*/
function booking_civicrm_navigationMenu(&$menu) {
$menuItems = CRM_Booking_Upgrader::getMenuItems();
foreach ($menuItems as $item) {
_booking_civix_insert_navigation_menu($menu, $item['parent_name'], $item);
}
_booking_civix_navigationMenu($menu);
}