Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
6b83d5bd | 31 | * @copyright CiviCRM LLC (c) 2004-2019 |
6a488035 TO |
32 | */ |
33 | ||
34 | /** | |
35 | * This class contains Contribution Page related functions. | |
36 | */ | |
37 | class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_ContributionPage { | |
38 | ||
39 | /** | |
7bc789a5 | 40 | * Creates a contribution page. |
6a488035 | 41 | * |
014c4014 | 42 | * @param array $params |
6a488035 | 43 | * |
16b10e64 | 44 | * @return CRM_Contribute_DAO_ContributionPage |
6a488035 | 45 | */ |
7bc789a5 | 46 | public static function create($params) { |
157b21d8 | 47 | $financialTypeId = NULL; |
a7488080 | 48 | if (!empty($params['id']) && !CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $params['id'], NULL, 1)) { |
157b21d8 PN |
49 | $financialTypeId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $params['id'], 'financial_type_id'); |
50 | } | |
7bc789a5 | 51 | |
52 | if (isset($params['payment_processor']) && is_array($params['payment_processor'])) { | |
53 | $params['payment_processor'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $params['payment_processor']); | |
54 | } | |
d0a0de8d EM |
55 | $hook = empty($params['id']) ? 'create' : 'edit'; |
56 | CRM_Utils_Hook::pre($hook, 'ContributionPage', CRM_Utils_Array::value('id', $params), $params); | |
6a488035 TO |
57 | $dao = new CRM_Contribute_DAO_ContributionPage(); |
58 | $dao->copyValues($params); | |
59 | $dao->save(); | |
8cc574cf | 60 | if ($financialTypeId && !empty($params['financial_type_id']) && $financialTypeId != $params['financial_type_id']) { |
e1c77163 | 61 | CRM_Price_BAO_PriceFieldValue::updateFinancialType($params['id'], 'civicrm_contribution_page', $params['financial_type_id']); |
157b21d8 | 62 | } |
d0a0de8d | 63 | CRM_Utils_Hook::post($hook, 'ContributionPage', $dao->id, $dao); |
6a488035 TO |
64 | return $dao; |
65 | } | |
66 | ||
67 | /** | |
fe482240 | 68 | * Update the is_active flag in the db. |
6a488035 | 69 | * |
2c4442ca | 70 | * @deprecated - this bypasses hooks. |
71 | * | |
014c4014 TO |
72 | * @param int $id |
73 | * Id of the database record. | |
74 | * @param bool $is_active | |
75 | * Value we want to set the is_active field. | |
6a488035 | 76 | * |
8a4fede3 | 77 | * @return bool |
78 | * true if we found and updated the object, else false | |
6a488035 | 79 | */ |
00be9182 | 80 | public static function setIsActive($id, $is_active) { |
6a488035 TO |
81 | return CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_ContributionPage', $id, 'is_active', $is_active); |
82 | } | |
83 | ||
186c9c17 | 84 | /** |
2c4442ca | 85 | * Load values for a contribution page. |
86 | * | |
100fef9d | 87 | * @param int $id |
2c4442ca | 88 | * @param array $values |
186c9c17 | 89 | */ |
00be9182 | 90 | public static function setValues($id, &$values) { |
be2fb01f | 91 | $modules = ['CiviContribute', 'soft_credit', 'on_behalf']; |
4779abb3 | 92 | $values['custom_pre_id'] = $values['custom_post_id'] = NULL; |
6a488035 | 93 | |
be2fb01f | 94 | $params = ['id' => $id]; |
6a488035 | 95 | CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_ContributionPage', $params, $values); |
8ef12e64 | 96 | |
6a488035 | 97 | // get the profile ids |
be2fb01f | 98 | $ufJoinParams = [ |
6a488035 TO |
99 | 'entity_table' => 'civicrm_contribution_page', |
100 | 'entity_id' => $id, | |
be2fb01f | 101 | ]; |
6a488035 | 102 | |
4779abb3 | 103 | // retrieve profile id as also unserialize module_data corresponding to each $module |
104 | foreach ($modules as $module) { | |
105 | $ufJoinParams['module'] = $module; | |
106 | $ufJoin = new CRM_Core_DAO_UFJoin(); | |
107 | $ufJoin->copyValues($ufJoinParams); | |
108 | if ($module == 'CiviContribute') { | |
109 | $ufJoin->orderBy('weight asc'); | |
110 | $ufJoin->find(); | |
111 | while ($ufJoin->fetch()) { | |
112 | if ($ufJoin->weight == 1) { | |
113 | $values['custom_pre_id'] = $ufJoin->uf_group_id; | |
114 | } | |
115 | else { | |
116 | $values['custom_post_id'] = $ufJoin->uf_group_id; | |
117 | } | |
118 | } | |
119 | } | |
120 | else { | |
121 | $ufJoin->find(TRUE); | |
122 | if (!$ufJoin->is_active) { | |
123 | continue; | |
124 | } | |
125 | $params = CRM_Contribute_BAO_ContributionPage::formatModuleData($ufJoin->module_data, TRUE, $module); | |
126 | $values = array_merge($params, $values); | |
127 | if ($module == 'soft_credit') { | |
128 | $values['honoree_profile_id'] = $ufJoin->uf_group_id; | |
129 | $values['honor_block_is_active'] = $ufJoin->is_active; | |
130 | } | |
131 | else { | |
132 | $values['onbehalf_profile_id'] = $ufJoin->uf_group_id; | |
133 | } | |
134 | } | |
6a488035 | 135 | } |
874c9be7 | 136 | } |
6a488035 TO |
137 | |
138 | /** | |
fe482240 | 139 | * Send the emails. |
6a488035 | 140 | * |
014c4014 TO |
141 | * @param int $contactID |
142 | * Contact id. | |
143 | * @param array $values | |
144 | * Associated array of fields. | |
145 | * @param bool $isTest | |
146 | * If in test mode. | |
147 | * @param bool $returnMessageText | |
148 | * Return the message text instead of sending the mail. | |
6a488035 | 149 | * |
2c4442ca | 150 | * @param array $fieldTypes |
6a488035 | 151 | */ |
00be9182 | 152 | public static function sendMail($contactID, $values, $isTest = FALSE, $returnMessageText = FALSE, $fieldTypes = NULL) { |
be2fb01f CW |
153 | $gIds = []; |
154 | $params = ['custom_pre_id' => [], 'custom_post_id' => []]; | |
6a488035 | 155 | $email = NULL; |
6e10d414 | 156 | |
157 | // We are trying to fight the good fight against leaky variables (CRM-17519) so let's get really explicit | |
158 | // about ensuring the variables we want for the template are defined. | |
159 | // @todo add to this until all tpl params are explicit in this function and not waltzing around the codebase. | |
858f7096 | 160 | // Next stage is to remove this & ensure there are no e-notices - ie. all are set before they hit this fn. |
be2fb01f | 161 | $valuesRequiredForTemplate = [ |
858f7096 | 162 | 'customPre', |
163 | 'customPost', | |
164 | 'customPre_grouptitle', | |
165 | 'customPost_grouptitle', | |
166 | 'useForMember', | |
167 | 'membership_assign', | |
168 | 'amount', | |
d9924163 | 169 | 'receipt_date', |
c2358f41 | 170 | 'is_pay_later', |
be2fb01f | 171 | ]; |
858f7096 | 172 | |
6e10d414 | 173 | foreach ($valuesRequiredForTemplate as $valueRequiredForTemplate) { |
174 | if (!isset($values[$valueRequiredForTemplate])) { | |
175 | $values[$valueRequiredForTemplate] = NULL; | |
176 | } | |
177 | } | |
178 | ||
6a488035 TO |
179 | if (isset($values['custom_pre_id'])) { |
180 | $preProfileType = CRM_Core_BAO_UFField::getProfileType($values['custom_pre_id']); | |
8cc574cf | 181 | if ($preProfileType == 'Membership' && !empty($values['membership_id'])) { |
be2fb01f CW |
182 | $params['custom_pre_id'] = [ |
183 | [ | |
6a488035 TO |
184 | 'member_id', |
185 | '=', | |
186 | $values['membership_id'], | |
187 | 0, | |
188 | 0, | |
be2fb01f CW |
189 | ], |
190 | ]; | |
6a488035 | 191 | } |
8cc574cf | 192 | elseif ($preProfileType == 'Contribution' && !empty($values['contribution_id'])) { |
be2fb01f CW |
193 | $params['custom_pre_id'] = [ |
194 | [ | |
6a488035 TO |
195 | 'contribution_id', |
196 | '=', | |
197 | $values['contribution_id'], | |
198 | 0, | |
199 | 0, | |
be2fb01f CW |
200 | ], |
201 | ]; | |
6a488035 TO |
202 | } |
203 | ||
204 | $gIds['custom_pre_id'] = $values['custom_pre_id']; | |
205 | } | |
206 | ||
207 | if (isset($values['custom_post_id'])) { | |
208 | $postProfileType = CRM_Core_BAO_UFField::getProfileType($values['custom_post_id']); | |
8cc574cf | 209 | if ($postProfileType == 'Membership' && !empty($values['membership_id'])) { |
be2fb01f CW |
210 | $params['custom_post_id'] = [ |
211 | [ | |
6a488035 TO |
212 | 'member_id', |
213 | '=', | |
214 | $values['membership_id'], | |
215 | 0, | |
216 | 0, | |
be2fb01f CW |
217 | ], |
218 | ]; | |
6a488035 | 219 | } |
8cc574cf | 220 | elseif ($postProfileType == 'Contribution' && !empty($values['contribution_id'])) { |
be2fb01f CW |
221 | $params['custom_post_id'] = [ |
222 | [ | |
6a488035 TO |
223 | 'contribution_id', |
224 | '=', | |
225 | $values['contribution_id'], | |
226 | 0, | |
227 | 0, | |
be2fb01f CW |
228 | ], |
229 | ]; | |
6a488035 TO |
230 | } |
231 | ||
232 | $gIds['custom_post_id'] = $values['custom_post_id']; | |
233 | } | |
234 | ||
a7488080 CW |
235 | if (!empty($values['is_for_organization'])) { |
236 | if (!empty($values['membership_id'])) { | |
be2fb01f CW |
237 | $params['onbehalf_profile'] = [ |
238 | [ | |
6a488035 TO |
239 | 'member_id', |
240 | '=', | |
241 | $values['membership_id'], | |
242 | 0, | |
243 | 0, | |
be2fb01f CW |
244 | ], |
245 | ]; | |
6a488035 | 246 | } |
a7488080 | 247 | elseif (!empty($values['contribution_id'])) { |
be2fb01f CW |
248 | $params['onbehalf_profile'] = [ |
249 | [ | |
6a488035 TO |
250 | 'contribution_id', |
251 | '=', | |
252 | $values['contribution_id'], | |
253 | 0, | |
254 | 0, | |
be2fb01f CW |
255 | ], |
256 | ]; | |
6a488035 TO |
257 | } |
258 | } | |
259 | ||
260 | //check whether it is a test drive | |
261 | if ($isTest && !empty($params['custom_pre_id'])) { | |
be2fb01f | 262 | $params['custom_pre_id'][] = [ |
6a488035 TO |
263 | 'contribution_test', |
264 | '=', | |
265 | 1, | |
266 | 0, | |
267 | 0, | |
be2fb01f | 268 | ]; |
6a488035 TO |
269 | } |
270 | ||
271 | if ($isTest && !empty($params['custom_post_id'])) { | |
be2fb01f | 272 | $params['custom_post_id'][] = [ |
6a488035 TO |
273 | 'contribution_test', |
274 | '=', | |
275 | 1, | |
276 | 0, | |
277 | 0, | |
be2fb01f | 278 | ]; |
6a488035 | 279 | } |
8ef12e64 | 280 | |
6a488035 TO |
281 | if (!$returnMessageText && !empty($gIds)) { |
282 | //send notification email if field values are set (CRM-1941) | |
283 | foreach ($gIds as $key => $gId) { | |
284 | if ($gId) { | |
285 | $email = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $gId, 'notify'); | |
286 | if ($email) { | |
481a74f4 | 287 | $val = CRM_Core_BAO_UFGroup::checkFieldsEmptyValues($gId, $contactID, CRM_Utils_Array::value($key, $params), TRUE); |
6a488035 TO |
288 | CRM_Core_BAO_UFGroup::commonSendMail($contactID, $val); |
289 | } | |
290 | } | |
291 | } | |
292 | } | |
293 | ||
8cc574cf | 294 | if (!empty($values['is_email_receipt']) || !empty($values['onbehalf_dupe_alert']) || |
6a488035 TO |
295 | $returnMessageText |
296 | ) { | |
297 | $template = CRM_Core_Smarty::singleton(); | |
298 | ||
299 | // get the billing location type | |
300 | if (!array_key_exists('related_contact', $values)) { | |
b576d770 | 301 | $billingLocationTypeId = CRM_Core_BAO_LocationType::getBilling(); |
6a488035 TO |
302 | } |
303 | else { | |
304 | // presence of related contact implies onbehalf of org case, | |
305 | // where location type is set to default. | |
306 | $locType = CRM_Core_BAO_LocationType::getDefault(); | |
307 | $billingLocationTypeId = $locType->id; | |
308 | } | |
309 | ||
310 | if (!array_key_exists('related_contact', $values)) { | |
311 | list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID, FALSE, $billingLocationTypeId); | |
312 | } | |
313 | // get primary location email if no email exist( for billing location). | |
314 | if (!$email) { | |
315 | list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID); | |
316 | } | |
317 | if (empty($displayName)) { | |
318 | list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID); | |
319 | } | |
320 | ||
321 | //for display profile need to get individual contact id, | |
322 | //hence get it from related_contact if on behalf of org true CRM-3767 | |
323 | //CRM-5001 Contribution/Membership:: On Behalf of Organization, | |
324 | //If profile GROUP contain the Individual type then consider the | |
325 | //profile is of Individual ( including the custom data of membership/contribution ) | |
326 | //IF Individual type not present in profile then it is consider as Organization data. | |
327 | $userID = $contactID; | |
328 | if ($preID = CRM_Utils_Array::value('custom_pre_id', $values)) { | |
a7488080 | 329 | if (!empty($values['related_contact'])) { |
6a488035 | 330 | $preProfileTypes = CRM_Core_BAO_UFGroup::profileGroups($preID); |
b8950542 | 331 | //@todo - following line should not refer to undefined $postProfileTypes? figure out way to test |
6a488035 TO |
332 | if (in_array('Individual', $preProfileTypes) || in_array('Contact', $postProfileTypes)) { |
333 | //Take Individual contact ID | |
334 | $userID = CRM_Utils_Array::value('related_contact', $values); | |
335 | } | |
336 | } | |
6e10d414 | 337 | list($values['customPre_grouptitle'], $values['customPre']) = self::getProfileNameAndFields($preID, $userID, $params['custom_pre_id']); |
6a488035 TO |
338 | } |
339 | $userID = $contactID; | |
340 | if ($postID = CRM_Utils_Array::value('custom_post_id', $values)) { | |
a7488080 | 341 | if (!empty($values['related_contact'])) { |
6a488035 TO |
342 | $postProfileTypes = CRM_Core_BAO_UFGroup::profileGroups($postID); |
343 | if (in_array('Individual', $postProfileTypes) || in_array('Contact', $postProfileTypes)) { | |
344 | //Take Individual contact ID | |
345 | $userID = CRM_Utils_Array::value('related_contact', $values); | |
346 | } | |
347 | } | |
6e10d414 | 348 | list($values['customPost_grouptitle'], $values['customPost']) = self::getProfileNameAndFields($postID, $userID, $params['custom_post_id']); |
6a488035 | 349 | } |
1421174e | 350 | if (isset($values['honor'])) { |
351 | $honorValues = $values['honor']; | |
be2fb01f | 352 | $template->_values = ['honoree_profile_id' => $values['honoree_profile_id']]; |
1421174e | 353 | CRM_Contribute_BAO_ContributionSoft::formatHonoreeProfileFields( |
354 | $template, | |
355 | $honorValues['honor_profile_values'], | |
1421174e | 356 | $honorValues['honor_id'] |
357 | ); | |
358 | } | |
6a488035 TO |
359 | |
360 | $title = isset($values['title']) ? $values['title'] : CRM_Contribute_PseudoConstant::contributionPage($values['contribution_page_id']); | |
361 | ||
557e8899 | 362 | // Set email variables explicitly to avoid leaky smarty variables. |
363 | // All of these will be assigned to the template, replacing any that might be assigned elsewhere. | |
be2fb01f | 364 | $tplParams = [ |
6a488035 TO |
365 | 'email' => $email, |
366 | 'receiptFromEmail' => CRM_Utils_Array::value('receipt_from_email', $values), | |
367 | 'contactID' => $contactID, | |
368 | 'displayName' => $displayName, | |
369 | 'contributionID' => CRM_Utils_Array::value('contribution_id', $values), | |
370 | 'contributionOtherID' => CRM_Utils_Array::value('contribution_other_id', $values), | |
6a488035 TO |
371 | // CRM-5095 |
372 | 'lineItem' => CRM_Utils_Array::value('lineItem', $values), | |
373 | // CRM-5095 | |
374 | 'priceSetID' => CRM_Utils_Array::value('priceSetID', $values), | |
375 | 'title' => $title, | |
376 | 'isShare' => CRM_Utils_Array::value('is_share', $values), | |
8b067691 | 377 | 'thankyou_title' => CRM_Utils_Array::value('thankyou_title', $values), |
6e10d414 | 378 | 'customPre' => $values['customPre'], |
379 | 'customPre_grouptitle' => $values['customPre_grouptitle'], | |
380 | 'customPost' => $values['customPost'], | |
381 | 'customPost_grouptitle' => $values['customPost_grouptitle'], | |
557e8899 | 382 | 'useForMember' => $values['useForMember'], |
858f7096 | 383 | 'membership_assign' => $values['membership_assign'], |
384 | 'amount' => $values['amount'], | |
c2358f41 | 385 | 'is_pay_later' => $values['is_pay_later'], |
76e8d9c4 | 386 | 'receipt_date' => !$values['receipt_date'] ? NULL : date('YmdHis', strtotime($values['receipt_date'])), |
e05d2e11 | 387 | 'pay_later_receipt' => CRM_Utils_Array::value('pay_later_receipt', $values), |
399cd461 | 388 | 'honor_block_is_active' => CRM_Utils_Array::value('honor_block_is_active', $values), |
3b28799d | 389 | 'contributionStatus' => CRM_Utils_Array::value('contribution_status', $values), |
be2fb01f | 390 | ]; |
6a488035 | 391 | |
91bb24a7 | 392 | if ($contributionTypeId = CRM_Utils_Array::value('financial_type_id', $values)) { |
b956b310 | 393 | $tplParams['financialTypeId'] = $contributionTypeId; |
394 | $tplParams['financialTypeName'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', | |
91bb24a7 | 395 | $contributionTypeId); |
b956b310 | 396 | // Legacy support |
397 | $tplParams['contributionTypeName'] = $tplParams['financialTypeName']; | |
398 | $tplParams['contributionTypeId'] = $contributionTypeId; | |
6a488035 TO |
399 | } |
400 | ||
401 | if ($contributionPageId = CRM_Utils_Array::value('id', $values)) { | |
402 | $tplParams['contributionPageId'] = $contributionPageId; | |
403 | } | |
404 | ||
405 | // address required during receipt processing (pdf and email receipt) | |
406 | if ($displayAddress = CRM_Utils_Array::value('address', $values)) { | |
407 | $tplParams['address'] = $displayAddress; | |
408 | } | |
409 | ||
410 | // CRM-6976 | |
411 | $originalCCReceipt = CRM_Utils_Array::value('cc_receipt', $values); | |
412 | ||
413 | // cc to related contacts of contributor OR the one who | |
414 | // signs up. Is used for cases like - on behalf of | |
415 | // contribution / signup ..etc | |
416 | if (array_key_exists('related_contact', $values)) { | |
417 | list($ccDisplayName, $ccEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($values['related_contact']); | |
418 | $ccMailId = "{$ccDisplayName} <{$ccEmail}>"; | |
419 | ||
fdd2a6db | 420 | //@todo - this is the only place in this function where $values is altered - but I can't find any evidence it is used |
0d8afee2 | 421 | $values['cc_receipt'] = !empty($values['cc_receipt']) ? ($values['cc_receipt'] . ',' . $ccMailId) : $ccMailId; |
6a488035 TO |
422 | |
423 | // reset primary-email in the template | |
424 | $tplParams['email'] = $ccEmail; | |
425 | ||
426 | $tplParams['onBehalfName'] = $displayName; | |
427 | $tplParams['onBehalfEmail'] = $email; | |
428 | ||
4779abb3 | 429 | if (!empty($values['onbehalf_profile_id'])) { |
430 | self::buildCustomDisplay($values['onbehalf_profile_id'], 'onBehalfProfile', $contactID, $template, $params['onbehalf_profile'], $fieldTypes); | |
431 | } | |
6a488035 TO |
432 | } |
433 | ||
434 | // use either the contribution or membership receipt, based on whether it’s a membership-related contrib or not | |
be2fb01f | 435 | $sendTemplateParams = [ |
12dac866 | 436 | 'groupName' => !empty($values['isMembership']) ? 'msg_tpl_workflow_membership' : 'msg_tpl_workflow_contribution', |
437 | 'valueName' => !empty($values['isMembership']) ? 'membership_online_receipt' : 'contribution_online_receipt', | |
6a488035 TO |
438 | 'contactId' => $contactID, |
439 | 'tplParams' => $tplParams, | |
440 | 'isTest' => $isTest, | |
441 | 'PDFFilename' => 'receipt.pdf', | |
be2fb01f | 442 | ]; |
6a488035 TO |
443 | |
444 | if ($returnMessageText) { | |
c6327d7d | 445 | list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams); |
be2fb01f | 446 | return [ |
6a488035 TO |
447 | 'subject' => $subject, |
448 | 'body' => $message, | |
449 | 'to' => $displayName, | |
450 | 'html' => $html, | |
be2fb01f | 451 | ]; |
6a488035 TO |
452 | } |
453 | ||
ec7e3954 E |
454 | if (empty($values['receipt_from_name']) && empty($values['receipt_from_name'])) { |
455 | list($values['receipt_from_name'], $values['receipt_from_email']) = CRM_Core_BAO_Domain::getNameAndEmail(); | |
456 | } | |
457 | ||
6a488035 TO |
458 | if ($values['is_email_receipt']) { |
459 | $sendTemplateParams['from'] = CRM_Utils_Array::value('receipt_from_name', $values) . ' <' . $values['receipt_from_email'] . '>'; | |
460 | $sendTemplateParams['toName'] = $displayName; | |
461 | $sendTemplateParams['toEmail'] = $email; | |
462 | $sendTemplateParams['cc'] = CRM_Utils_Array::value('cc_receipt', $values); | |
463 | $sendTemplateParams['bcc'] = CRM_Utils_Array::value('bcc_receipt', $values); | |
9161952c | 464 | //send email with pdf invoice |
481a74f4 | 465 | $template = CRM_Core_Smarty::singleton(); |
9161952c | 466 | $taxAmt = $template->get_template_vars('dataArray'); |
aaffa79f | 467 | $prefixValue = Civi::settings()->get('contribution_invoice_settings'); |
9161952c | 468 | $invoicing = CRM_Utils_Array::value('invoicing', $prefixValue); |
121bf42c | 469 | if (isset($invoicing) && isset($prefixValue['is_email_pdf'])) { |
874c9be7 | 470 | $sendTemplateParams['isEmailPdf'] = TRUE; |
9161952c PD |
471 | $sendTemplateParams['contributionId'] = $values['contribution_id']; |
472 | } | |
c6327d7d | 473 | list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams); |
6a488035 TO |
474 | } |
475 | ||
476 | // send duplicate alert, if dupe match found during on-behalf-of processing. | |
a7488080 | 477 | if (!empty($values['onbehalf_dupe_alert'])) { |
6a488035 TO |
478 | $sendTemplateParams['groupName'] = 'msg_tpl_workflow_contribution'; |
479 | $sendTemplateParams['valueName'] = 'contribution_dupalert'; | |
480 | $sendTemplateParams['from'] = ts('Automatically Generated') . " <{$values['receipt_from_email']}>"; | |
481 | $sendTemplateParams['toName'] = CRM_Utils_Array::value('receipt_from_name', $values); | |
482 | $sendTemplateParams['toEmail'] = CRM_Utils_Array::value('receipt_from_email', $values); | |
483 | $sendTemplateParams['tplParams']['onBehalfID'] = $contactID; | |
484 | $sendTemplateParams['tplParams']['receiptMessage'] = $message; | |
485 | ||
486 | // fix cc and reset back to original, CRM-6976 | |
487 | $sendTemplateParams['cc'] = $originalCCReceipt; | |
488 | ||
c6327d7d | 489 | CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams); |
6a488035 TO |
490 | } |
491 | } | |
492 | } | |
8ef12e64 | 493 | |
6e10d414 | 494 | /** |
495 | * Get the profile title and fields. | |
496 | * | |
497 | * @param int $gid | |
498 | * @param int $cid | |
499 | * @param array $params | |
500 | * @param array $fieldTypes | |
501 | * | |
502 | * @return array | |
503 | */ | |
be2fb01f | 504 | protected static function getProfileNameAndFields($gid, $cid, &$params, $fieldTypes = []) { |
6e10d414 | 505 | $groupTitle = NULL; |
be2fb01f | 506 | $values = []; |
6e10d414 | 507 | if ($gid) { |
508 | if (CRM_Core_BAO_UFGroup::filterUFGroups($gid, $cid)) { | |
509 | $fields = CRM_Core_BAO_UFGroup::getFields($gid, FALSE, CRM_Core_Action::VIEW, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL); | |
510 | foreach ($fields as $k => $v) { | |
511 | if (!$groupTitle) { | |
512 | $groupTitle = $v["groupTitle"]; | |
513 | } | |
514 | // suppress all file fields from display and formatting fields | |
515 | if ( | |
516 | CRM_Utils_Array::value('data_type', $v, '') == 'File' || | |
517 | CRM_Utils_Array::value('name', $v, '') == 'image_URL' || | |
518 | CRM_Utils_Array::value('field_type', $v) == 'Formatting' | |
519 | ) { | |
520 | unset($fields[$k]); | |
521 | } | |
522 | ||
523 | if (!empty($fieldTypes) && (!in_array($v['field_type'], $fieldTypes))) { | |
524 | unset($fields[$k]); | |
525 | } | |
526 | } | |
527 | ||
528 | CRM_Core_BAO_UFGroup::getValues($cid, $fields, $values, FALSE, $params); | |
529 | } | |
530 | } | |
be2fb01f | 531 | return [$groupTitle, $values]; |
6e10d414 | 532 | } |
533 | ||
186c9c17 | 534 | /** |
84f0ed41 | 535 | * Send the emails for Recurring Contribution Notification. |
6a488035 | 536 | * |
014c4014 TO |
537 | * @param string $type |
538 | * TxnType. | |
539 | * @param int $contactID | |
540 | * Contact id for contributor. | |
541 | * @param int $pageID | |
542 | * Contribution page id. | |
543 | * @param object $recur | |
544 | * Object of recurring contribution table. | |
2a6da8d7 | 545 | * @param bool|object $autoRenewMembership is it a auto renew membership. |
6a488035 | 546 | */ |
00be9182 | 547 | public static function recurringNotify($type, $contactID, $pageID, $recur, $autoRenewMembership = FALSE) { |
be2fb01f | 548 | $value = []; |
ddf80fb9 | 549 | $isEmailReceipt = FALSE; |
6a488035 | 550 | if ($pageID) { |
be2fb01f | 551 | CRM_Core_DAO::commonRetrieveAll('CRM_Contribute_DAO_ContributionPage', 'id', $pageID, $value, [ |
91bb24a7 | 552 | 'title', |
553 | 'is_email_receipt', | |
554 | 'receipt_from_name', | |
555 | 'receipt_from_email', | |
556 | 'cc_receipt', | |
557 | 'bcc_receipt', | |
be2fb01f | 558 | ]); |
ab30e033 | 559 | $isEmailReceipt = CRM_Utils_Array::value('is_email_receipt', $value[$pageID]); |
6a488035 | 560 | } |
ab30e033 EM |
561 | elseif ($recur->id) { |
562 | // This means we are coming from back-office - ie. no page ID, but recurring. | |
563 | // Ideally this information would be passed into the function clearly rather than guessing by convention. | |
564 | $isEmailReceipt = TRUE; | |
6a488035 | 565 | } |
ab30e033 EM |
566 | |
567 | if ($isEmailReceipt) { | |
6a488035 TO |
568 | if ($pageID) { |
569 | $receiptFrom = '"' . CRM_Utils_Array::value('receipt_from_name', $value[$pageID]) . '" <' . $value[$pageID]['receipt_from_email'] . '>'; | |
570 | ||
571 | $receiptFromName = $value[$pageID]['receipt_from_name']; | |
572 | $receiptFromEmail = $value[$pageID]['receipt_from_email']; | |
573 | } | |
574 | else { | |
91bb24a7 | 575 | $domainValues = CRM_Core_BAO_Domain::getNameAndEmail(); |
576 | $receiptFrom = "$domainValues[0] <$domainValues[1]>"; | |
577 | $receiptFromName = $domainValues[0]; | |
6a488035 TO |
578 | $receiptFromEmail = $domainValues[1]; |
579 | } | |
580 | ||
581 | list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID, FALSE); | |
be2fb01f | 582 | $templatesParams = [ |
6a488035 TO |
583 | 'groupName' => 'msg_tpl_workflow_contribution', |
584 | 'valueName' => 'contribution_recurring_notify', | |
585 | 'contactId' => $contactID, | |
be2fb01f | 586 | 'tplParams' => [ |
6a488035 TO |
587 | 'recur_frequency_interval' => $recur->frequency_interval, |
588 | 'recur_frequency_unit' => $recur->frequency_unit, | |
589 | 'recur_installments' => $recur->installments, | |
590 | 'recur_start_date' => $recur->start_date, | |
591 | 'recur_end_date' => $recur->end_date, | |
592 | 'recur_amount' => $recur->amount, | |
593 | 'recur_txnType' => $type, | |
594 | 'displayName' => $displayName, | |
595 | 'receipt_from_name' => $receiptFromName, | |
596 | 'receipt_from_email' => $receiptFromEmail, | |
597 | 'auto_renew_membership' => $autoRenewMembership, | |
be2fb01f | 598 | ], |
6a488035 TO |
599 | 'from' => $receiptFrom, |
600 | 'toName' => $displayName, | |
601 | 'toEmail' => $email, | |
be2fb01f | 602 | ]; |
1421174e | 603 | //CRM-13811 |
039134ba | 604 | if ($pageID) { |
605 | $templatesParams['cc'] = CRM_Utils_Array::value('cc_receipt', $value[$pageID]); | |
606 | $templatesParams['bcc'] = CRM_Utils_Array::value('bcc_receipt', $value[$pageID]); | |
607 | } | |
6a488035 TO |
608 | if ($recur->id) { |
609 | // in some cases its just recurringNotify() thats called for the first time and these urls don't get set. | |
610 | // like in PaypalPro, & therefore we set it here additionally. | |
91bb24a7 | 611 | $template = CRM_Core_Smarty::singleton(); |
6a488035 | 612 | $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity($recur->id, 'recur', 'obj'); |
3e473c0b | 613 | $url = $paymentProcessor->subscriptionURL($recur->id, 'recur', 'cancel'); |
6a488035 TO |
614 | $template->assign('cancelSubscriptionUrl', $url); |
615 | ||
616 | $url = $paymentProcessor->subscriptionURL($recur->id, 'recur', 'billing'); | |
617 | $template->assign('updateSubscriptionBillingUrl', $url); | |
618 | ||
619 | $url = $paymentProcessor->subscriptionURL($recur->id, 'recur', 'update'); | |
620 | $template->assign('updateSubscriptionUrl', $url); | |
621 | } | |
622 | ||
84f0ed41 | 623 | list($sent) = CRM_Core_BAO_MessageTemplate::sendTemplate($templatesParams); |
6a488035 TO |
624 | |
625 | if ($sent) { | |
626 | CRM_Core_Error::debug_log_message('Success: mail sent for recurring notification.'); | |
627 | } | |
628 | else { | |
629 | CRM_Core_Error::debug_log_message('Failure: mail not sent for recurring notification.'); | |
630 | } | |
631 | } | |
632 | } | |
633 | ||
634 | /** | |
c7e7164f | 635 | * Add the custom fields for contribution page (ie profile). |
636 | * | |
637 | * @deprecated assigning values to smarty like this is risky because | |
638 | * - it is hard to debug since $name is used in the assign | |
639 | * - it is potentially 'leaky' - it's better to do this on the form | |
640 | * or close to where it is used / required. See CRM-17519 for leakage e.g. | |
6a488035 | 641 | * |
014c4014 TO |
642 | * @param int $gid |
643 | * Uf group id. | |
6a488035 | 644 | * @param string $name |
014c4014 TO |
645 | * @param int $cid |
646 | * Contact id. | |
2a6da8d7 | 647 | * @param $template |
014c4014 TO |
648 | * @param array $params |
649 | * Params to build component whereclause. | |
2a6da8d7 | 650 | * |
6e10d414 | 651 | * @param array|null $fieldTypes |
6a488035 | 652 | */ |
6e10d414 | 653 | public static function buildCustomDisplay($gid, $name, $cid, &$template, &$params, $fieldTypes = NULL) { |
654 | list($groupTitle, $values) = self::getProfileNameAndFields($gid, $cid, $params, $fieldTypes); | |
655 | if (!empty($values)) { | |
656 | $template->assign($name, $values); | |
6a488035 | 657 | } |
6e10d414 | 658 | $template->assign($name . "_grouptitle", $groupTitle); |
6a488035 TO |
659 | } |
660 | ||
661 | /** | |
2c4442ca | 662 | * Make a copy of a contribution page, including all the blocks in the page. |
6a488035 | 663 | * |
014c4014 TO |
664 | * @param int $id |
665 | * The contribution page id to copy. | |
6a488035 | 666 | * |
72b3a70c | 667 | * @return CRM_Contribute_DAO_ContributionPage |
6a488035 | 668 | */ |
00be9182 | 669 | public static function copy($id) { |
be2fb01f CW |
670 | $fieldsFix = [ |
671 | 'prefix' => [ | |
6a488035 | 672 | 'title' => ts('Copy of') . ' ', |
be2fb01f CW |
673 | ], |
674 | ]; | |
3fec1adc | 675 | $copy = CRM_Core_DAO::copyGeneric('CRM_Contribute_DAO_ContributionPage', [ |
353ffa53 | 676 | 'id' => $id, |
be2fb01f | 677 | ], NULL, $fieldsFix); |
6a488035 TO |
678 | |
679 | //copying all the blocks pertaining to the contribution page | |
3fec1adc | 680 | $copyPledgeBlock = CRM_Core_DAO::copyGeneric('CRM_Pledge_DAO_PledgeBlock', [ |
353ffa53 TO |
681 | 'entity_id' => $id, |
682 | 'entity_table' => 'civicrm_contribution_page', | |
be2fb01f | 683 | ], [ |
353ffa53 | 684 | 'entity_id' => $copy->id, |
be2fb01f | 685 | ]); |
6a488035 | 686 | |
3fec1adc | 687 | $copyMembershipBlock = CRM_Core_DAO::copyGeneric('CRM_Member_DAO_MembershipBlock', [ |
353ffa53 TO |
688 | 'entity_id' => $id, |
689 | 'entity_table' => 'civicrm_contribution_page', | |
be2fb01f | 690 | ], [ |
353ffa53 | 691 | 'entity_id' => $copy->id, |
be2fb01f | 692 | ]); |
6a488035 | 693 | |
3fec1adc | 694 | $copyUFJoin = CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFJoin', [ |
353ffa53 TO |
695 | 'entity_id' => $id, |
696 | 'entity_table' => 'civicrm_contribution_page', | |
be2fb01f | 697 | ], [ |
353ffa53 | 698 | 'entity_id' => $copy->id, |
be2fb01f | 699 | ]); |
6a488035 | 700 | |
3fec1adc | 701 | $copyWidget = CRM_Core_DAO::copyGeneric('CRM_Contribute_DAO_Widget', [ |
353ffa53 | 702 | 'contribution_page_id' => $id, |
be2fb01f | 703 | ], [ |
353ffa53 | 704 | 'contribution_page_id' => $copy->id, |
be2fb01f | 705 | ]); |
6a488035 | 706 | |
c6914066 | 707 | //copy price sets |
9da8dc8c | 708 | CRM_Price_BAO_PriceSet::copyPriceSet('civicrm_contribution_page', $id, $copy->id); |
c6914066 | 709 | |
3fec1adc | 710 | $copyTellFriend = CRM_Core_DAO::copyGeneric('CRM_Friend_DAO_Friend', [ |
353ffa53 TO |
711 | 'entity_id' => $id, |
712 | 'entity_table' => 'civicrm_contribution_page', | |
be2fb01f | 713 | ], [ |
353ffa53 | 714 | 'entity_id' => $copy->id, |
be2fb01f | 715 | ]); |
6a488035 | 716 | |
3fec1adc | 717 | $copyPersonalCampaignPages = CRM_Core_DAO::copyGeneric('CRM_PCP_DAO_PCPBlock', [ |
353ffa53 TO |
718 | 'entity_id' => $id, |
719 | 'entity_table' => 'civicrm_contribution_page', | |
be2fb01f | 720 | ], [ |
353ffa53 | 721 | 'entity_id' => $copy->id, |
b7ff0a0a | 722 | 'target_entity_id' => $copy->id, |
be2fb01f | 723 | ]); |
6a488035 | 724 | |
3fec1adc | 725 | $copyPremium = CRM_Core_DAO::copyGeneric('CRM_Contribute_DAO_Premium', [ |
353ffa53 TO |
726 | 'entity_id' => $id, |
727 | 'entity_table' => 'civicrm_contribution_page', | |
be2fb01f | 728 | ], [ |
353ffa53 | 729 | 'entity_id' => $copy->id, |
be2fb01f | 730 | ]); |
6a488035 TO |
731 | $premiumQuery = " |
732 | SELECT id | |
733 | FROM civicrm_premiums | |
734 | WHERE entity_table = 'civicrm_contribution_page' | |
735 | AND entity_id ={$id}"; | |
736 | ||
e03e1641 | 737 | $premiumDao = CRM_Core_DAO::executeQuery($premiumQuery); |
6a488035 TO |
738 | while ($premiumDao->fetch()) { |
739 | if ($premiumDao->id) { | |
be2fb01f | 740 | CRM_Core_DAO::copyGeneric('CRM_Contribute_DAO_PremiumsProduct', [ |
91bb24a7 | 741 | 'premiums_id' => $premiumDao->id, |
be2fb01f | 742 | ], [ |
91bb24a7 | 743 | 'premiums_id' => $copyPremium->id, |
be2fb01f | 744 | ]); |
6a488035 TO |
745 | } |
746 | } | |
747 | ||
748 | $copy->save(); | |
749 | ||
750 | CRM_Utils_Hook::copy('ContributionPage', $copy); | |
751 | ||
752 | return $copy; | |
753 | } | |
754 | ||
6a488035 | 755 | /** |
100fef9d | 756 | * Get info for all sections enable/disable. |
6a488035 | 757 | * |
2a6da8d7 | 758 | * @param array $contribPageIds |
a6c01b45 CW |
759 | * @return array |
760 | * info regarding all sections. | |
6a488035 | 761 | */ |
be2fb01f CW |
762 | public static function getSectionInfo($contribPageIds = []) { |
763 | $info = []; | |
6a488035 TO |
764 | $whereClause = NULL; |
765 | if (is_array($contribPageIds) && !empty($contribPageIds)) { | |
766 | $whereClause = 'WHERE civicrm_contribution_page.id IN ( ' . implode(', ', $contribPageIds) . ' )'; | |
767 | } | |
768 | ||
be2fb01f | 769 | $sections = [ |
6a488035 TO |
770 | 'settings', |
771 | 'amount', | |
772 | 'membership', | |
773 | 'custom', | |
774 | 'thankyou', | |
775 | 'friend', | |
776 | 'pcp', | |
777 | 'widget', | |
778 | 'premium', | |
be2fb01f | 779 | ]; |
6a488035 TO |
780 | $query = " |
781 | SELECT civicrm_contribution_page.id as id, | |
8ef12e64 | 782 | civicrm_contribution_page.financial_type_id as settings, |
6a488035 TO |
783 | amount_block_is_active as amount, |
784 | civicrm_membership_block.id as membership, | |
785 | civicrm_uf_join.id as custom, | |
786 | civicrm_contribution_page.thankyou_title as thankyou, | |
787 | civicrm_tell_friend.id as friend, | |
788 | civicrm_pcp_block.id as pcp, | |
789 | civicrm_contribution_widget.id as widget, | |
790 | civicrm_premiums.id as premium | |
791 | FROM civicrm_contribution_page | |
792 | LEFT JOIN civicrm_membership_block ON ( civicrm_membership_block.entity_id = civicrm_contribution_page.id | |
793 | AND civicrm_membership_block.entity_table = 'civicrm_contribution_page' | |
794 | AND civicrm_membership_block.is_active = 1 ) | |
795 | LEFT JOIN civicrm_uf_join ON ( civicrm_uf_join.entity_id = civicrm_contribution_page.id | |
796 | AND civicrm_uf_join.entity_table = 'civicrm_contribution_page' | |
797 | AND module = 'CiviContribute' | |
798 | AND civicrm_uf_join.is_active = 1 ) | |
799 | LEFT JOIN civicrm_tell_friend ON ( civicrm_tell_friend.entity_id = civicrm_contribution_page.id | |
800 | AND civicrm_tell_friend.entity_table = 'civicrm_contribution_page' | |
801 | AND civicrm_tell_friend.is_active = 1) | |
802 | LEFT JOIN civicrm_pcp_block ON ( civicrm_pcp_block.entity_id = civicrm_contribution_page.id | |
803 | AND civicrm_pcp_block.entity_table = 'civicrm_contribution_page' | |
804 | AND civicrm_pcp_block.is_active = 1 ) | |
805 | LEFT JOIN civicrm_contribution_widget ON ( civicrm_contribution_widget.contribution_page_id = civicrm_contribution_page.id | |
806 | AND civicrm_contribution_widget.is_active = 1 ) | |
807 | LEFT JOIN civicrm_premiums ON ( civicrm_premiums.entity_id = civicrm_contribution_page.id | |
808 | AND civicrm_premiums.entity_table = 'civicrm_contribution_page' | |
809 | AND civicrm_premiums.premiums_active = 1 ) | |
810 | $whereClause"; | |
811 | ||
812 | $contributionPage = CRM_Core_DAO::executeQuery($query); | |
813 | while ($contributionPage->fetch()) { | |
814 | if (!isset($info[$contributionPage->id]) || !is_array($info[$contributionPage->id])) { | |
815 | $info[$contributionPage->id] = array_fill_keys(array_values($sections), FALSE); | |
816 | } | |
817 | foreach ($sections as $section) { | |
818 | if ($contributionPage->$section) { | |
819 | $info[$contributionPage->id][$section] = TRUE; | |
820 | } | |
821 | } | |
822 | } | |
823 | ||
824 | return $info; | |
825 | } | |
e1462487 CW |
826 | |
827 | /** | |
828 | * Get options for a given field. | |
829 | * @see CRM_Core_DAO::buildOptions | |
830 | * | |
014c4014 | 831 | * @param string $fieldName |
353ffa53 TO |
832 | * @param string $context : @see CRM_Core_DAO::buildOptionsContext |
833 | * @param array $props : whatever is known about this dao object | |
e1462487 CW |
834 | * |
835 | * @return array|bool | |
836 | */ | |
be2fb01f CW |
837 | public static function buildOptions($fieldName, $context = NULL, $props = []) { |
838 | $params = []; | |
e1462487 CW |
839 | // Special logic for fields whose options depend on context or properties |
840 | switch ($fieldName) { | |
841 | case 'financial_type_id': | |
842 | // Fixme - this is going to ignore context, better to get conditions, add params, and call PseudoConstant::get | |
843 | return CRM_Financial_BAO_FinancialType::getIncomeFinancialType(); | |
874c9be7 | 844 | |
79d7553f | 845 | break; |
e1462487 CW |
846 | } |
847 | return CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context); | |
848 | } | |
ba60f73e | 849 | |
850 | /** | |
e63910c5 | 851 | * Get or Set honor/on_behalf params for processing module_data or setting default values. |
ba60f73e | 852 | * |
e63910c5 | 853 | * @param array $params : |
353ffa53 | 854 | * @param bool $setDefault : If yes then returns array to used for setting default value afterward |
e63910c5 | 855 | * @param string $module : processing module_data for which module? e.g. soft_credit, on_behalf |
ba60f73e | 856 | * |
857 | * @return array|string | |
858 | */ | |
e63910c5 | 859 | public static function formatModuleData($params, $setDefault = FALSE, $module) { |
98466ff9 | 860 | $tsLocale = CRM_Core_I18n::getLocale(); |
ba60f73e | 861 | $config = CRM_Core_Config::singleton(); |
e63910c5 | 862 | $json = $jsonDecode = NULL; |
ba60f73e | 863 | $domain = new CRM_Core_DAO_Domain(); |
864 | $domain->find(TRUE); | |
865 | ||
be2fb01f CW |
866 | $moduleDataFormat = [ |
867 | 'soft_credit' => [ | |
f23093b2 | 868 | 1 => 'soft_credit_types', |
be2fb01f | 869 | 'multilingual' => [ |
e63910c5 | 870 | 'honor_block_title', |
cb804cd9 | 871 | 'honor_block_text', |
be2fb01f CW |
872 | ], |
873 | ], | |
874 | 'on_behalf' => [ | |
f23093b2 | 875 | 1 => 'is_for_organization', |
be2fb01f | 876 | 'multilingual' => [ |
f23093b2 | 877 | 'for_organization', |
be2fb01f CW |
878 | ], |
879 | ], | |
880 | ]; | |
e63910c5 | 881 | |
12792976 | 882 | //When we are fetching the honor params respecting both multi and mono lingual state |
ba60f73e | 883 | //and setting it to default param of Contribution Page's Main and Setting form |
884 | if ($setDefault) { | |
e63910c5 | 885 | $jsonDecode = json_decode($params); |
886 | $jsonDecode = (array) $jsonDecode->$module; | |
887 | if (!$domain->locales && !empty($jsonDecode['default'])) { | |
12792976 | 888 | //monolingual state |
e63910c5 | 889 | $jsonDecode += (array) $jsonDecode['default']; |
890 | unset($jsonDecode['default']); | |
12792976 | 891 | } |
d50cdfb5 | 892 | elseif (!empty($jsonDecode[$tsLocale])) { |
12792976 | 893 | //multilingual state |
d50cdfb5 | 894 | foreach ($jsonDecode[$tsLocale] as $column => $value) { |
e63910c5 | 895 | $jsonDecode[$column] = $value; |
ba60f73e | 896 | } |
d50cdfb5 | 897 | unset($jsonDecode[$tsLocale]); |
ba60f73e | 898 | } |
e63910c5 | 899 | return $jsonDecode; |
ba60f73e | 900 | } |
901 | ||
902 | //check and handle multilingual honoree params | |
903 | if (!$domain->locales) { | |
904 | //if in singlelingual state simply return the array format | |
be2fb01f | 905 | $json = [$module => NULL]; |
e63910c5 | 906 | foreach ($moduleDataFormat[$module] as $key => $attribute) { |
907 | if ($key === 'multilingual') { | |
be2fb01f | 908 | $json[$module]['default'] = []; |
e63910c5 | 909 | foreach ($attribute as $attr) { |
910 | $json[$module]['default'][$attr] = $params[$attr]; | |
911 | } | |
912 | } | |
913 | else { | |
914 | $json[$module][$attribute] = $params[$attribute]; | |
915 | } | |
916 | } | |
917 | $json = json_encode($json); | |
ba60f73e | 918 | } |
919 | else { | |
920 | //if in multilingual state then retrieve the module_data against this contribution and | |
921 | //merge with earlier module_data json data to current so not to lose earlier multilingual module_data information | |
be2fb01f | 922 | $json = [$module => NULL]; |
e63910c5 | 923 | foreach ($moduleDataFormat[$module] as $key => $attribute) { |
924 | if ($key === 'multilingual') { | |
be2fb01f | 925 | $json[$module][$config->lcMessages] = []; |
e63910c5 | 926 | foreach ($attribute as $attr) { |
927 | $json[$module][$config->lcMessages][$attr] = $params[$attr]; | |
928 | } | |
929 | } | |
930 | else { | |
931 | $json[$module][$attribute] = $params[$attribute]; | |
d1f8e278 | 932 | } |
d1f8e278 | 933 | } |
d1f8e278 | 934 | |
935 | $ufJoinDAO = new CRM_Core_DAO_UFJoin(); | |
e63910c5 | 936 | $ufJoinDAO->module = $module; |
d1f8e278 | 937 | $ufJoinDAO->entity_id = $params['id']; |
938 | $ufJoinDAO->find(TRUE); | |
939 | $jsonData = json_decode($ufJoinDAO->module_data); | |
940 | if ($jsonData) { | |
e63910c5 | 941 | $json[$module] = array_merge((array) $jsonData->$module, $json[$module]); |
d1f8e278 | 942 | } |
e63910c5 | 943 | $json = json_encode($json); |
d1f8e278 | 944 | } |
e63910c5 | 945 | return $json; |
d1f8e278 | 946 | } |
947 | ||
948 | /** | |
949 | * Generate html for pdf in confirmation receipt email attachment. | |
014c4014 TO |
950 | * @param int $contributionId |
951 | * Contribution Page Id. | |
952 | * @param int $userID | |
953 | * Contact id for contributor. | |
a6c01b45 | 954 | * @return array |
9161952c | 955 | */ |
00be9182 | 956 | public static function addInvoicePdfToEmail($contributionId, $userID) { |
be2fb01f CW |
957 | $contributionID = [$contributionId]; |
958 | $contactId = [$userID]; | |
959 | $pdfParams = [ | |
9161952c | 960 | 'output' => 'pdf_invoice', |
21dfd5f5 | 961 | 'forPage' => 'confirmpage', |
be2fb01f | 962 | ]; |
1273d77c | 963 | $pdfHtml = CRM_Contribute_Form_Task_Invoice::printPDF($contributionID, $pdfParams, $contactId); |
9161952c PD |
964 | return $pdfHtml; |
965 | } | |
f64a217a EM |
966 | |
967 | /** | |
7fe37828 EM |
968 | * Helper to determine if the page supports separate membership payments. |
969 | * | |
79d7553f | 970 | * @param int $id form id |
f64a217a | 971 | * |
a6c01b45 CW |
972 | * @return bool |
973 | * isSeparateMembershipPayment | |
f64a217a | 974 | */ |
00be9182 | 975 | public static function getIsMembershipPayment($id) { |
be2fb01f | 976 | $membershipBlocks = civicrm_api3('membership_block', 'get', [ |
1330f57a SL |
977 | 'entity_table' => 'civicrm_contribution_page', |
978 | 'entity_id' => $id, | |
979 | 'sequential' => TRUE, | |
980 | ]); | |
22e263ad | 981 | if (!$membershipBlocks['count']) { |
f64a217a EM |
982 | return FALSE; |
983 | } | |
984 | return $membershipBlocks['values'][0]['is_separate_payment']; | |
985 | } | |
96025800 | 986 | |
6a488035 | 987 | } |