3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2015
35 * This class contains Contribution Page related functions.
37 class CRM_Contribute_BAO_ContributionPage
extends CRM_Contribute_DAO_ContributionPage
{
40 * Creates a contribution page.
42 * @param array $params
44 * @return CRM_Contribute_DAO_ContributionPage
46 public static function create($params) {
47 $financialTypeId = NULL;
48 if (!empty($params['id']) && !CRM_Price_BAO_PriceSet
::getFor('civicrm_contribution_page', $params['id'], NULL, 1)) {
49 $financialTypeId = CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_ContributionPage', $params['id'], 'financial_type_id');
52 if (isset($params['payment_processor']) && is_array($params['payment_processor'])) {
53 $params['payment_processor'] = implode(CRM_Core_DAO
::VALUE_SEPARATOR
, $params['payment_processor']);
55 $hook = empty($params['id']) ?
'create' : 'edit';
56 CRM_Utils_Hook
::pre($hook, 'ContributionPage', CRM_Utils_Array
::value('id', $params), $params);
57 $dao = new CRM_Contribute_DAO_ContributionPage();
58 $dao->copyValues($params);
60 if ($financialTypeId && !empty($params['financial_type_id']) && $financialTypeId != $params['financial_type_id']) {
61 CRM_Price_BAO_PriceFieldValue
::updateFinancialType($params['id'], 'civicrm_contribution_page', $params['financial_type_id']);
63 CRM_Utils_Hook
::post($hook, 'ContributionPage', $dao->id
, $dao);
68 * Update the is_active flag in the db.
70 * @deprecated - this bypasses hooks.
73 * Id of the database record.
74 * @param bool $is_active
75 * Value we want to set the is_active field.
78 * DAO object on success, null otherwise
80 public static function setIsActive($id, $is_active) {
81 return CRM_Core_DAO
::setFieldValue('CRM_Contribute_DAO_ContributionPage', $id, 'is_active', $is_active);
85 * Load values for a contribution page.
88 * @param array $values
90 public static function setValues($id, &$values) {
95 CRM_Core_DAO
::commonRetrieve('CRM_Contribute_DAO_ContributionPage', $params, $values);
97 // get the profile ids
98 $ufJoinParams = array(
99 'module' => 'CiviContribute',
100 'entity_table' => 'civicrm_contribution_page',
103 list($values['custom_pre_id'], $customPostIds) = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
105 if (!empty($customPostIds)) {
106 $values['custom_post_id'] = $customPostIds[0];
109 $values['custom_post_id'] = '';
116 * @param int $contactID
118 * @param array $values
119 * Associated array of fields.
120 * @param bool $isTest
122 * @param bool $returnMessageText
123 * Return the message text instead of sending the mail.
125 * @param array $fieldTypes
127 public static function sendMail($contactID, $values, $isTest = FALSE, $returnMessageText = FALSE, $fieldTypes = NULL) {
128 $gIds = $params = array();
130 if (isset($values['custom_pre_id'])) {
131 $preProfileType = CRM_Core_BAO_UFField
::getProfileType($values['custom_pre_id']);
132 if ($preProfileType == 'Membership' && !empty($values['membership_id'])) {
133 $params['custom_pre_id'] = array(
137 $values['membership_id'],
143 elseif ($preProfileType == 'Contribution' && !empty($values['contribution_id'])) {
144 $params['custom_pre_id'] = array(
148 $values['contribution_id'],
155 $gIds['custom_pre_id'] = $values['custom_pre_id'];
158 if (isset($values['custom_post_id'])) {
159 $postProfileType = CRM_Core_BAO_UFField
::getProfileType($values['custom_post_id']);
160 if ($postProfileType == 'Membership' && !empty($values['membership_id'])) {
161 $params['custom_post_id'] = array(
165 $values['membership_id'],
171 elseif ($postProfileType == 'Contribution' && !empty($values['contribution_id'])) {
172 $params['custom_post_id'] = array(
176 $values['contribution_id'],
183 $gIds['custom_post_id'] = $values['custom_post_id'];
186 if (!empty($values['is_for_organization'])) {
187 if (!empty($values['membership_id'])) {
188 $params['onbehalf_profile'] = array(
192 $values['membership_id'],
198 elseif (!empty($values['contribution_id'])) {
199 $params['onbehalf_profile'] = array(
203 $values['contribution_id'],
211 //check whether it is a test drive
212 if ($isTest && !empty($params['custom_pre_id'])) {
213 $params['custom_pre_id'][] = array(
222 if ($isTest && !empty($params['custom_post_id'])) {
223 $params['custom_post_id'][] = array(
232 if (!$returnMessageText && !empty($gIds)) {
233 //send notification email if field values are set (CRM-1941)
234 foreach ($gIds as $key => $gId) {
236 $email = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup', $gId, 'notify');
238 $val = CRM_Core_BAO_UFGroup
::checkFieldsEmptyValues($gId, $contactID, CRM_Utils_Array
::value($key, $params), TRUE);
239 CRM_Core_BAO_UFGroup
::commonSendMail($contactID, $val);
245 if (!empty($values['is_email_receipt']) ||
!empty($values['onbehalf_dupe_alert']) ||
248 $template = CRM_Core_Smarty
::singleton();
250 // get the billing location type
251 if (!array_key_exists('related_contact', $values)) {
252 $locationTypes = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
253 $billingLocationTypeId = array_search('Billing', $locationTypes);
256 // presence of related contact implies onbehalf of org case,
257 // where location type is set to default.
258 $locType = CRM_Core_BAO_LocationType
::getDefault();
259 $billingLocationTypeId = $locType->id
;
262 if (!array_key_exists('related_contact', $values)) {
263 list($displayName, $email) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contactID, FALSE, $billingLocationTypeId);
265 // get primary location email if no email exist( for billing location).
267 list($displayName, $email) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contactID);
269 if (empty($displayName)) {
270 list($displayName, $email) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contactID);
273 //for display profile need to get individual contact id,
274 //hence get it from related_contact if on behalf of org true CRM-3767
275 //CRM-5001 Contribution/Membership:: On Behalf of Organization,
276 //If profile GROUP contain the Individual type then consider the
277 //profile is of Individual ( including the custom data of membership/contribution )
278 //IF Individual type not present in profile then it is consider as Organization data.
279 $userID = $contactID;
280 if ($preID = CRM_Utils_Array
::value('custom_pre_id', $values)) {
281 if (!empty($values['related_contact'])) {
282 $preProfileTypes = CRM_Core_BAO_UFGroup
::profileGroups($preID);
283 //@todo - following line should not refer to undefined $postProfileTypes? figure out way to test
284 if (in_array('Individual', $preProfileTypes) ||
in_array('Contact', $postProfileTypes)) {
285 //Take Individual contact ID
286 $userID = CRM_Utils_Array
::value('related_contact', $values);
289 self
::buildCustomDisplay($preID, 'customPre', $userID, $template, $params['custom_pre_id']);
291 $userID = $contactID;
292 if ($postID = CRM_Utils_Array
::value('custom_post_id', $values)) {
293 if (!empty($values['related_contact'])) {
294 $postProfileTypes = CRM_Core_BAO_UFGroup
::profileGroups($postID);
295 if (in_array('Individual', $postProfileTypes) ||
in_array('Contact', $postProfileTypes)) {
296 //Take Individual contact ID
297 $userID = CRM_Utils_Array
::value('related_contact', $values);
300 self
::buildCustomDisplay($postID, 'customPost', $userID, $template, $params['custom_post_id']);
302 if (isset($values['honor'])) {
303 $honorValues = $values['honor'];
304 CRM_Contribute_BAO_ContributionSoft
::formatHonoreeProfileFields(
306 $honorValues['honor_profile_values'],
307 $honorValues['honor_profile_id'],
308 $honorValues['honor_id']
312 $title = isset($values['title']) ?
$values['title'] : CRM_Contribute_PseudoConstant
::contributionPage($values['contribution_page_id']);
314 // set email in the template here
317 'receiptFromEmail' => CRM_Utils_Array
::value('receipt_from_email', $values),
318 'contactID' => $contactID,
319 'displayName' => $displayName,
320 'contributionID' => CRM_Utils_Array
::value('contribution_id', $values),
321 'contributionOtherID' => CRM_Utils_Array
::value('contribution_other_id', $values),
323 'lineItem' => CRM_Utils_Array
::value('lineItem', $values),
325 'priceSetID' => CRM_Utils_Array
::value('priceSetID', $values),
327 'isShare' => CRM_Utils_Array
::value('is_share', $values),
328 'thankyou_title' => CRM_Utils_Array
::value('thankyou_title', $values),
331 if ($contributionTypeId = CRM_Utils_Array
::value('financial_type_id', $values)) {
332 $tplParams['contributionTypeId'] = $contributionTypeId;
333 $tplParams['contributionTypeName'] = CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_FinancialType',
334 $contributionTypeId);
337 if ($contributionPageId = CRM_Utils_Array
::value('id', $values)) {
338 $tplParams['contributionPageId'] = $contributionPageId;
341 // address required during receipt processing (pdf and email receipt)
342 if ($displayAddress = CRM_Utils_Array
::value('address', $values)) {
343 $tplParams['address'] = $displayAddress;
347 $originalCCReceipt = CRM_Utils_Array
::value('cc_receipt', $values);
349 // cc to related contacts of contributor OR the one who
350 // signs up. Is used for cases like - on behalf of
351 // contribution / signup ..etc
352 if (array_key_exists('related_contact', $values)) {
353 list($ccDisplayName, $ccEmail) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($values['related_contact']);
354 $ccMailId = "{$ccDisplayName} <{$ccEmail}>";
356 //@todo - this is the only place in this function where $values is altered - but I can't find any evidence it is used
357 $values['cc_receipt'] = !empty($values['cc_receipt']) ?
($values['cc_receipt'] . ',' . $ccMailId) : $ccMailId;
359 // reset primary-email in the template
360 $tplParams['email'] = $ccEmail;
362 $tplParams['onBehalfName'] = $displayName;
363 $tplParams['onBehalfEmail'] = $email;
365 $ufJoinParams = array(
366 'module' => 'onBehalf',
367 'entity_table' => 'civicrm_contribution_page',
368 'entity_id' => $values['id'],
370 $OnBehalfProfile = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
371 $profileId = $OnBehalfProfile[0];
372 $userID = $contactID;
373 self
::buildCustomDisplay($profileId, 'onBehalfProfile', $userID, $template, $params['onbehalf_profile'], $fieldTypes);
376 // use either the contribution or membership receipt, based on whether it’s a membership-related contrib or not
377 $sendTemplateParams = array(
378 'groupName' => !empty($values['isMembership']) ?
'msg_tpl_workflow_membership' : 'msg_tpl_workflow_contribution',
379 'valueName' => !empty($values['isMembership']) ?
'membership_online_receipt' : 'contribution_online_receipt',
380 'contactId' => $contactID,
381 'tplParams' => $tplParams,
383 'PDFFilename' => 'receipt.pdf',
386 if ($returnMessageText) {
387 list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
389 'subject' => $subject,
391 'to' => $displayName,
396 if ($values['is_email_receipt']) {
397 $sendTemplateParams['from'] = CRM_Utils_Array
::value('receipt_from_name', $values) . ' <' . $values['receipt_from_email'] . '>';
398 $sendTemplateParams['toName'] = $displayName;
399 $sendTemplateParams['toEmail'] = $email;
400 $sendTemplateParams['cc'] = CRM_Utils_Array
::value('cc_receipt', $values);
401 $sendTemplateParams['bcc'] = CRM_Utils_Array
::value('bcc_receipt', $values);
402 //send email with pdf invoice
403 $template = CRM_Core_Smarty
::singleton();
404 $taxAmt = $template->get_template_vars('dataArray');
405 $prefixValue = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
, 'contribution_invoice_settings');
406 $invoicing = CRM_Utils_Array
::value('invoicing', $prefixValue);
407 if (isset($invoicing) && isset($prefixValue['is_email_pdf'])) {
408 $sendTemplateParams['isEmailPdf'] = TRUE;
409 $sendTemplateParams['contributionId'] = $values['contribution_id'];
411 list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
414 // send duplicate alert, if dupe match found during on-behalf-of processing.
415 if (!empty($values['onbehalf_dupe_alert'])) {
416 $sendTemplateParams['groupName'] = 'msg_tpl_workflow_contribution';
417 $sendTemplateParams['valueName'] = 'contribution_dupalert';
418 $sendTemplateParams['from'] = ts('Automatically Generated') . " <{$values['receipt_from_email']}>";
419 $sendTemplateParams['toName'] = CRM_Utils_Array
::value('receipt_from_name', $values);
420 $sendTemplateParams['toEmail'] = CRM_Utils_Array
::value('receipt_from_email', $values);
421 $sendTemplateParams['tplParams']['onBehalfID'] = $contactID;
422 $sendTemplateParams['tplParams']['receiptMessage'] = $message;
424 // fix cc and reset back to original, CRM-6976
425 $sendTemplateParams['cc'] = $originalCCReceipt;
427 CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
433 * Send the emails for Recurring Contribution Notification.
435 * @param string $type
437 * @param int $contactID
438 * Contact id for contributor.
440 * Contribution page id.
441 * @param object $recur
442 * Object of recurring contribution table.
443 * @param bool|object $autoRenewMembership is it a auto renew membership.
445 public static function recurringNotify($type, $contactID, $pageID, $recur, $autoRenewMembership = FALSE) {
447 $isEmailReceipt = FALSE;
449 CRM_Core_DAO
::commonRetrieveAll('CRM_Contribute_DAO_ContributionPage', 'id', $pageID, $value, array(
453 'receipt_from_email',
457 $isEmailReceipt = CRM_Utils_Array
::value('is_email_receipt', $value[$pageID]);
459 elseif ($recur->id
) {
460 // This means we are coming from back-office - ie. no page ID, but recurring.
461 // Ideally this information would be passed into the function clearly rather than guessing by convention.
462 $isEmailReceipt = TRUE;
465 if ($isEmailReceipt) {
467 $receiptFrom = '"' . CRM_Utils_Array
::value('receipt_from_name', $value[$pageID]) . '" <' . $value[$pageID]['receipt_from_email'] . '>';
469 $receiptFromName = $value[$pageID]['receipt_from_name'];
470 $receiptFromEmail = $value[$pageID]['receipt_from_email'];
473 $domainValues = CRM_Core_BAO_Domain
::getNameAndEmail();
474 $receiptFrom = "$domainValues[0] <$domainValues[1]>";
475 $receiptFromName = $domainValues[0];
476 $receiptFromEmail = $domainValues[1];
479 list($displayName, $email) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contactID, FALSE);
480 $templatesParams = array(
481 'groupName' => 'msg_tpl_workflow_contribution',
482 'valueName' => 'contribution_recurring_notify',
483 'contactId' => $contactID,
484 'tplParams' => array(
485 'recur_frequency_interval' => $recur->frequency_interval
,
486 'recur_frequency_unit' => $recur->frequency_unit
,
487 'recur_installments' => $recur->installments
,
488 'recur_start_date' => $recur->start_date
,
489 'recur_end_date' => $recur->end_date
,
490 'recur_amount' => $recur->amount
,
491 'recur_txnType' => $type,
492 'displayName' => $displayName,
493 'receipt_from_name' => $receiptFromName,
494 'receipt_from_email' => $receiptFromEmail,
495 'auto_renew_membership' => $autoRenewMembership,
497 'from' => $receiptFrom,
498 'toName' => $displayName,
503 $templatesParams['cc'] = CRM_Utils_Array
::value('cc_receipt', $value[$pageID]);
504 $templatesParams['bcc'] = CRM_Utils_Array
::value('bcc_receipt', $value[$pageID]);
507 // in some cases its just recurringNotify() thats called for the first time and these urls don't get set.
508 // like in PaypalPro, & therefore we set it here additionally.
509 $template = CRM_Core_Smarty
::singleton();
510 $paymentProcessor = CRM_Financial_BAO_PaymentProcessor
::getProcessorForEntity($recur->id
, 'recur', 'obj');
511 $url = $paymentProcessor->subscriptionURL($recur->id
, 'recur');
512 $template->assign('cancelSubscriptionUrl', $url);
514 $url = $paymentProcessor->subscriptionURL($recur->id
, 'recur', 'billing');
515 $template->assign('updateSubscriptionBillingUrl', $url);
517 $url = $paymentProcessor->subscriptionURL($recur->id
, 'recur', 'update');
518 $template->assign('updateSubscriptionUrl', $url);
521 list($sent) = CRM_Core_BAO_MessageTemplate
::sendTemplate($templatesParams);
524 CRM_Core_Error
::debug_log_message('Success: mail sent for recurring notification.');
527 CRM_Core_Error
::debug_log_message('Failure: mail not sent for recurring notification.');
533 * Add the custom fields for contribution page (ie profile)
537 * @param string $name
541 * @param array $params
542 * Params to build component whereclause.
544 * @param array $fieldTypes
546 public static function buildCustomDisplay($gid, $name, $cid, &$template, &$params, $fieldTypes = array()) {
548 if (CRM_Core_BAO_UFGroup
::filterUFGroups($gid, $cid)) {
551 $fields = CRM_Core_BAO_UFGroup
::getFields($gid, FALSE, CRM_Core_Action
::VIEW
, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission
::CREATE
, NULL);
552 foreach ($fields as $k => $v) {
554 $groupTitle = $v["groupTitle"];
556 // suppress all file fields from display and formatting fields
558 CRM_Utils_Array
::value('data_type', $v, '') == 'File' ||
559 CRM_Utils_Array
::value('name', $v, '') == 'image_URL' ||
560 CRM_Utils_Array
::value('field_type', $v) == 'Formatting'
565 if (!empty($fieldTypes) && (!in_array($v['field_type'], $fieldTypes))) {
571 $template->assign($name . "_grouptitle", $groupTitle);
574 CRM_Core_BAO_UFGroup
::getValues($cid, $fields, $values, FALSE, $params);
576 if (count($values)) {
577 $template->assign($name, $values);
584 * Make a copy of a contribution page, including all the blocks in the page.
587 * The contribution page id to copy.
589 * @return CRM_Contribute_DAO_ContributionPage
591 public static function copy($id) {
594 'title' => ts('Copy of') . ' ',
597 $copy = &CRM_Core_DAO
::copyGeneric('CRM_Contribute_DAO_ContributionPage', array(
599 ), NULL, $fieldsFix);
601 //copying all the blocks pertaining to the contribution page
602 $copyPledgeBlock = &CRM_Core_DAO
::copyGeneric('CRM_Pledge_DAO_PledgeBlock', array(
604 'entity_table' => 'civicrm_contribution_page',
606 'entity_id' => $copy->id
,
609 $copyMembershipBlock = &CRM_Core_DAO
::copyGeneric('CRM_Member_DAO_MembershipBlock', array(
611 'entity_table' => 'civicrm_contribution_page',
613 'entity_id' => $copy->id
,
616 $copyUFJoin = &CRM_Core_DAO
::copyGeneric('CRM_Core_DAO_UFJoin', array(
618 'entity_table' => 'civicrm_contribution_page',
620 'entity_id' => $copy->id
,
623 $copyWidget = &CRM_Core_DAO
::copyGeneric('CRM_Contribute_DAO_Widget', array(
624 'contribution_page_id' => $id,
626 'contribution_page_id' => $copy->id
,
630 CRM_Price_BAO_PriceSet
::copyPriceSet('civicrm_contribution_page', $id, $copy->id
);
632 $copyTellFriend = &CRM_Core_DAO
::copyGeneric('CRM_Friend_DAO_Friend', array(
634 'entity_table' => 'civicrm_contribution_page',
636 'entity_id' => $copy->id
,
639 $copyPersonalCampaignPages = &CRM_Core_DAO
::copyGeneric('CRM_PCP_DAO_PCPBlock', array(
641 'entity_table' => 'civicrm_contribution_page',
643 'entity_id' => $copy->id
,
644 'target_entity_id' => $copy->id
,
647 $copyPremium = &CRM_Core_DAO
::copyGeneric('CRM_Contribute_DAO_Premium', array(
649 'entity_table' => 'civicrm_contribution_page',
651 'entity_id' => $copy->id
,
655 FROM civicrm_premiums
656 WHERE entity_table = 'civicrm_contribution_page'
657 AND entity_id ={$id}";
659 $premiumDao = CRM_Core_DAO
::executeQuery($premiumQuery, CRM_Core_DAO
::$_nullArray);
660 while ($premiumDao->fetch()) {
661 if ($premiumDao->id
) {
662 CRM_Core_DAO
::copyGeneric('CRM_Contribute_DAO_PremiumsProduct', array(
663 'premiums_id' => $premiumDao->id
,
665 'premiums_id' => $copyPremium->id
,
672 CRM_Utils_Hook
::copy('ContributionPage', $copy);
678 * Get info for all sections enable/disable.
680 * @param array $contribPageIds
682 * info regarding all sections.
684 public static function getSectionInfo($contribPageIds = array()) {
687 if (is_array($contribPageIds) && !empty($contribPageIds)) {
688 $whereClause = 'WHERE civicrm_contribution_page.id IN ( ' . implode(', ', $contribPageIds) . ' )';
703 SELECT civicrm_contribution_page.id as id,
704 civicrm_contribution_page.financial_type_id as settings,
705 amount_block_is_active as amount,
706 civicrm_membership_block.id as membership,
707 civicrm_uf_join.id as custom,
708 civicrm_contribution_page.thankyou_title as thankyou,
709 civicrm_tell_friend.id as friend,
710 civicrm_pcp_block.id as pcp,
711 civicrm_contribution_widget.id as widget,
712 civicrm_premiums.id as premium
713 FROM civicrm_contribution_page
714 LEFT JOIN civicrm_membership_block ON ( civicrm_membership_block.entity_id = civicrm_contribution_page.id
715 AND civicrm_membership_block.entity_table = 'civicrm_contribution_page'
716 AND civicrm_membership_block.is_active = 1 )
717 LEFT JOIN civicrm_uf_join ON ( civicrm_uf_join.entity_id = civicrm_contribution_page.id
718 AND civicrm_uf_join.entity_table = 'civicrm_contribution_page'
719 AND module = 'CiviContribute'
720 AND civicrm_uf_join.is_active = 1 )
721 LEFT JOIN civicrm_tell_friend ON ( civicrm_tell_friend.entity_id = civicrm_contribution_page.id
722 AND civicrm_tell_friend.entity_table = 'civicrm_contribution_page'
723 AND civicrm_tell_friend.is_active = 1)
724 LEFT JOIN civicrm_pcp_block ON ( civicrm_pcp_block.entity_id = civicrm_contribution_page.id
725 AND civicrm_pcp_block.entity_table = 'civicrm_contribution_page'
726 AND civicrm_pcp_block.is_active = 1 )
727 LEFT JOIN civicrm_contribution_widget ON ( civicrm_contribution_widget.contribution_page_id = civicrm_contribution_page.id
728 AND civicrm_contribution_widget.is_active = 1 )
729 LEFT JOIN civicrm_premiums ON ( civicrm_premiums.entity_id = civicrm_contribution_page.id
730 AND civicrm_premiums.entity_table = 'civicrm_contribution_page'
731 AND civicrm_premiums.premiums_active = 1 )
734 $contributionPage = CRM_Core_DAO
::executeQuery($query);
735 while ($contributionPage->fetch()) {
736 if (!isset($info[$contributionPage->id
]) ||
!is_array($info[$contributionPage->id
])) {
737 $info[$contributionPage->id
] = array_fill_keys(array_values($sections), FALSE);
739 foreach ($sections as $section) {
740 if ($contributionPage->$section) {
741 $info[$contributionPage->id
][$section] = TRUE;
750 * Get options for a given field.
751 * @see CRM_Core_DAO::buildOptions
753 * @param string $fieldName
754 * @param string $context : @see CRM_Core_DAO::buildOptionsContext
755 * @param array $props : whatever is known about this dao object
759 public static function buildOptions($fieldName, $context = NULL, $props = array()) {
761 // Special logic for fields whose options depend on context or properties
762 switch ($fieldName) {
763 case 'financial_type_id':
764 // Fixme - this is going to ignore context, better to get conditions, add params, and call PseudoConstant::get
765 return CRM_Financial_BAO_FinancialType
::getIncomeFinancialType();
769 return CRM_Core_PseudoConstant
::get(__CLASS__
, $fieldName, $params, $context);
773 * Get or Set multilingually affected honor params for processing module_data or setting default values.
775 * @param string $params :
776 * @param bool $setDefault : If yes then returns array to used for setting default value afterward
778 * @return array|string
780 public static function formatMultilingualHonorParams($params, $setDefault = FALSE) {
781 $config = CRM_Core_Config
::singleton();
782 $sctJson = $sctJsonDecode = NULL;
783 $domain = new CRM_Core_DAO_Domain();
786 //When we are fetching the honor params respecting both multi and mono lingual state
787 //and setting it to default param of Contribution Page's Main and Setting form
789 $sctJsonDecode = json_decode($params);
790 $sctJsonDecode = (array) $sctJsonDecode->soft_credit
;
791 if (!$domain->locales
&& !empty($sctJsonDecode['default'])) {
793 $sctJsonDecode +
= (array) $sctJsonDecode['default'];
795 elseif (!empty($sctJsonDecode[$config->lcMessages
])) {
797 foreach ($sctJsonDecode[$config->lcMessages
] as $column => $value) {
798 $sctJsonDecode[$column] = $value;
800 unset($sctJsonDecode[$config->lcMessages
]);
802 return $sctJsonDecode;
805 //check and handle multilingual honoree params
806 if (!$domain->locales
) {
807 //if in singlelingual state simply return the array format
808 $sctJson = json_encode(
810 'soft_credit' => array(
811 'soft_credit_types' => $params['soft_credit_types'],
813 'honor_block_title' => $params['honor_block_title'],
814 'honor_block_text' => $params['honor_block_text'],
821 //if in multilingual state then retrieve the module_data against this contribution and
822 //merge with earlier module_data json data to current so not to lose earlier multilingual module_data information
824 'soft_credit' => array(
825 'soft_credit_types' => $params['soft_credit_types'],
826 $config->lcMessages
=> array(
827 'honor_block_title' => $params['honor_block_title'],
828 'honor_block_text' => $params['honor_block_text'],
833 $ufJoinDAO = new CRM_Core_DAO_UFJoin();
834 $ufJoinDAO->module
= 'soft_credit';
835 $ufJoinDAO->entity_id
= $params['id'];
836 $ufJoinDAO->find(TRUE);
837 $jsonData = json_decode($ufJoinDAO->module_data
);
839 $sctJson['soft_credit'] = array_merge((array) $jsonData->soft_credit
, $sctJson['soft_credit']);
841 $sctJson = json_encode($sctJson);
847 * Generate html for pdf in confirmation receipt email attachment.
849 * @param int $contributionId
850 * Contribution Page Id.
852 * Contact id for contributor.
855 public static function addInvoicePdfToEmail($contributionId, $userID) {
856 $contributionID = array($contributionId);
857 $contactId = array($userID);
859 'output' => 'pdf_invoice',
860 'forPage' => 'confirmpage',
862 $pdfHtml = CRM_Contribute_Form_Task_Invoice
::printPDF($contributionID,
863 $pdfParams, $contactId, CRM_Core_DAO
::$_nullObject);
868 * Helper to determine if the page supports separate membership payments.
870 * @param int $id form id
873 * isSeparateMembershipPayment
875 public static function getIsMembershipPayment($id) {
876 $membershipBlocks = civicrm_api3('membership_block', 'get', array(
877 'entity_table' => 'civicrm_contribution_page',
879 'sequential' => TRUE,
881 if (!$membershipBlocks['count']) {
884 return $membershipBlocks['values'][0]['is_separate_payment'];