-
Notifications
You must be signed in to change notification settings - Fork 0
/
submitteddonotionreport.php
303 lines (280 loc) · 10.2 KB
/
submitteddonotionreport.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
<?php
require_once 'submitteddonotionreport.civix.php';
use CRM_Submitteddonotionreport_ExtensionUtil as E;
/**
* Implements hook_civicrm_config().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_config
*/
function submitteddonotionreport_civicrm_config(&$config) {
_submitteddonotionreport_civix_civicrm_config($config);
}
/**
* Implements hook_civicrm_xmlMenu().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_xmlMenu
*/
function submitteddonotionreport_civicrm_xmlMenu(&$files) {
_submitteddonotionreport_civix_civicrm_xmlMenu($files);
}
/**
* Implements hook_civicrm_install().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_install
*/
function submitteddonotionreport_civicrm_install() {
_submitteddonotionreport_civix_civicrm_install();
}
/**
* Implements hook_civicrm_postInstall().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_postInstall
*/
function submitteddonotionreport_civicrm_postInstall() {
_submitteddonotionreport_civix_civicrm_postInstall();
}
/**
* Implements hook_civicrm_uninstall().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_uninstall
*/
function submitteddonotionreport_civicrm_uninstall() {
_submitteddonotionreport_civix_civicrm_uninstall();
}
/**
* Implements hook_civicrm_enable().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_enable
*/
function submitteddonotionreport_civicrm_enable() {
_submitteddonotionreport_civix_civicrm_enable();
}
/**
* Implements hook_civicrm_disable().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_disable
*/
function submitteddonotionreport_civicrm_disable() {
_submitteddonotionreport_civix_civicrm_disable();
}
/**
* Implements hook_civicrm_upgrade().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_upgrade
*/
function submitteddonotionreport_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
return _submitteddonotionreport_civix_civicrm_upgrade($op, $queue);
}
/**
* Implements hook_civicrm_managed().
*
* Generate a list of entities to create/deactivate/delete when this module
* is installed, disabled, uninstalled.
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_managed
*/
function submitteddonotionreport_civicrm_managed(&$entities) {
_submitteddonotionreport_civix_civicrm_managed($entities);
}
/**
* Implements hook_civicrm_caseTypes().
*
* Generate a list of case-types.
*
* Note: This hook only runs in CiviCRM 4.4+.
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_caseTypes
*/
function submitteddonotionreport_civicrm_caseTypes(&$caseTypes) {
_submitteddonotionreport_civix_civicrm_caseTypes($caseTypes);
}
/**
* Implements hook_civicrm_angularModules().
*
* Generate a list of Angular modules.
*
* Note: This hook only runs in CiviCRM 4.5+. It may
* use features only available in v4.6+.
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_angularModules
*/
function submitteddonotionreport_civicrm_angularModules(&$angularModules) {
_submitteddonotionreport_civix_civicrm_angularModules($angularModules);
}
/**
* Implements hook_civicrm_alterSettingsFolders().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_alterSettingsFolders
*/
function submitteddonotionreport_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) {
_submitteddonotionreport_civix_civicrm_alterSettingsFolders($metaDataFolders);
}
/**
* Implements hook_civicrm_entityTypes().
*
* Declare entity types provided by this module.
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_entityTypes
*/
function submitteddonotionreport_civicrm_entityTypes(&$entityTypes) {
_submitteddonotionreport_civix_civicrm_entityTypes($entityTypes);
}
/**
* Implements hook_civicrm_alterReportVar().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_alterReportVar
*/
function submitteddonotionreport_civicrm_alterReportVar(
$varType,
&$var,
&$object
) {
if ('CRM_Report_Form_Contribute_Detail' != get_class($object)) {
return;
}
if ($varType == 'columns') {
$var['civicrm_contribution']['fields']['source_contact_name'] = [
'title' => ts('Source Name'),
'dbAlias' => "source_contact_table.sort_name",
];
$var['civicrm_contribution']['fields']['contribution_created_date'] = [
'title' => ts('Contribution Created Date'),
'dbAlias' => "source_activity_table.created_date",
];
$var['civicrm_contribution']['fields']['source_contact_id'] = [
'title' => ts('Source Contact Id'),
'no_display' => TRUE,
'required' => TRUE,
'dbAlias' => "source_contact_table.id",
];
$var['civicrm_contribution']['filters']['contribution_created_date'] = [
'title' => ts('Contribution Created Date'),
'dbAlias' => "source_activity_table.created_date",
'type' => CRM_Utils_Type::T_DATE,
];
$var['civicrm_contribution']['filters']['source_contact_name'] = [
'title' => ts('Source Name'),
'dbAlias' => "source_contact_table.sort_name",
'type' => CRM_Utils_Type::T_STRING,
];
$var['civicrm_contribution']['filters']['source_contact_group'] = [
'title' => ts('Source Contact Group'),
'type' => CRM_Utils_Type::T_INT,
'operatorType' => CRM_Report_Form::OP_MULTISELECT,
'dbAlias' => "source_contact_group.group_id",
'options' => CRM_Core_PseudoConstant::nestedGroup(),
];
}
elseif ($varType == 'sql') {
$object->_originVar = NULL;
$params = $object->getVar('_params');
$aliases = $object->getVar('_aliases');
if (empty($params['source_contact_group_value'])
&& empty($params['source_contact_name_value'])
&& empty($params['fields']['source_contact_name'])
&& empty($params['contribution_created_date_value'])
&& empty($params['fields']['contribution_created_date'])
) {
$fromClause = "
INNER JOIN civicrm_contribution source_contact_table
ON {$aliases['civicrm_contribution']}.id = source_contact_table.id
";
}
else {
$results = civicrm_api3('OptionValue', 'get', [
'return' => ["value", 'name'],
'option_group_id' => "activity_type",
'name' => ['IN' => [
"Contribution",
"Event Registration",
"Membership Signup",
"Membership Renewal"
]
],
])['values'];
foreach ($results as $result) {
$activityTypeIds[$result['name']] = $result['value'];
}
$recordTypeId = civicrm_api3('OptionValue', 'getvalue', [
'return' => "value",
'option_group_id' => "activity_contacts",
'name' => "Activity Source",
]);
$fromClause = "
LEFT JOIN (
SELECT ca.source_record_id, cac.contact_id, ca.id activity_id
FROM civicrm_activity ca
INNER JOIN civicrm_activity_contact cac ON ca.id = cac.activity_id
AND ca.activity_type_id = {$activityTypeIds['Contribution']}
AND cac.record_type_id = {$recordTypeId}
UNION
SELECT cpp.contribution_id, cac.contact_id, ca.id
FROM civicrm_activity ca
INNER JOIN civicrm_activity_contact cac ON ca.id = cac.activity_id
AND ca.activity_type_id = {$activityTypeIds['Event Registration']}
AND cac.record_type_id = {$recordTypeId}
INNER JOIN civicrm_participant_payment cpp
ON cpp.participant_id = ca.source_record_id
UNION
SELECT cmp.contribution_id, cac.contact_id, ca.id
FROM civicrm_activity ca
INNER JOIN civicrm_activity_contact cac ON ca.id = cac.activity_id
AND ca.activity_type_id IN ({$activityTypeIds['Membership Signup']}, {$activityTypeIds['Membership Renewal']})
AND cac.record_type_id = {$recordTypeId}
INNER JOIN civicrm_membership_payment cmp
ON cmp.membership_id = ca.source_record_id
) AS contribution_activity_table
ON {$aliases['civicrm_contribution']}.id = contribution_activity_table.source_record_id
LEFT JOIN civicrm_contact source_contact_table
ON source_contact_table.id = contribution_activity_table.contact_id
LEFT JOIN civicrm_activity source_activity_table
ON source_activity_table.id = contribution_activity_table.activity_id
";
if (!empty($params['source_contact_group_value'])) {
$filteredGroups = $params['source_contact_group_value'];
$fromClause .= " LEFT JOIN (
SELECT DISTINCT contact_id, group_id
FROM civicrm_group_contact
WHERE group_id IN (" . implode(', ', $filteredGroups) . ")
AND status = 'Added'
UNION DISTINCT
SELECT contact_id, group_id
FROM civicrm_group_contact_cache
WHERE group_id IN (" . implode(', ', $filteredGroups) . ")
) AS source_contact_group
ON source_contact_group.contact_id = source_contact_table.id
";
}
}
$from = $object->getVar('_from') . $fromClause;
$object->_originVar = $from;
$object->setVar('_from', $from);
}
elseif ($varType == 'rows') {
if (!empty($object->_originVar)) {
$object->setVar('_from', $object->_originVar);
}
$entryFound = 0;
foreach ($var as $id => $row) {
if (array_key_exists('civicrm_contribution_source_contact_name', $row) &&
!empty($var[$id]['civicrm_contribution_source_contact_name']) &&
array_key_exists('civicrm_contribution_source_contact_id', $row)
) {
$url = CRM_Utils_System::url("civicrm/contact/view",
'reset=1&cid=' . $row['civicrm_contribution_source_contact_id'],
TRUE,
NULL,
FALSE
);
$var[$id]['civicrm_contribution_source_contact_name_link'] = $url;
$var[$id]['civicrm_contribution_source_contact_name_hover'] = ts("View Contact Summary for this Contact.");
$entryFound = TRUE;
}
// skip looking further in rows, if first row itself doesn't
// have the column we need
if (!$entryFound) {
break;
}
}
}
}