3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
18 use Civi\Api4\Contribution
;
19 use Civi\Api4\LineItem
;
22 * This class contains Contribution Page related functions.
24 class CRM_Contribute_BAO_ContributionPage
extends CRM_Contribute_DAO_ContributionPage
{
27 * Creates a contribution page.
29 * @param array $params
31 * @return CRM_Contribute_DAO_ContributionPage
33 public static function create($params) {
34 $financialTypeId = NULL;
35 if (!empty($params['id']) && !CRM_Price_BAO_PriceSet
::getFor('civicrm_contribution_page', $params['id'], NULL, 1)) {
36 $financialTypeId = CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_ContributionPage', $params['id'], 'financial_type_id');
39 if (isset($params['payment_processor']) && is_array($params['payment_processor'])) {
40 $params['payment_processor'] = implode(CRM_Core_DAO
::VALUE_SEPARATOR
, $params['payment_processor']);
42 $hook = empty($params['id']) ?
'create' : 'edit';
43 CRM_Utils_Hook
::pre($hook, 'ContributionPage', CRM_Utils_Array
::value('id', $params), $params);
44 $dao = new CRM_Contribute_DAO_ContributionPage();
45 $dao->copyValues($params);
47 if ($financialTypeId && !empty($params['financial_type_id']) && $financialTypeId != $params['financial_type_id']) {
48 CRM_Price_BAO_PriceFieldValue
::updateFinancialType($params['id'], 'civicrm_contribution_page', $params['financial_type_id']);
50 CRM_Utils_Hook
::post($hook, 'ContributionPage', $dao->id
, $dao);
51 CRM_Core_PseudoConstant
::flush();
56 * Update the is_active flag in the db.
58 * @deprecated - this bypasses hooks.
61 * Id of the database record.
62 * @param bool $is_active
63 * Value we want to set the is_active field.
66 * true if we found and updated the object, else false
68 public static function setIsActive($id, $is_active) {
69 return CRM_Core_DAO
::setFieldValue('CRM_Contribute_DAO_ContributionPage', $id, 'is_active', $is_active);
73 * Load values for a contribution page.
76 * @param array $values
78 public static function setValues($id, &$values) {
79 $modules = ['CiviContribute', 'soft_credit', 'on_behalf'];
80 $values['custom_pre_id'] = $values['custom_post_id'] = NULL;
82 $params = ['id' => $id];
83 CRM_Core_DAO
::commonRetrieve('CRM_Contribute_DAO_ContributionPage', $params, $values);
85 // get the profile ids
87 'entity_table' => 'civicrm_contribution_page',
91 // retrieve profile id as also unserialize module_data corresponding to each $module
92 foreach ($modules as $module) {
93 $ufJoinParams['module'] = $module;
94 $ufJoin = new CRM_Core_DAO_UFJoin();
95 $ufJoin->copyValues($ufJoinParams);
96 if ($module == 'CiviContribute') {
97 $ufJoin->orderBy('weight asc');
99 while ($ufJoin->fetch()) {
100 if ($ufJoin->weight
== 1) {
101 $values['custom_pre_id'] = $ufJoin->uf_group_id
;
104 $values['custom_post_id'] = $ufJoin->uf_group_id
;
110 if (!$ufJoin->is_active
) {
113 $params = CRM_Contribute_BAO_ContributionPage
::formatModuleData($ufJoin->module_data
, TRUE, $module);
114 $values = array_merge($params, $values);
115 if ($module == 'soft_credit') {
116 $values['honoree_profile_id'] = $ufJoin->uf_group_id
;
117 $values['honor_block_is_active'] = $ufJoin->is_active
;
120 $values['onbehalf_profile_id'] = $ufJoin->uf_group_id
;
129 * @param int $contactID
131 * @param array $values
132 * Associated array of fields.
133 * @param bool $isTest
135 * @param bool $returnMessageText
136 * Return the message text instead of sending the mail.
138 * @param array $fieldTypes
140 * @throws \CRM_Core_Exception
142 public static function sendMail($contactID, $values, $isTest = FALSE, $returnMessageText = FALSE, $fieldTypes = NULL) {
144 $params = ['custom_pre_id' => [], 'custom_post_id' => []];
147 // We are trying to fight the good fight against leaky variables (CRM-17519) so let's get really explicit
148 // about ensuring the variables we want for the template are defined.
149 // @todo add to this until all tpl params are explicit in this function and not waltzing around the codebase.
150 // Next stage is to remove this & ensure there are no e-notices - ie. all are set before they hit this fn.
151 $valuesRequiredForTemplate = [
154 'customPre_grouptitle',
155 'customPost_grouptitle',
163 foreach ($valuesRequiredForTemplate as $valueRequiredForTemplate) {
164 if (!isset($values[$valueRequiredForTemplate])) {
165 $values[$valueRequiredForTemplate] = NULL;
169 if (isset($values['custom_pre_id'])) {
170 $preProfileType = CRM_Core_BAO_UFField
::getProfileType($values['custom_pre_id']);
171 if ($preProfileType == 'Membership' && !empty($values['membership_id'])) {
172 $params['custom_pre_id'] = [
176 $values['membership_id'],
182 elseif ($preProfileType == 'Contribution' && !empty($values['contribution_id'])) {
183 $params['custom_pre_id'] = [
187 $values['contribution_id'],
194 $gIds['custom_pre_id'] = $values['custom_pre_id'];
197 if (isset($values['custom_post_id'])) {
198 $postProfileType = CRM_Core_BAO_UFField
::getProfileType($values['custom_post_id']);
199 if ($postProfileType == 'Membership' && !empty($values['membership_id'])) {
200 $params['custom_post_id'] = [
204 $values['membership_id'],
210 elseif ($postProfileType == 'Contribution' && !empty($values['contribution_id'])) {
211 $params['custom_post_id'] = [
215 $values['contribution_id'],
222 $gIds['custom_post_id'] = $values['custom_post_id'];
225 if (!empty($values['is_for_organization'])) {
226 if (!empty($values['membership_id'])) {
227 $params['onbehalf_profile'] = [
231 $values['membership_id'],
237 elseif (!empty($values['contribution_id'])) {
238 $params['onbehalf_profile'] = [
242 $values['contribution_id'],
250 //check whether it is a test drive
251 if ($isTest && !empty($params['custom_pre_id'])) {
252 $params['custom_pre_id'][] = [
261 if ($isTest && !empty($params['custom_post_id'])) {
262 $params['custom_post_id'][] = [
271 if (!$returnMessageText && !empty($gIds)) {
272 //send notification email if field values are set (CRM-1941)
273 foreach ($gIds as $key => $gId) {
275 $email = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup', $gId, 'notify');
277 $val = CRM_Core_BAO_UFGroup
::checkFieldsEmptyValues($gId, $contactID, CRM_Utils_Array
::value($key, $params), TRUE);
278 CRM_Core_BAO_UFGroup
::commonSendMail($contactID, $val);
284 if (!empty($values['is_email_receipt']) ||
!empty($values['onbehalf_dupe_alert']) ||
287 $template = CRM_Core_Smarty
::singleton();
289 if (!array_key_exists('related_contact', $values)) {
290 [$displayName, $email] = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contactID, FALSE, CRM_Core_BAO_LocationType
::getBilling());
292 // get primary location email if no email exist( for billing location).
294 [$displayName, $email] = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contactID);
296 if (empty($displayName)) {
297 [$displayName, $email] = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contactID);
300 //for display profile need to get individual contact id,
301 //hence get it from related_contact if on behalf of org true CRM-3767
302 //CRM-5001 Contribution/Membership:: On Behalf of Organization,
303 //If profile GROUP contain the Individual type then consider the
304 //profile is of Individual ( including the custom data of membership/contribution )
305 //IF Individual type not present in profile then it is consider as Organization data.
306 $userID = $contactID;
307 if ($preID = CRM_Utils_Array
::value('custom_pre_id', $values)) {
308 if (!empty($values['related_contact'])) {
309 $preProfileTypes = CRM_Core_BAO_UFGroup
::profileGroups($preID);
310 if (in_array('Individual', $preProfileTypes) ||
in_array('Contact', $preProfileTypes)) {
311 //Take Individual contact ID
312 $userID = $values['related_contact'] ??
NULL;
315 [$values['customPre_grouptitle'], $values['customPre']] = self
::getProfileNameAndFields($preID, $userID, $params['custom_pre_id']);
317 $userID = $contactID;
318 if ($postID = CRM_Utils_Array
::value('custom_post_id', $values)) {
319 if (!empty($values['related_contact'])) {
320 $postProfileTypes = CRM_Core_BAO_UFGroup
::profileGroups($postID);
321 if (in_array('Individual', $postProfileTypes) ||
in_array('Contact', $postProfileTypes)) {
322 //Take Individual contact ID
323 $userID = $values['related_contact'] ??
NULL;
326 list($values['customPost_grouptitle'], $values['customPost']) = self
::getProfileNameAndFields($postID, $userID, $params['custom_post_id']);
328 // Assign honoree values for the receipt. But first, stop any leaks from
329 // previously assigned values.
330 $template->assign('honoreeProfile', []);
331 $template->assign('honorName', NULL);
332 if (isset($values['honor'])) {
333 $honorValues = $values['honor'];
334 $template->_values
= ['honoree_profile_id' => $values['honoree_profile_id']];
335 CRM_Contribute_BAO_ContributionSoft
::formatHonoreeProfileFields(
337 $honorValues['honor_profile_values'],
338 $honorValues['honor_id']
342 $title = $values['title'] ?? CRM_Contribute_BAO_Contribution_Utils
::getContributionPageTitle($values['contribution_page_id']);
344 // Set email variables explicitly to avoid leaky smarty variables.
345 // All of these will be assigned to the template, replacing any that might be assigned elsewhere.
348 'receiptFromEmail' => $values['receipt_from_email'] ??
NULL,
349 'contactID' => $contactID,
350 'displayName' => $displayName,
351 'contributionID' => $values['contribution_id'] ??
NULL,
352 'contributionOtherID' => $values['contribution_other_id'] ??
NULL,
354 'lineItem' => $values['lineItem'] ??
NULL,
356 'priceSetID' => $values['priceSetID'] ??
NULL,
358 'isShare' => $values['is_share'] ??
NULL,
359 'thankyou_title' => $values['thankyou_title'] ??
NULL,
360 'customPre' => $values['customPre'],
361 'customPre_grouptitle' => $values['customPre_grouptitle'],
362 'customPost' => $values['customPost'],
363 'customPost_grouptitle' => $values['customPost_grouptitle'],
364 'useForMember' => $values['useForMember'],
365 'membership_assign' => $values['membership_assign'],
366 'amount' => $values['amount'],
367 'is_pay_later' => $values['is_pay_later'],
368 'receipt_date' => !$values['receipt_date'] ?
NULL : date('YmdHis', strtotime($values['receipt_date'])),
369 'pay_later_receipt' => $values['pay_later_receipt'] ??
NULL,
370 'honor_block_is_active' => $values['honor_block_is_active'] ??
NULL,
371 'contributionStatus' => $values['contribution_status'] ??
NULL,
372 'currency' => CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_Contribution', $values['contribution_id'], 'currency') ?? CRM_Core_Config
::singleton()->defaultCurrency
,
375 if (!empty($values['financial_type_id'])) {
376 $tplParams['financialTypeId'] = $values['financial_type_id'];
377 $tplParams['financialTypeName'] = CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_FinancialType',
378 $values['financial_type_id']);
380 $tplParams['contributionTypeName'] = $tplParams['financialTypeName'];
383 if ($contributionPageId = CRM_Utils_Array
::value('id', $values)) {
384 $tplParams['contributionPageId'] = $contributionPageId;
387 // address required during receipt processing (pdf and email receipt)
388 if ($displayAddress = CRM_Utils_Array
::value('address', $values)) {
389 $tplParams['address'] = $displayAddress;
393 $originalCCReceipt = $values['cc_receipt'] ??
NULL;
395 // cc to related contacts of contributor OR the one who
396 // signs up. Is used for cases like - on behalf of
397 // contribution / signup ..etc
398 if (array_key_exists('related_contact', $values)) {
399 list($ccDisplayName, $ccEmail) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($values['related_contact']);
400 $ccMailId = "{$ccDisplayName} <{$ccEmail}>";
402 //@todo - this is the only place in this function where $values is altered - but I can't find any evidence it is used
403 $values['cc_receipt'] = !empty($values['cc_receipt']) ?
($values['cc_receipt'] . ',' . $ccMailId) : $ccMailId;
405 // reset primary-email in the template
406 $tplParams['email'] = $ccEmail;
408 $tplParams['onBehalfName'] = $displayName;
409 $tplParams['onBehalfEmail'] = $email;
411 if (!empty($values['onbehalf_profile_id'])) {
412 self
::buildCustomDisplay($values['onbehalf_profile_id'], 'onBehalfProfile', $contactID, $template, $params['onbehalf_profile'], $fieldTypes);
416 // use either the contribution or membership receipt, based on whether it’s a membership-related contrib or not
417 $sendTemplateParams = [
418 'groupName' => !empty($values['isMembership']) ?
'msg_tpl_workflow_membership' : 'msg_tpl_workflow_contribution',
419 'valueName' => !empty($values['isMembership']) ?
'membership_online_receipt' : 'contribution_online_receipt',
420 'contactId' => $contactID,
421 'tplParams' => $tplParams,
423 'PDFFilename' => 'receipt.pdf',
426 if ($returnMessageText) {
427 list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
429 'subject' => $subject,
431 'to' => $displayName,
436 if (empty($values['receipt_from_name']) && empty($values['receipt_from_name'])) {
437 list($values['receipt_from_name'], $values['receipt_from_email']) = CRM_Core_BAO_Domain
::getNameAndEmail();
440 if ($values['is_email_receipt']) {
441 $sendTemplateParams['from'] = CRM_Utils_Array
::value('receipt_from_name', $values) . ' <' . $values['receipt_from_email'] . '>';
442 $sendTemplateParams['toName'] = $displayName;
443 $sendTemplateParams['toEmail'] = $email;
444 $sendTemplateParams['cc'] = $values['cc_receipt'] ??
NULL;
445 $sendTemplateParams['bcc'] = $values['bcc_receipt'] ??
NULL;
446 //send email with pdf invoice
447 if (Civi
::settings()->get('invoice_is_email_pdf')) {
448 $sendTemplateParams['isEmailPdf'] = TRUE;
449 $sendTemplateParams['contributionId'] = $values['contribution_id'];
451 list($sent, $subject, $message) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
454 // send duplicate alert, if dupe match found during on-behalf-of processing.
455 if (!empty($values['onbehalf_dupe_alert'])) {
456 $sendTemplateParams['groupName'] = 'msg_tpl_workflow_contribution';
457 $sendTemplateParams['valueName'] = 'contribution_dupalert';
458 $sendTemplateParams['from'] = ts('Automatically Generated') . " <{$values['receipt_from_email']}>";
459 $sendTemplateParams['toName'] = $values['receipt_from_name'] ??
NULL;
460 $sendTemplateParams['toEmail'] = $values['receipt_from_email'] ??
NULL;
461 $sendTemplateParams['tplParams']['onBehalfID'] = $contactID;
462 $sendTemplateParams['tplParams']['receiptMessage'] = $message;
464 // fix cc and reset back to original, CRM-6976
465 $sendTemplateParams['cc'] = $originalCCReceipt;
467 CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
473 * Get the profile title and fields.
477 * @param array $params
478 * @param array $fieldTypes
482 * @throws \CRM_Core_Exception
484 protected static function getProfileNameAndFields($gid, $cid, $params, $fieldTypes = []) {
488 if (CRM_Core_BAO_UFGroup
::filterUFGroups($gid, $cid)) {
489 $fields = CRM_Core_BAO_UFGroup
::getFields($gid, FALSE, CRM_Core_Action
::VIEW
, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission
::CREATE
, NULL);
490 foreach ($fields as $k => $v) {
492 $groupTitle = $v['groupDisplayTitle'];
494 // suppress all file fields from display and formatting fields
496 $v['data_type'] === 'File' ||
$v['name'] === 'image_URL' ||
$v['field_type'] === 'Formatting') {
500 if (!empty($fieldTypes) && (!in_array($v['field_type'], $fieldTypes))) {
505 CRM_Core_BAO_UFGroup
::getValues($cid, $fields, $values, FALSE, $params);
508 return [$groupTitle, $values];
512 * Send the emails for Recurring Contribution Notification.
514 * @param int $contributionID
515 * @param string $type
517 * Contribution page id.
518 * @param object $recur
520 * @throws \API_Exception
522 public static function recurringNotify($contributionID, $type, $recur): void
{
523 $contribution = Contribution
::get(FALSE)
524 ->addWhere('id', '=', $contributionID)
526 'contribution_page_id',
528 'contribution_recur_id',
529 'contribution_recur_id.is_email_receipt',
530 'contribution_page_id.title',
531 'contribution_page_id.is_email_receipt',
532 'contribution_page_id.receipt_from_name',
533 'contribution_page_id.receipt_from_email',
534 'contribution_page_id.cc_receipt',
535 'contribution_page_id.bcc_receipt',
537 ->execute()->first();
539 $isMembership = !empty(LineItem
::get(FALSE)
540 ->addWhere('contribution_id', '=', $contributionID)
541 ->addWhere('entity_table', '=', 'civicrm_membership')
542 ->addSelect('id')->execute()->first());
544 if ($contribution['contribution_recur_id.is_email_receipt'] ||
$contribution['contribution_page_id.is_email_receipt']) {
545 if ($contribution['contribution_page_id.receipt_from_email']) {
546 $receiptFromName = $contribution['contribution_page_id.receipt_from_name'];
547 $receiptFromEmail = $contribution['contribution_page_id.receipt_from_email'];
550 [$receiptFromName, $receiptFromEmail] = CRM_Core_BAO_Domain
::getNameAndEmail();
553 $receiptFrom = "$receiptFromName <$receiptFromEmail>";
554 [$displayName, $email] = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contribution['contact_id'], FALSE);
556 'groupName' => 'msg_tpl_workflow_contribution',
557 'valueName' => 'contribution_recurring_notify',
558 'contactId' => $contribution['contact_id'],
560 'recur_frequency_interval' => $recur->frequency_interval
,
561 'recur_frequency_unit' => $recur->frequency_unit
,
562 'recur_installments' => $recur->installments
,
563 'recur_start_date' => $recur->start_date
,
564 'recur_end_date' => $recur->end_date
,
565 'recur_amount' => $recur->amount
,
566 'recur_txnType' => $type,
567 'displayName' => $displayName,
568 'receipt_from_name' => $receiptFromName,
569 'receipt_from_email' => $receiptFromEmail,
570 'auto_renew_membership' => $isMembership,
572 'from' => $receiptFrom,
573 'toName' => $displayName,
577 $templatesParams['cc'] = $contribution['contribution_page_id.cc_receipt'];
578 $templatesParams['bcc'] = $contribution['contribution_page_id.cc_receipt'];
580 // in some cases its just recurringNotify() thats called for the first time and these urls don't get set.
581 // like in PaypalPro, & therefore we set it here additionally.
582 $template = CRM_Core_Smarty
::singleton();
583 $paymentProcessor = CRM_Financial_BAO_PaymentProcessor
::getProcessorForEntity($recur->id
, 'recur', 'obj');
584 $url = $paymentProcessor->subscriptionURL($recur->id
, 'recur', 'cancel');
585 $template->assign('cancelSubscriptionUrl', $url);
587 $url = $paymentProcessor->subscriptionURL($recur->id
, 'recur', 'billing');
588 $template->assign('updateSubscriptionBillingUrl', $url);
590 $url = $paymentProcessor->subscriptionURL($recur->id
, 'recur', 'update');
591 $template->assign('updateSubscriptionUrl', $url);
594 list($sent) = CRM_Core_BAO_MessageTemplate
::sendTemplate($templatesParams);
597 CRM_Core_Error
::debug_log_message('Success: mail sent for recurring notification.');
600 CRM_Core_Error
::debug_log_message('Failure: mail not sent for recurring notification.');
606 * Add the custom fields for contribution page (ie profile).
608 * @deprecated assigning values to smarty like this is risky because
609 * - it is hard to debug since $name is used in the assign
610 * - it is potentially 'leaky' - it's better to do this on the form
611 * or close to where it is used / required. See CRM-17519 for leakage e.g.
615 * @param string $name
619 * @param array $params
620 * Params to build component whereclause.
622 * @param array|null $fieldTypes
624 public static function buildCustomDisplay($gid, $name, $cid, &$template, &$params, $fieldTypes = NULL) {
625 list($groupTitle, $values) = self
::getProfileNameAndFields($gid, $cid, $params, $fieldTypes);
626 if (!empty($values)) {
627 $template->assign($name, $values);
629 $template->assign($name . "_grouptitle", $groupTitle);
633 * Make a copy of a contribution page, including all the blocks in the page.
636 * The contribution page id to copy.
638 * @return CRM_Contribute_DAO_ContributionPage
640 public static function copy($id) {
641 $session = CRM_Core_Session
::singleton();
645 'title' => ts('Copy of') . ' ',
648 'created_id' => $session->get('userID'),
649 'created_date' => date('YmdHis'),
652 $copy = CRM_Core_DAO
::copyGeneric('CRM_Contribute_DAO_ContributionPage', [
654 ], NULL, $fieldsFix);
656 //copying all the blocks pertaining to the contribution page
657 $copyPledgeBlock = CRM_Core_DAO
::copyGeneric('CRM_Pledge_DAO_PledgeBlock', [
659 'entity_table' => 'civicrm_contribution_page',
661 'entity_id' => $copy->id
,
664 $copyMembershipBlock = CRM_Core_DAO
::copyGeneric('CRM_Member_DAO_MembershipBlock', [
666 'entity_table' => 'civicrm_contribution_page',
668 'entity_id' => $copy->id
,
671 $copyUFJoin = CRM_Core_DAO
::copyGeneric('CRM_Core_DAO_UFJoin', [
673 'entity_table' => 'civicrm_contribution_page',
675 'entity_id' => $copy->id
,
678 $copyWidget = CRM_Core_DAO
::copyGeneric('CRM_Contribute_DAO_Widget', [
679 'contribution_page_id' => $id,
681 'contribution_page_id' => $copy->id
,
685 CRM_Price_BAO_PriceSet
::copyPriceSet('civicrm_contribution_page', $id, $copy->id
);
687 $copyTellFriend = CRM_Core_DAO
::copyGeneric('CRM_Friend_DAO_Friend', [
689 'entity_table' => 'civicrm_contribution_page',
691 'entity_id' => $copy->id
,
694 $copyPersonalCampaignPages = CRM_Core_DAO
::copyGeneric('CRM_PCP_DAO_PCPBlock', [
696 'entity_table' => 'civicrm_contribution_page',
698 'entity_id' => $copy->id
,
699 'target_entity_id' => $copy->id
,
702 $copyPremium = CRM_Core_DAO
::copyGeneric('CRM_Contribute_DAO_Premium', [
704 'entity_table' => 'civicrm_contribution_page',
706 'entity_id' => $copy->id
,
710 FROM civicrm_premiums
711 WHERE entity_table = 'civicrm_contribution_page'
712 AND entity_id ={$id}";
714 $premiumDao = CRM_Core_DAO
::executeQuery($premiumQuery);
715 while ($premiumDao->fetch()) {
716 if ($premiumDao->id
) {
717 CRM_Core_DAO
::copyGeneric('CRM_Contribute_DAO_PremiumsProduct', [
718 'premiums_id' => $premiumDao->id
,
720 'premiums_id' => $copyPremium->id
,
727 CRM_Utils_Hook
::copy('ContributionPage', $copy);
733 * Get info for all sections enable/disable.
735 * @param array $contribPageIds
737 * info regarding all sections.
739 public static function getSectionInfo($contribPageIds = []) {
742 if (is_array($contribPageIds) && !empty($contribPageIds)) {
743 $whereClause = 'WHERE civicrm_contribution_page.id IN ( ' . implode(', ', $contribPageIds) . ' )';
758 SELECT civicrm_contribution_page.id as id,
759 civicrm_contribution_page.financial_type_id as settings,
760 amount_block_is_active as amount,
761 civicrm_membership_block.id as membership,
762 civicrm_uf_join.id as custom,
763 civicrm_contribution_page.thankyou_title as thankyou,
764 civicrm_tell_friend.id as friend,
765 civicrm_pcp_block.id as pcp,
766 civicrm_contribution_widget.id as widget,
767 civicrm_premiums.id as premium
768 FROM civicrm_contribution_page
769 LEFT JOIN civicrm_membership_block ON ( civicrm_membership_block.entity_id = civicrm_contribution_page.id
770 AND civicrm_membership_block.entity_table = 'civicrm_contribution_page'
771 AND civicrm_membership_block.is_active = 1 )
772 LEFT JOIN civicrm_uf_join ON ( civicrm_uf_join.entity_id = civicrm_contribution_page.id
773 AND civicrm_uf_join.entity_table = 'civicrm_contribution_page'
774 AND module = 'CiviContribute'
775 AND civicrm_uf_join.is_active = 1 )
776 LEFT JOIN civicrm_tell_friend ON ( civicrm_tell_friend.entity_id = civicrm_contribution_page.id
777 AND civicrm_tell_friend.entity_table = 'civicrm_contribution_page'
778 AND civicrm_tell_friend.is_active = 1)
779 LEFT JOIN civicrm_pcp_block ON ( civicrm_pcp_block.entity_id = civicrm_contribution_page.id
780 AND civicrm_pcp_block.entity_table = 'civicrm_contribution_page'
781 AND civicrm_pcp_block.is_active = 1 )
782 LEFT JOIN civicrm_contribution_widget ON ( civicrm_contribution_widget.contribution_page_id = civicrm_contribution_page.id
783 AND civicrm_contribution_widget.is_active = 1 )
784 LEFT JOIN civicrm_premiums ON ( civicrm_premiums.entity_id = civicrm_contribution_page.id
785 AND civicrm_premiums.entity_table = 'civicrm_contribution_page'
786 AND civicrm_premiums.premiums_active = 1 )
789 $contributionPage = CRM_Core_DAO
::executeQuery($query);
790 while ($contributionPage->fetch()) {
791 if (!isset($info[$contributionPage->id
]) ||
!is_array($info[$contributionPage->id
])) {
792 $info[$contributionPage->id
] = array_fill_keys(array_values($sections), FALSE);
794 foreach ($sections as $section) {
795 if ($contributionPage->$section) {
796 $info[$contributionPage->id
][$section] = TRUE;
805 * Get options for a given field.
806 * @see CRM_Core_DAO::buildOptions
808 * @param string $fieldName
809 * @param string $context : @see CRM_Core_DAO::buildOptionsContext
810 * @param array $props : whatever is known about this dao object
814 public static function buildOptions($fieldName, $context = NULL, $props = []) {
816 // Special logic for fields whose options depend on context or properties
817 switch ($fieldName) {
818 case 'financial_type_id':
819 // https://lab.civicrm.org/dev/core/issues/547 if CiviContribute not enabled this causes an invalid query
820 // @todo - the component is enabled check should be done within getIncomeFinancialType
821 // It looks to me like test cover was NOT added to cover the change
822 // that added this so we need to assume there is no test cover
823 if (CRM_Core_Component
::isEnabled('CiviContribute')) {
824 // if check_permission has been passed in (not Null) then restrict.
825 return CRM_Financial_BAO_FinancialType
::getIncomeFinancialType($props['check_permissions'] ??
TRUE);
829 return CRM_Core_PseudoConstant
::get(__CLASS__
, $fieldName, $params, $context);
833 * Get or Set honor/on_behalf params for processing module_data or setting default values.
835 * @param array $params :
836 * @param bool $setDefault : If yes then returns array to used for setting default value afterward
837 * @param string $module : processing module_data for which module? e.g. soft_credit, on_behalf
839 * @return array|string
841 public static function formatModuleData($params, $setDefault, $module) {
842 $tsLocale = CRM_Core_I18n
::getLocale();
843 $config = CRM_Core_Config
::singleton();
844 $json = $jsonDecode = NULL;
845 $multilingual = CRM_Core_I18n
::isMultilingual();
847 $moduleDataFormat = [
849 1 => 'soft_credit_types',
856 1 => 'is_for_organization',
863 //When we are fetching the honor params respecting both multi and mono lingual state
864 //and setting it to default param of Contribution Page's Main and Setting form
866 $jsonDecode = json_decode($params);
867 $jsonDecode = (array) $jsonDecode->$module;
868 if ($multilingual && !empty($jsonDecode[$tsLocale])) {
870 foreach ($jsonDecode[$tsLocale] as $column => $value) {
871 $jsonDecode[$column] = $value;
873 unset($jsonDecode[$tsLocale]);
875 elseif (!empty($jsonDecode['default'])) {
876 //monolingual state, or an undefined value in multilingual
877 $jsonDecode +
= (array) $jsonDecode['default'];
878 unset($jsonDecode['default']);
883 //check and handle multilingual honoree params
884 if (!$multilingual) {
885 //if in singlelingual state simply return the array format
886 $json = [$module => NULL];
887 foreach ($moduleDataFormat[$module] as $key => $attribute) {
888 if ($key === 'multilingual') {
889 $json[$module]['default'] = [];
890 foreach ($attribute as $attr) {
891 $json[$module]['default'][$attr] = $params[$attr];
895 $json[$module][$attribute] = $params[$attribute];
898 $json = json_encode($json);
901 //if in multilingual state then retrieve the module_data against this contribution and
902 //merge with earlier module_data json data to current so not to lose earlier multilingual module_data information
903 $json = [$module => NULL];
904 foreach ($moduleDataFormat[$module] as $key => $attribute) {
905 if ($key === 'multilingual') {
906 $json[$module][$tsLocale] = [];
907 foreach ($attribute as $attr) {
908 $json[$module][$tsLocale][$attr] = $params[$attr];
912 $json[$module][$attribute] = $params[$attribute];
916 $ufJoinDAO = new CRM_Core_DAO_UFJoin();
917 $ufJoinDAO->module
= $module;
918 $ufJoinDAO->entity_id
= $params['id'];
919 $ufJoinDAO->find(TRUE);
920 $jsonData = json_decode($ufJoinDAO->module_data
);
922 $json[$module] = array_merge((array) $jsonData->$module, $json[$module]);
924 $json = json_encode($json);
930 * Generate html for pdf in confirmation receipt email attachment.
931 * @param int $contributionId
932 * Contribution Page Id.
934 * Contact id for contributor.
937 public static function addInvoicePdfToEmail($contributionId, $userID) {
938 $contributionID = [$contributionId];
939 $contactId = [$userID];
941 'output' => 'pdf_invoice',
942 'forPage' => 'confirmpage',
944 $pdfHtml = CRM_Contribute_Form_Task_Invoice
::printPDF($contributionID, $pdfParams, $contactId);
949 * Helper to determine if the page supports separate membership payments.
951 * @param int $id form id
954 * isSeparateMembershipPayment
956 public static function getIsMembershipPayment($id) {
957 $membershipBlocks = civicrm_api3('membership_block', 'get', [
958 'entity_table' => 'civicrm_contribution_page',
960 'sequential' => TRUE,
962 if (!$membershipBlocks['count']) {
965 return $membershipBlocks['values'][0]['is_separate_payment'];