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) {
91 $modules = array('CiviContribute', 'soft_credit', 'on_behalf');
92 $values['custom_pre_id'] = $values['custom_post_id'] = NULL;
94 $params = array('id' => $id);
95 CRM_Core_DAO
::commonRetrieve('CRM_Contribute_DAO_ContributionPage', $params, $values);
97 // get the profile ids
98 $ufJoinParams = array(
99 'entity_table' => 'civicrm_contribution_page',
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');
111 while ($ufJoin->fetch()) {
112 if ($ufJoin->weight
== 1) {
113 $values['custom_pre_id'] = $ufJoin->uf_group_id
;
116 $values['custom_post_id'] = $ufJoin->uf_group_id
;
122 if (!$ufJoin->is_active
) {
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
;
132 $values['onbehalf_profile_id'] = $ufJoin->uf_group_id
;
141 * @param int $contactID
143 * @param array $values
144 * Associated array of fields.
145 * @param bool $isTest
147 * @param bool $returnMessageText
148 * Return the message text instead of sending the mail.
150 * @param array $fieldTypes
152 public static function sendMail($contactID, $values, $isTest = FALSE, $returnMessageText = FALSE, $fieldTypes = NULL) {
154 $params = array('custom_pre_id' => array(), 'custom_post_id' => array());
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.
160 $valuesRequiredForTemplate = array('customPre', 'customPost', 'customPre_grouptitle', 'customPost_grouptitle',
162 foreach ($valuesRequiredForTemplate as $valueRequiredForTemplate) {
163 if (!isset($values[$valueRequiredForTemplate])) {
164 $values[$valueRequiredForTemplate] = NULL;
168 if (isset($values['custom_pre_id'])) {
169 $preProfileType = CRM_Core_BAO_UFField
::getProfileType($values['custom_pre_id']);
170 if ($preProfileType == 'Membership' && !empty($values['membership_id'])) {
171 $params['custom_pre_id'] = array(
175 $values['membership_id'],
181 elseif ($preProfileType == 'Contribution' && !empty($values['contribution_id'])) {
182 $params['custom_pre_id'] = array(
186 $values['contribution_id'],
193 $gIds['custom_pre_id'] = $values['custom_pre_id'];
196 if (isset($values['custom_post_id'])) {
197 $postProfileType = CRM_Core_BAO_UFField
::getProfileType($values['custom_post_id']);
198 if ($postProfileType == 'Membership' && !empty($values['membership_id'])) {
199 $params['custom_post_id'] = array(
203 $values['membership_id'],
209 elseif ($postProfileType == 'Contribution' && !empty($values['contribution_id'])) {
210 $params['custom_post_id'] = array(
214 $values['contribution_id'],
221 $gIds['custom_post_id'] = $values['custom_post_id'];
224 if (!empty($values['is_for_organization'])) {
225 if (!empty($values['membership_id'])) {
226 $params['onbehalf_profile'] = array(
230 $values['membership_id'],
236 elseif (!empty($values['contribution_id'])) {
237 $params['onbehalf_profile'] = array(
241 $values['contribution_id'],
249 //check whether it is a test drive
250 if ($isTest && !empty($params['custom_pre_id'])) {
251 $params['custom_pre_id'][] = array(
260 if ($isTest && !empty($params['custom_post_id'])) {
261 $params['custom_post_id'][] = array(
270 if (!$returnMessageText && !empty($gIds)) {
271 //send notification email if field values are set (CRM-1941)
272 foreach ($gIds as $key => $gId) {
274 $email = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup', $gId, 'notify');
276 $val = CRM_Core_BAO_UFGroup
::checkFieldsEmptyValues($gId, $contactID, CRM_Utils_Array
::value($key, $params), TRUE);
277 CRM_Core_BAO_UFGroup
::commonSendMail($contactID, $val);
283 if (!empty($values['is_email_receipt']) ||
!empty($values['onbehalf_dupe_alert']) ||
286 $template = CRM_Core_Smarty
::singleton();
288 // get the billing location type
289 if (!array_key_exists('related_contact', $values)) {
290 $billingLocationTypeId = CRM_Core_BAO_LocationType
::getBilling();
293 // presence of related contact implies onbehalf of org case,
294 // where location type is set to default.
295 $locType = CRM_Core_BAO_LocationType
::getDefault();
296 $billingLocationTypeId = $locType->id
;
299 if (!array_key_exists('related_contact', $values)) {
300 list($displayName, $email) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contactID, FALSE, $billingLocationTypeId);
302 // get primary location email if no email exist( for billing location).
304 list($displayName, $email) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contactID);
306 if (empty($displayName)) {
307 list($displayName, $email) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contactID);
310 //for display profile need to get individual contact id,
311 //hence get it from related_contact if on behalf of org true CRM-3767
312 //CRM-5001 Contribution/Membership:: On Behalf of Organization,
313 //If profile GROUP contain the Individual type then consider the
314 //profile is of Individual ( including the custom data of membership/contribution )
315 //IF Individual type not present in profile then it is consider as Organization data.
316 $userID = $contactID;
317 if ($preID = CRM_Utils_Array
::value('custom_pre_id', $values)) {
318 if (!empty($values['related_contact'])) {
319 $preProfileTypes = CRM_Core_BAO_UFGroup
::profileGroups($preID);
320 //@todo - following line should not refer to undefined $postProfileTypes? figure out way to test
321 if (in_array('Individual', $preProfileTypes) ||
in_array('Contact', $postProfileTypes)) {
322 //Take Individual contact ID
323 $userID = CRM_Utils_Array
::value('related_contact', $values);
326 list($values['customPre_grouptitle'], $values['customPre']) = self
::getProfileNameAndFields($preID, $userID, $params['custom_pre_id']);
328 $userID = $contactID;
329 if ($postID = CRM_Utils_Array
::value('custom_post_id', $values)) {
330 if (!empty($values['related_contact'])) {
331 $postProfileTypes = CRM_Core_BAO_UFGroup
::profileGroups($postID);
332 if (in_array('Individual', $postProfileTypes) ||
in_array('Contact', $postProfileTypes)) {
333 //Take Individual contact ID
334 $userID = CRM_Utils_Array
::value('related_contact', $values);
337 list($values['customPost_grouptitle'], $values['customPost']) = self
::getProfileNameAndFields($postID, $userID, $params['custom_post_id']);
339 if (isset($values['honor'])) {
340 $honorValues = $values['honor'];
341 $template->_values
= array('honoree_profile_id' => $values['honoree_profile_id']);
342 CRM_Contribute_BAO_ContributionSoft
::formatHonoreeProfileFields(
344 $honorValues['honor_profile_values'],
345 $honorValues['honor_id']
349 $title = isset($values['title']) ?
$values['title'] : CRM_Contribute_PseudoConstant
::contributionPage($values['contribution_page_id']);
351 // Set email variables explicitly to avoid leaky smarty variables.
352 // All of these will be assigned to the template, replacing any that might be assigned elsewhere.
355 'receiptFromEmail' => CRM_Utils_Array
::value('receipt_from_email', $values),
356 'contactID' => $contactID,
357 'displayName' => $displayName,
358 'contributionID' => CRM_Utils_Array
::value('contribution_id', $values),
359 'contributionOtherID' => CRM_Utils_Array
::value('contribution_other_id', $values),
361 'lineItem' => CRM_Utils_Array
::value('lineItem', $values),
363 'priceSetID' => CRM_Utils_Array
::value('priceSetID', $values),
365 'isShare' => CRM_Utils_Array
::value('is_share', $values),
366 'thankyou_title' => CRM_Utils_Array
::value('thankyou_title', $values),
367 'customPre' => $values['customPre'],
368 'customPre_grouptitle' => $values['customPre_grouptitle'],
369 'customPost' => $values['customPost'],
370 'customPost_grouptitle' => $values['customPost_grouptitle'],
371 'useForMember' => $values['useForMember'],
374 if ($contributionTypeId = CRM_Utils_Array
::value('financial_type_id', $values)) {
375 $tplParams['contributionTypeId'] = $contributionTypeId;
376 $tplParams['contributionTypeName'] = CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_FinancialType',
377 $contributionTypeId);
380 if ($contributionPageId = CRM_Utils_Array
::value('id', $values)) {
381 $tplParams['contributionPageId'] = $contributionPageId;
384 // address required during receipt processing (pdf and email receipt)
385 if ($displayAddress = CRM_Utils_Array
::value('address', $values)) {
386 $tplParams['address'] = $displayAddress;
390 $originalCCReceipt = CRM_Utils_Array
::value('cc_receipt', $values);
392 // cc to related contacts of contributor OR the one who
393 // signs up. Is used for cases like - on behalf of
394 // contribution / signup ..etc
395 if (array_key_exists('related_contact', $values)) {
396 list($ccDisplayName, $ccEmail) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($values['related_contact']);
397 $ccMailId = "{$ccDisplayName} <{$ccEmail}>";
399 //@todo - this is the only place in this function where $values is altered - but I can't find any evidence it is used
400 $values['cc_receipt'] = !empty($values['cc_receipt']) ?
($values['cc_receipt'] . ',' . $ccMailId) : $ccMailId;
402 // reset primary-email in the template
403 $tplParams['email'] = $ccEmail;
405 $tplParams['onBehalfName'] = $displayName;
406 $tplParams['onBehalfEmail'] = $email;
408 if (!empty($values['onbehalf_profile_id'])) {
409 self
::buildCustomDisplay($values['onbehalf_profile_id'], 'onBehalfProfile', $contactID, $template, $params['onbehalf_profile'], $fieldTypes);
413 // use either the contribution or membership receipt, based on whether it’s a membership-related contrib or not
414 $sendTemplateParams = array(
415 'groupName' => !empty($values['isMembership']) ?
'msg_tpl_workflow_membership' : 'msg_tpl_workflow_contribution',
416 'valueName' => !empty($values['isMembership']) ?
'membership_online_receipt' : 'contribution_online_receipt',
417 'contactId' => $contactID,
418 'tplParams' => $tplParams,
420 'PDFFilename' => 'receipt.pdf',
423 if ($returnMessageText) {
424 list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
426 'subject' => $subject,
428 'to' => $displayName,
433 if ($values['is_email_receipt']) {
434 $sendTemplateParams['from'] = CRM_Utils_Array
::value('receipt_from_name', $values) . ' <' . $values['receipt_from_email'] . '>';
435 $sendTemplateParams['toName'] = $displayName;
436 $sendTemplateParams['toEmail'] = $email;
437 $sendTemplateParams['cc'] = CRM_Utils_Array
::value('cc_receipt', $values);
438 $sendTemplateParams['bcc'] = CRM_Utils_Array
::value('bcc_receipt', $values);
439 //send email with pdf invoice
440 $template = CRM_Core_Smarty
::singleton();
441 $taxAmt = $template->get_template_vars('dataArray');
442 $prefixValue = Civi
::settings()->get('contribution_invoice_settings');
443 $invoicing = CRM_Utils_Array
::value('invoicing', $prefixValue);
444 if (isset($invoicing) && isset($prefixValue['is_email_pdf'])) {
445 $sendTemplateParams['isEmailPdf'] = TRUE;
446 $sendTemplateParams['contributionId'] = $values['contribution_id'];
448 list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
451 // send duplicate alert, if dupe match found during on-behalf-of processing.
452 if (!empty($values['onbehalf_dupe_alert'])) {
453 $sendTemplateParams['groupName'] = 'msg_tpl_workflow_contribution';
454 $sendTemplateParams['valueName'] = 'contribution_dupalert';
455 $sendTemplateParams['from'] = ts('Automatically Generated') . " <{$values['receipt_from_email']}>";
456 $sendTemplateParams['toName'] = CRM_Utils_Array
::value('receipt_from_name', $values);
457 $sendTemplateParams['toEmail'] = CRM_Utils_Array
::value('receipt_from_email', $values);
458 $sendTemplateParams['tplParams']['onBehalfID'] = $contactID;
459 $sendTemplateParams['tplParams']['receiptMessage'] = $message;
461 // fix cc and reset back to original, CRM-6976
462 $sendTemplateParams['cc'] = $originalCCReceipt;
464 CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
470 * Get the profile title and fields.
474 * @param array $params
475 * @param array $fieldTypes
479 protected static function getProfileNameAndFields($gid, $cid, &$params, $fieldTypes = array()) {
483 if (CRM_Core_BAO_UFGroup
::filterUFGroups($gid, $cid)) {
484 $fields = CRM_Core_BAO_UFGroup
::getFields($gid, FALSE, CRM_Core_Action
::VIEW
, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission
::CREATE
, NULL);
485 foreach ($fields as $k => $v) {
487 $groupTitle = $v["groupTitle"];
489 // suppress all file fields from display and formatting fields
491 CRM_Utils_Array
::value('data_type', $v, '') == 'File' ||
492 CRM_Utils_Array
::value('name', $v, '') == 'image_URL' ||
493 CRM_Utils_Array
::value('field_type', $v) == 'Formatting'
498 if (!empty($fieldTypes) && (!in_array($v['field_type'], $fieldTypes))) {
503 CRM_Core_BAO_UFGroup
::getValues($cid, $fields, $values, FALSE, $params);
506 return array($groupTitle, $values);
510 * Send the emails for Recurring Contribution Notification.
512 * @param string $type
514 * @param int $contactID
515 * Contact id for contributor.
517 * Contribution page id.
518 * @param object $recur
519 * Object of recurring contribution table.
520 * @param bool|object $autoRenewMembership is it a auto renew membership.
522 public static function recurringNotify($type, $contactID, $pageID, $recur, $autoRenewMembership = FALSE) {
524 $isEmailReceipt = FALSE;
526 CRM_Core_DAO
::commonRetrieveAll('CRM_Contribute_DAO_ContributionPage', 'id', $pageID, $value, array(
530 'receipt_from_email',
534 $isEmailReceipt = CRM_Utils_Array
::value('is_email_receipt', $value[$pageID]);
536 elseif ($recur->id
) {
537 // This means we are coming from back-office - ie. no page ID, but recurring.
538 // Ideally this information would be passed into the function clearly rather than guessing by convention.
539 $isEmailReceipt = TRUE;
542 if ($isEmailReceipt) {
544 $receiptFrom = '"' . CRM_Utils_Array
::value('receipt_from_name', $value[$pageID]) . '" <' . $value[$pageID]['receipt_from_email'] . '>';
546 $receiptFromName = $value[$pageID]['receipt_from_name'];
547 $receiptFromEmail = $value[$pageID]['receipt_from_email'];
550 $domainValues = CRM_Core_BAO_Domain
::getNameAndEmail();
551 $receiptFrom = "$domainValues[0] <$domainValues[1]>";
552 $receiptFromName = $domainValues[0];
553 $receiptFromEmail = $domainValues[1];
556 list($displayName, $email) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contactID, FALSE);
557 $templatesParams = array(
558 'groupName' => 'msg_tpl_workflow_contribution',
559 'valueName' => 'contribution_recurring_notify',
560 'contactId' => $contactID,
561 'tplParams' => array(
562 'recur_frequency_interval' => $recur->frequency_interval
,
563 'recur_frequency_unit' => $recur->frequency_unit
,
564 'recur_installments' => $recur->installments
,
565 'recur_start_date' => $recur->start_date
,
566 'recur_end_date' => $recur->end_date
,
567 'recur_amount' => $recur->amount
,
568 'recur_txnType' => $type,
569 'displayName' => $displayName,
570 'receipt_from_name' => $receiptFromName,
571 'receipt_from_email' => $receiptFromEmail,
572 'auto_renew_membership' => $autoRenewMembership,
574 'from' => $receiptFrom,
575 'toName' => $displayName,
580 $templatesParams['cc'] = CRM_Utils_Array
::value('cc_receipt', $value[$pageID]);
581 $templatesParams['bcc'] = CRM_Utils_Array
::value('bcc_receipt', $value[$pageID]);
584 // in some cases its just recurringNotify() thats called for the first time and these urls don't get set.
585 // like in PaypalPro, & therefore we set it here additionally.
586 $template = CRM_Core_Smarty
::singleton();
587 $paymentProcessor = CRM_Financial_BAO_PaymentProcessor
::getProcessorForEntity($recur->id
, 'recur', 'obj');
588 $url = $paymentProcessor->subscriptionURL($recur->id
, 'recur');
589 $template->assign('cancelSubscriptionUrl', $url);
591 $url = $paymentProcessor->subscriptionURL($recur->id
, 'recur', 'billing');
592 $template->assign('updateSubscriptionBillingUrl', $url);
594 $url = $paymentProcessor->subscriptionURL($recur->id
, 'recur', 'update');
595 $template->assign('updateSubscriptionUrl', $url);
598 list($sent) = CRM_Core_BAO_MessageTemplate
::sendTemplate($templatesParams);
601 CRM_Core_Error
::debug_log_message('Success: mail sent for recurring notification.');
604 CRM_Core_Error
::debug_log_message('Failure: mail not sent for recurring notification.');
610 * Add the custom fields for contribution page (ie profile).
612 * @deprecated assigning values to smarty like this is risky because
613 * - it is hard to debug since $name is used in the assign
614 * - it is potentially 'leaky' - it's better to do this on the form
615 * or close to where it is used / required. See CRM-17519 for leakage e.g.
619 * @param string $name
623 * @param array $params
624 * Params to build component whereclause.
626 * @param array|null $fieldTypes
628 public static function buildCustomDisplay($gid, $name, $cid, &$template, &$params, $fieldTypes = NULL) {
629 list($groupTitle, $values) = self
::getProfileNameAndFields($gid, $cid, $params, $fieldTypes);
630 if (!empty($values)) {
631 $template->assign($name, $values);
633 $template->assign($name . "_grouptitle", $groupTitle);
637 * Make a copy of a contribution page, including all the blocks in the page.
640 * The contribution page id to copy.
642 * @return CRM_Contribute_DAO_ContributionPage
644 public static function copy($id) {
647 'title' => ts('Copy of') . ' ',
650 $copy = &CRM_Core_DAO
::copyGeneric('CRM_Contribute_DAO_ContributionPage', array(
652 ), NULL, $fieldsFix);
654 //copying all the blocks pertaining to the contribution page
655 $copyPledgeBlock = &CRM_Core_DAO
::copyGeneric('CRM_Pledge_DAO_PledgeBlock', array(
657 'entity_table' => 'civicrm_contribution_page',
659 'entity_id' => $copy->id
,
662 $copyMembershipBlock = &CRM_Core_DAO
::copyGeneric('CRM_Member_DAO_MembershipBlock', array(
664 'entity_table' => 'civicrm_contribution_page',
666 'entity_id' => $copy->id
,
669 $copyUFJoin = &CRM_Core_DAO
::copyGeneric('CRM_Core_DAO_UFJoin', array(
671 'entity_table' => 'civicrm_contribution_page',
673 'entity_id' => $copy->id
,
676 $copyWidget = &CRM_Core_DAO
::copyGeneric('CRM_Contribute_DAO_Widget', array(
677 'contribution_page_id' => $id,
679 'contribution_page_id' => $copy->id
,
683 CRM_Price_BAO_PriceSet
::copyPriceSet('civicrm_contribution_page', $id, $copy->id
);
685 $copyTellFriend = &CRM_Core_DAO
::copyGeneric('CRM_Friend_DAO_Friend', array(
687 'entity_table' => 'civicrm_contribution_page',
689 'entity_id' => $copy->id
,
692 $copyPersonalCampaignPages = &CRM_Core_DAO
::copyGeneric('CRM_PCP_DAO_PCPBlock', array(
694 'entity_table' => 'civicrm_contribution_page',
696 'entity_id' => $copy->id
,
697 'target_entity_id' => $copy->id
,
700 $copyPremium = &CRM_Core_DAO
::copyGeneric('CRM_Contribute_DAO_Premium', array(
702 'entity_table' => 'civicrm_contribution_page',
704 'entity_id' => $copy->id
,
708 FROM civicrm_premiums
709 WHERE entity_table = 'civicrm_contribution_page'
710 AND entity_id ={$id}";
712 $premiumDao = CRM_Core_DAO
::executeQuery($premiumQuery, CRM_Core_DAO
::$_nullArray);
713 while ($premiumDao->fetch()) {
714 if ($premiumDao->id
) {
715 CRM_Core_DAO
::copyGeneric('CRM_Contribute_DAO_PremiumsProduct', array(
716 'premiums_id' => $premiumDao->id
,
718 'premiums_id' => $copyPremium->id
,
725 CRM_Utils_Hook
::copy('ContributionPage', $copy);
731 * Get info for all sections enable/disable.
733 * @param array $contribPageIds
735 * info regarding all sections.
737 public static function getSectionInfo($contribPageIds = array()) {
740 if (is_array($contribPageIds) && !empty($contribPageIds)) {
741 $whereClause = 'WHERE civicrm_contribution_page.id IN ( ' . implode(', ', $contribPageIds) . ' )';
756 SELECT civicrm_contribution_page.id as id,
757 civicrm_contribution_page.financial_type_id as settings,
758 amount_block_is_active as amount,
759 civicrm_membership_block.id as membership,
760 civicrm_uf_join.id as custom,
761 civicrm_contribution_page.thankyou_title as thankyou,
762 civicrm_tell_friend.id as friend,
763 civicrm_pcp_block.id as pcp,
764 civicrm_contribution_widget.id as widget,
765 civicrm_premiums.id as premium
766 FROM civicrm_contribution_page
767 LEFT JOIN civicrm_membership_block ON ( civicrm_membership_block.entity_id = civicrm_contribution_page.id
768 AND civicrm_membership_block.entity_table = 'civicrm_contribution_page'
769 AND civicrm_membership_block.is_active = 1 )
770 LEFT JOIN civicrm_uf_join ON ( civicrm_uf_join.entity_id = civicrm_contribution_page.id
771 AND civicrm_uf_join.entity_table = 'civicrm_contribution_page'
772 AND module = 'CiviContribute'
773 AND civicrm_uf_join.is_active = 1 )
774 LEFT JOIN civicrm_tell_friend ON ( civicrm_tell_friend.entity_id = civicrm_contribution_page.id
775 AND civicrm_tell_friend.entity_table = 'civicrm_contribution_page'
776 AND civicrm_tell_friend.is_active = 1)
777 LEFT JOIN civicrm_pcp_block ON ( civicrm_pcp_block.entity_id = civicrm_contribution_page.id
778 AND civicrm_pcp_block.entity_table = 'civicrm_contribution_page'
779 AND civicrm_pcp_block.is_active = 1 )
780 LEFT JOIN civicrm_contribution_widget ON ( civicrm_contribution_widget.contribution_page_id = civicrm_contribution_page.id
781 AND civicrm_contribution_widget.is_active = 1 )
782 LEFT JOIN civicrm_premiums ON ( civicrm_premiums.entity_id = civicrm_contribution_page.id
783 AND civicrm_premiums.entity_table = 'civicrm_contribution_page'
784 AND civicrm_premiums.premiums_active = 1 )
787 $contributionPage = CRM_Core_DAO
::executeQuery($query);
788 while ($contributionPage->fetch()) {
789 if (!isset($info[$contributionPage->id
]) ||
!is_array($info[$contributionPage->id
])) {
790 $info[$contributionPage->id
] = array_fill_keys(array_values($sections), FALSE);
792 foreach ($sections as $section) {
793 if ($contributionPage->$section) {
794 $info[$contributionPage->id
][$section] = TRUE;
803 * Get options for a given field.
804 * @see CRM_Core_DAO::buildOptions
806 * @param string $fieldName
807 * @param string $context : @see CRM_Core_DAO::buildOptionsContext
808 * @param array $props : whatever is known about this dao object
812 public static function buildOptions($fieldName, $context = NULL, $props = array()) {
814 // Special logic for fields whose options depend on context or properties
815 switch ($fieldName) {
816 case 'financial_type_id':
817 // Fixme - this is going to ignore context, better to get conditions, add params, and call PseudoConstant::get
818 return CRM_Financial_BAO_FinancialType
::getIncomeFinancialType();
822 return CRM_Core_PseudoConstant
::get(__CLASS__
, $fieldName, $params, $context);
826 * Get or Set honor/on_behalf params for processing module_data or setting default values.
828 * @param array $params :
829 * @param bool $setDefault : If yes then returns array to used for setting default value afterward
830 * @param string $module : processing module_data for which module? e.g. soft_credit, on_behalf
832 * @return array|string
834 public static function formatModuleData($params, $setDefault = FALSE, $module) {
836 $config = CRM_Core_Config
::singleton();
837 $json = $jsonDecode = NULL;
838 $domain = new CRM_Core_DAO_Domain();
841 $moduleDataFormat = array(
842 'soft_credit' => array(
843 1 => 'soft_credit_types',
844 'multilingual' => array(
849 'on_behalf' => array(
850 1 => 'is_for_organization',
851 'multilingual' => array(
857 //When we are fetching the honor params respecting both multi and mono lingual state
858 //and setting it to default param of Contribution Page's Main and Setting form
860 $jsonDecode = json_decode($params);
861 $jsonDecode = (array) $jsonDecode->$module;
862 if (!$domain->locales
&& !empty($jsonDecode['default'])) {
864 $jsonDecode +
= (array) $jsonDecode['default'];
865 unset($jsonDecode['default']);
867 elseif (!empty($jsonDecode[$tsLocale])) {
869 foreach ($jsonDecode[$tsLocale] as $column => $value) {
870 $jsonDecode[$column] = $value;
872 unset($jsonDecode[$tsLocale]);
877 //check and handle multilingual honoree params
878 if (!$domain->locales
) {
879 //if in singlelingual state simply return the array format
880 $json = array($module => NULL);
881 foreach ($moduleDataFormat[$module] as $key => $attribute) {
882 if ($key === 'multilingual') {
883 $json[$module]['default'] = array();
884 foreach ($attribute as $attr) {
885 $json[$module]['default'][$attr] = $params[$attr];
889 $json[$module][$attribute] = $params[$attribute];
892 $json = json_encode($json);
895 //if in multilingual state then retrieve the module_data against this contribution and
896 //merge with earlier module_data json data to current so not to lose earlier multilingual module_data information
897 $json = array($module => NULL);
898 foreach ($moduleDataFormat[$module] as $key => $attribute) {
899 if ($key === 'multilingual') {
900 $json[$module][$config->lcMessages
] = array();
901 foreach ($attribute as $attr) {
902 $json[$module][$config->lcMessages
][$attr] = $params[$attr];
906 $json[$module][$attribute] = $params[$attribute];
910 $ufJoinDAO = new CRM_Core_DAO_UFJoin();
911 $ufJoinDAO->module
= $module;
912 $ufJoinDAO->entity_id
= $params['id'];
913 $ufJoinDAO->find(TRUE);
914 $jsonData = json_decode($ufJoinDAO->module_data
);
916 $json[$module] = array_merge((array) $jsonData->$module, $json[$module]);
918 $json = json_encode($json);
924 * Generate html for pdf in confirmation receipt email attachment.
925 * @param int $contributionId
926 * Contribution Page Id.
928 * Contact id for contributor.
931 public static function addInvoicePdfToEmail($contributionId, $userID) {
932 $contributionID = array($contributionId);
933 $contactId = array($userID);
935 'output' => 'pdf_invoice',
936 'forPage' => 'confirmpage',
938 $pdfHtml = CRM_Contribute_Form_Task_Invoice
::printPDF($contributionID,
939 $pdfParams, $contactId, CRM_Core_DAO
::$_nullObject);
944 * Helper to determine if the page supports separate membership payments.
946 * @param int $id form id
949 * isSeparateMembershipPayment
951 public static function getIsMembershipPayment($id) {
952 $membershipBlocks = civicrm_api3('membership_block', 'get', array(
953 'entity_table' => 'civicrm_contribution_page',
955 'sequential' => TRUE,
957 if (!$membershipBlocks['count']) {
960 return $membershipBlocks['values'][0]['is_separate_payment'];