generated from compucorp/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcertificate.php
178 lines (154 loc) · 5.34 KB
/
certificate.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
<?php
require_once 'certificate.civix.php';
use CRM_Certificate_ExtensionUtil as E;
/**
* Implements hook_civicrm_config().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_config/
*/
function certificate_civicrm_config(&$config) {
_certificate_civix_civicrm_config($config);
_compucertificate_add_token_subscribers();
}
/**
* Implements hook_civicrm_install().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_install
*/
function certificate_civicrm_install() {
_certificate_civix_civicrm_install();
}
/**
* Implements hook_civicrm_enable().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_enable
*/
function certificate_civicrm_enable() {
_certificate_civix_civicrm_enable();
}
/**
* Implements hook_civicrm_navigationMenu().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_navigationMenu
*/
function certificate_civicrm_navigationMenu(&$menu) {
_certificate_civix_insert_navigation_menu($menu, 'Administer', array(
'label' => E::ts('Certificates'),
'name' => 'compu-configure-certificate',
'url' => 'civicrm/admin/certificates',
'permission' => 'configure certificates',
));
_certificate_civix_insert_navigation_menu($menu, 'Administer/Communications', array(
'label' => E::ts('Image Formats (Certificates)'),
'name' => 'compucertificate-configure-imageformats',
'url' => 'civicrm/admin/certificates/imageFormats?reset=1',
'permission' => 'configure certificates',
));
}
/**
* Implements hook_civicrm_permission().
*
* Declare permissions used by the extension
*/
function certificate_civicrm_permission(&$permissions) {
$permissions['configure certificates'] = [
ts('CompuCertificate: configure certificates'),
ts('User can configure which message templates can be downloaded as certificates.'),
];
}
/**
* Subscribes to token evaluate events, this enables
* each entity to resolve tokens with the appropraite value
*
*/
function _compucertificate_add_token_subscribers() {
Civi::dispatcher()->addSubscriber(new CRM_Certificate_Token_Case());
Civi::dispatcher()->addSubscriber(new CRM_Certificate_Token_Event());
Civi::dispatcher()->addSubscriber(new CRM_Certificate_Token_Contact());
Civi::dispatcher()->addSubscriber(new CRM_Certificate_Token_Participant());
Civi::dispatcher()->addSubscriber(new CRM_Certificate_Token_Membership());
Civi::dispatcher()->addSubscriber(new CRM_Certificate_Token_Certificate());
}
function _compucertificate_getCaseIdFromUrlIfExist() {
$caseId = NULL;
if (!empty($_GET['caseid'])) {
$caseId = (int) $_GET['caseid'];
}
return $caseId;
}
/**
* Implements hook_civicrm_tokens().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_tokens
*/
function certificate_civicrm_tokens(&$tokens) {
$tokens[CRM_Certificate_Token_Case::TOKEN] = CRM_Certificate_Token_Case::prefixedEntityTokens();
$tokens[CRM_Certificate_Token_Event::TOKEN] = CRM_Certificate_Token_Event::prefixedEntityTokens();
$tokens[CRM_Certificate_Token_Contact::TOKEN] = CRM_Certificate_Token_Contact::prefixedEntityTokens();
$tokens[CRM_Certificate_Token_Participant::TOKEN] = CRM_Certificate_Token_Participant::prefixedEntityTokens();
$tokens[CRM_Certificate_Token_Membership::TOKEN] = CRM_Certificate_Token_Membership::prefixedEntityTokens();
$tokens[CRM_Certificate_Token_Certificate::TOKEN] = CRM_Certificate_Token_Certificate::prefixedEntityTokens();
if (_compucertificate_getCaseIdFromUrlIfExist()) {
$tokens['certificate_url']['certificate_url.case'] = 'Case Certificate URL';
}
}
/**
* Implements hook_civicrm_tokenvalues().
*/
function certificate_civicrm_tokenValues(&$values, $cids, $job = NULL, $tokens = [], $context = NULL) {
$caseId = _compucertificate_getCaseIdFromUrlIfExist();
$hooks = [new CRM_Certificate_Hook_Token_CaseCertificateUrlTokensValues($caseId)];
foreach ($hooks as &$hook) {
$hook->run($values, $cids, $job, $tokens, $context);
}
}
/**
* Implements addCiviCaseDependentAngularModules().
*/
function certificate_addCiviCaseDependentAngularModules(&$dependentModules) {
$dependentModules[] = "certificate";
}
/**
* Implements hook_civicrm_apiWrappers().
*/
function certificate_civicrm_apiWrappers(&$wrappers, $apiRequest) {
if ($apiRequest['entity'] == 'Case' & $apiRequest['action'] === 'getdetails') {
$wrappers[] = new CRM_Certificate_Api_Wrapper_Case();
}
}
/**
* Implements hook_civicrm_pageRun().
*/
function certificate_civicrm_pageRun(&$page) {
$hooks = [
new CRM_Certificate_Hook_PageRun_EventPageTab($page),
new CRM_Certificate_Hook_PageRun_MemberPageTab($page),
];
array_walk($hooks, function ($hook) {
$hook->run();
});
}
/**
* Implements hook_civicrm_buildForm().
*/
function certificate_civicrm_buildForm($formName, &$form) {
$hooks = [];
if (CRM_Certificate_Hook_BuildForm_MessageTemplates::shouldRun($form)) {
$hooks[] = new CRM_Certificate_Hook_BuildForm_MessageTemplates($form);
}
array_walk($hooks, function ($hook) {
$hook->run();
});
}
/**
* Implements hook_civicrm_postProcess().
*/
function certificate_civicrm_postProcess($formName, &$form) {
$hooks = [];
if (CRM_Certificate_Hook_PostProcess_MessageTemplates::shouldRun($form)) {
$hooks[] = new CRM_Certificate_Hook_PostProcess_MessageTemplates($formName, $form);
}
array_walk($hooks, function ($hook) {
$hook->run();
});
}