-
Notifications
You must be signed in to change notification settings - Fork 0
/
events.php
148 lines (130 loc) · 4.68 KB
/
events.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
<?php
/*-------------------------------------------------------+
| BUND Event Customisations |
| Copyright (C) 2020 SYSTOPIA |
| Author: B. Endres ([email protected]) |
| http://www.systopia.de/ |
+--------------------------------------------------------+
| This program is released as free software under the |
| Affero GPL license. You can redistribute it and/or |
| modify it under the terms of this license which you |
| can read by viewing the included agpl.txt or online |
| at www.gnu.org/licenses/agpl.html. Removal of this |
| copyright header is strictly prohibited without |
| written permission from the original author(s). |
+--------------------------------------------------------*/
require_once 'events.civix.php';
use CRM_Events_ExtensionUtil as E;
/**
* Implements hook_civicrm_config().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_config/
*/
function events_civicrm_config(&$config)
{
_events_civix_civicrm_config($config);
$dispatcher = new \Civi\RemoteDispatcher();
// ADD REMOTE EVENT PROFILE
$dispatcher->addUniqueListener(
'civi.remoteevent.get.result',
['CRM_Events_RemoteEventModifications', 'overrideRegistrationRestrictions']
);
$dispatcher->addUniqueListener(
'civi.remoteevent.registration.validate',
['CRM_Events_RemoteEventModifications', 'validateRegistrationRestrictions'],
-500 // run late
);
$dispatcher->addUniqueListener(
'civi.remoteevent.registration.submit',
['CRM_Events_Logic', 'triggerUpdateContactEventStats'], CRM_Remoteevent_Registration::AFTER_PARTICIPANT_CREATION);
// ADD REMOTE CONTACT PROFILE
$dispatcher->addUniqueListener(
'civi.remotecontact.getprofiles',
['CRM_Events_Profile_EventDaysProfile', 'registerProfiles']);
}
/**
* POST hook
* @see https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_post/
*/
function events_civicrm_post($op, $objectName, $objectId, &$objectRef) {
if ($objectName == 'Participant' && $objectId) {
if ($op == 'create' || $op == 'edit' || $op == 'delete') {
// the participant object was manipulated -> update event data via callback (after this transaction)
if (CRM_Core_Transaction::isActive()) {
CRM_Core_Transaction::addCallback(
CRM_Core_Transaction::PHASE_POST_COMMIT,
'events_civicrm_post_participant_update',
[$objectId, $objectRef]);
} else {
events_civicrm_post_participant_update($objectId, $objectRef);
}
}
}
}
/**
* Participant update callback: trigger contact updates
*/
function events_civicrm_post_participant_update($participant_id, $participantBAO) {
try {
// find the contact_id
if (isset($participantBAO->contact_id)) {
$contact_id = (int) $participantBAO->contact_id;
} else {
$contact_id = (int) civicrm_api3('Participant', 'getvalue', [
'id' => $participant_id,
'return' => 'contact_id']);
}
// finally call the update
CRM_Events_Logic::updateContactEventStats($contact_id);
} catch (Exception $ex) {
Civi::log()->debug(E::LONG_NAME . ': exception prevented contact update: ' . $ex->getMessage());
}
}
/**
* Implements hook_civicrm_install().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_install
*/
function events_civicrm_install()
{
_events_civix_civicrm_install();
}
/**
* Implements hook_civicrm_enable().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_enable
*/
function events_civicrm_enable()
{
_events_civix_civicrm_enable();
}
/**
* Implements hook_civicrm_navigationMenu().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_navigationMenu
*/
function events_civicrm_navigationMenu(&$menu)
{
_events_civix_insert_navigation_menu(
$menu,
'Administer/CiviEvent',
[
'label' => E::ts('BUND Event Configuration'),
'name' => 'bund_event_configuration',
'url' => 'civicrm/event/bund/settings',
'permission' => 'administer CiviCRM',
'operator' => 'OR',
'separator' => 0,
]
);
_events_civix_navigationMenu($menu);
}
// --- Functions below this ship commented out. Uncomment as required. ---
/**
* Implements hook_civicrm_preProcess().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_preProcess
*
* function events_civicrm_preProcess($formName, &$form) {
*
* } // */