3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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-2016
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 // Next stage is to remove this & ensure there are no e-notices - ie. all are set before they hit this fn.
161 $valuesRequiredForTemplate = array(
164 'customPre_grouptitle',
165 'customPost_grouptitle',
173 foreach ($valuesRequiredForTemplate as $valueRequiredForTemplate) {
174 if (!isset($values[$valueRequiredForTemplate])) {
175 $values[$valueRequiredForTemplate] = NULL;
179 if (isset($values['custom_pre_id'])) {
180 $preProfileType = CRM_Core_BAO_UFField
::getProfileType($values['custom_pre_id']);
181 if ($preProfileType == 'Membership' && !empty($values['membership_id'])) {
182 $params['custom_pre_id'] = array(
186 $values['membership_id'],
192 elseif ($preProfileType == 'Contribution' && !empty($values['contribution_id'])) {
193 $params['custom_pre_id'] = array(
197 $values['contribution_id'],
204 $gIds['custom_pre_id'] = $values['custom_pre_id'];
207 if (isset($values['custom_post_id'])) {
208 $postProfileType = CRM_Core_BAO_UFField
::getProfileType($values['custom_post_id']);
209 if ($postProfileType == 'Membership' && !empty($values['membership_id'])) {
210 $params['custom_post_id'] = array(
214 $values['membership_id'],
220 elseif ($postProfileType == 'Contribution' && !empty($values['contribution_id'])) {
221 $params['custom_post_id'] = array(
225 $values['contribution_id'],
232 $gIds['custom_post_id'] = $values['custom_post_id'];
235 if (!empty($values['is_for_organization'])) {
236 if (!empty($values['membership_id'])) {
237 $params['onbehalf_profile'] = array(
241 $values['membership_id'],
247 elseif (!empty($values['contribution_id'])) {
248 $params['onbehalf_profile'] = array(
252 $values['contribution_id'],
260 //check whether it is a test drive
261 if ($isTest && !empty($params['custom_pre_id'])) {
262 $params['custom_pre_id'][] = array(
271 if ($isTest && !empty($params['custom_post_id'])) {
272 $params['custom_post_id'][] = array(
281 if (!$returnMessageText && !empty($gIds)) {
282 //send notification email if field values are set (CRM-1941)
283 foreach ($gIds as $key => $gId) {
285 $email = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup', $gId, 'notify');
287 $val = CRM_Core_BAO_UFGroup
::checkFieldsEmptyValues($gId, $contactID, CRM_Utils_Array
::value($key, $params), TRUE);
288 CRM_Core_BAO_UFGroup
::commonSendMail($contactID, $val);
294 if (!empty($values['is_email_receipt']) ||
!empty($values['onbehalf_dupe_alert']) ||
297 $template = CRM_Core_Smarty
::singleton();
299 // get the billing location type
300 if (!array_key_exists('related_contact', $values)) {
301 $billingLocationTypeId = CRM_Core_BAO_LocationType
::getBilling();
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
;
310 if (!array_key_exists('related_contact', $values)) {
311 list($displayName, $email) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contactID, FALSE, $billingLocationTypeId);
313 // get primary location email if no email exist( for billing location).
315 list($displayName, $email) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contactID);
317 if (empty($displayName)) {
318 list($displayName, $email) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contactID);
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)) {
329 if (!empty($values['related_contact'])) {
330 $preProfileTypes = CRM_Core_BAO_UFGroup
::profileGroups($preID);
331 //@todo - following line should not refer to undefined $postProfileTypes? figure out way to test
332 if (in_array('Individual', $preProfileTypes) ||
in_array('Contact', $postProfileTypes)) {
333 //Take Individual contact ID
334 $userID = CRM_Utils_Array
::value('related_contact', $values);
337 list($values['customPre_grouptitle'], $values['customPre']) = self
::getProfileNameAndFields($preID, $userID, $params['custom_pre_id']);
339 $userID = $contactID;
340 if ($postID = CRM_Utils_Array
::value('custom_post_id', $values)) {
341 if (!empty($values['related_contact'])) {
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);
348 list($values['customPost_grouptitle'], $values['customPost']) = self
::getProfileNameAndFields($postID, $userID, $params['custom_post_id']);
350 if (isset($values['honor'])) {
351 $honorValues = $values['honor'];
352 $template->_values
= array('honoree_profile_id' => $values['honoree_profile_id']);
353 CRM_Contribute_BAO_ContributionSoft
::formatHonoreeProfileFields(
355 $honorValues['honor_profile_values'],
356 $honorValues['honor_id']
360 $title = isset($values['title']) ?
$values['title'] : CRM_Contribute_PseudoConstant
::contributionPage($values['contribution_page_id']);
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.
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),
372 'lineItem' => CRM_Utils_Array
::value('lineItem', $values),
374 'priceSetID' => CRM_Utils_Array
::value('priceSetID', $values),
376 'isShare' => CRM_Utils_Array
::value('is_share', $values),
377 'thankyou_title' => CRM_Utils_Array
::value('thankyou_title', $values),
378 'customPre' => $values['customPre'],
379 'customPre_grouptitle' => $values['customPre_grouptitle'],
380 'customPost' => $values['customPost'],
381 'customPost_grouptitle' => $values['customPost_grouptitle'],
382 'useForMember' => $values['useForMember'],
383 'membership_assign' => $values['membership_assign'],
384 'amount' => $values['amount'],
385 'is_pay_later' => $values['is_pay_later'],
386 'receipt_date' => !$values['receipt_date'] ?
NULL : date('YmdHis', strtotime($values['receipt_date'])),
387 'pay_later_receipt' => CRM_Utils_Array
::value('pay_later_receipt', $values),
390 if ($contributionTypeId = CRM_Utils_Array
::value('financial_type_id', $values)) {
391 $tplParams['financialTypeId'] = $contributionTypeId;
392 $tplParams['financialTypeName'] = CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_FinancialType',
393 $contributionTypeId);
395 $tplParams['contributionTypeName'] = $tplParams['financialTypeName'];
396 $tplParams['contributionTypeId'] = $contributionTypeId;
399 if ($contributionPageId = CRM_Utils_Array
::value('id', $values)) {
400 $tplParams['contributionPageId'] = $contributionPageId;
403 // address required during receipt processing (pdf and email receipt)
404 if ($displayAddress = CRM_Utils_Array
::value('address', $values)) {
405 $tplParams['address'] = $displayAddress;
409 $originalCCReceipt = CRM_Utils_Array
::value('cc_receipt', $values);
411 // cc to related contacts of contributor OR the one who
412 // signs up. Is used for cases like - on behalf of
413 // contribution / signup ..etc
414 if (array_key_exists('related_contact', $values)) {
415 list($ccDisplayName, $ccEmail) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($values['related_contact']);
416 $ccMailId = "{$ccDisplayName} <{$ccEmail}>";
418 //@todo - this is the only place in this function where $values is altered - but I can't find any evidence it is used
419 $values['cc_receipt'] = !empty($values['cc_receipt']) ?
($values['cc_receipt'] . ',' . $ccMailId) : $ccMailId;
421 // reset primary-email in the template
422 $tplParams['email'] = $ccEmail;
424 $tplParams['onBehalfName'] = $displayName;
425 $tplParams['onBehalfEmail'] = $email;
427 if (!empty($values['onbehalf_profile_id'])) {
428 self
::buildCustomDisplay($values['onbehalf_profile_id'], 'onBehalfProfile', $contactID, $template, $params['onbehalf_profile'], $fieldTypes);
432 // use either the contribution or membership receipt, based on whether it’s a membership-related contrib or not
433 $sendTemplateParams = array(
434 'groupName' => !empty($values['isMembership']) ?
'msg_tpl_workflow_membership' : 'msg_tpl_workflow_contribution',
435 'valueName' => !empty($values['isMembership']) ?
'membership_online_receipt' : 'contribution_online_receipt',
436 'contactId' => $contactID,
437 'tplParams' => $tplParams,
439 'PDFFilename' => 'receipt.pdf',
442 if ($returnMessageText) {
443 list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
445 'subject' => $subject,
447 'to' => $displayName,
452 if (empty($values['receipt_from_name']) && empty($values['receipt_from_name'])) {
453 list($values['receipt_from_name'], $values['receipt_from_email']) = CRM_Core_BAO_Domain
::getNameAndEmail();
456 if ($values['is_email_receipt']) {
457 $sendTemplateParams['from'] = CRM_Utils_Array
::value('receipt_from_name', $values) . ' <' . $values['receipt_from_email'] . '>';
458 $sendTemplateParams['toName'] = $displayName;
459 $sendTemplateParams['toEmail'] = $email;
460 $sendTemplateParams['cc'] = CRM_Utils_Array
::value('cc_receipt', $values);
461 $sendTemplateParams['bcc'] = CRM_Utils_Array
::value('bcc_receipt', $values);
462 //send email with pdf invoice
463 $template = CRM_Core_Smarty
::singleton();
464 $taxAmt = $template->get_template_vars('dataArray');
465 $prefixValue = Civi
::settings()->get('contribution_invoice_settings');
466 $invoicing = CRM_Utils_Array
::value('invoicing', $prefixValue);
467 if (isset($invoicing) && isset($prefixValue['is_email_pdf'])) {
468 $sendTemplateParams['isEmailPdf'] = TRUE;
469 $sendTemplateParams['contributionId'] = $values['contribution_id'];
471 list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
474 // send duplicate alert, if dupe match found during on-behalf-of processing.
475 if (!empty($values['onbehalf_dupe_alert'])) {
476 $sendTemplateParams['groupName'] = 'msg_tpl_workflow_contribution';
477 $sendTemplateParams['valueName'] = 'contribution_dupalert';
478 $sendTemplateParams['from'] = ts('Automatically Generated') . " <{$values['receipt_from_email']}>";
479 $sendTemplateParams['toName'] = CRM_Utils_Array
::value('receipt_from_name', $values);
480 $sendTemplateParams['toEmail'] = CRM_Utils_Array
::value('receipt_from_email', $values);
481 $sendTemplateParams['tplParams']['onBehalfID'] = $contactID;
482 $sendTemplateParams['tplParams']['receiptMessage'] = $message;
484 // fix cc and reset back to original, CRM-6976
485 $sendTemplateParams['cc'] = $originalCCReceipt;
487 CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
493 * Get the profile title and fields.
497 * @param array $params
498 * @param array $fieldTypes
502 protected static function getProfileNameAndFields($gid, $cid, &$params, $fieldTypes = array()) {
506 if (CRM_Core_BAO_UFGroup
::filterUFGroups($gid, $cid)) {
507 $fields = CRM_Core_BAO_UFGroup
::getFields($gid, FALSE, CRM_Core_Action
::VIEW
, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission
::CREATE
, NULL);
508 foreach ($fields as $k => $v) {
510 $groupTitle = $v["groupTitle"];
512 // suppress all file fields from display and formatting fields
514 CRM_Utils_Array
::value('data_type', $v, '') == 'File' ||
515 CRM_Utils_Array
::value('name', $v, '') == 'image_URL' ||
516 CRM_Utils_Array
::value('field_type', $v) == 'Formatting'
521 if (!empty($fieldTypes) && (!in_array($v['field_type'], $fieldTypes))) {
526 CRM_Core_BAO_UFGroup
::getValues($cid, $fields, $values, FALSE, $params);
529 return array($groupTitle, $values);
533 * Send the emails for Recurring Contribution Notification.
535 * @param string $type
537 * @param int $contactID
538 * Contact id for contributor.
540 * Contribution page id.
541 * @param object $recur
542 * Object of recurring contribution table.
543 * @param bool|object $autoRenewMembership is it a auto renew membership.
545 public static function recurringNotify($type, $contactID, $pageID, $recur, $autoRenewMembership = FALSE) {
547 $isEmailReceipt = FALSE;
549 CRM_Core_DAO
::commonRetrieveAll('CRM_Contribute_DAO_ContributionPage', 'id', $pageID, $value, array(
553 'receipt_from_email',
557 $isEmailReceipt = CRM_Utils_Array
::value('is_email_receipt', $value[$pageID]);
559 elseif ($recur->id
) {
560 // This means we are coming from back-office - ie. no page ID, but recurring.
561 // Ideally this information would be passed into the function clearly rather than guessing by convention.
562 $isEmailReceipt = TRUE;
565 if ($isEmailReceipt) {
567 $receiptFrom = '"' . CRM_Utils_Array
::value('receipt_from_name', $value[$pageID]) . '" <' . $value[$pageID]['receipt_from_email'] . '>';
569 $receiptFromName = $value[$pageID]['receipt_from_name'];
570 $receiptFromEmail = $value[$pageID]['receipt_from_email'];
573 $domainValues = CRM_Core_BAO_Domain
::getNameAndEmail();
574 $receiptFrom = "$domainValues[0] <$domainValues[1]>";
575 $receiptFromName = $domainValues[0];
576 $receiptFromEmail = $domainValues[1];
579 list($displayName, $email) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contactID, FALSE);
580 $templatesParams = array(
581 'groupName' => 'msg_tpl_workflow_contribution',
582 'valueName' => 'contribution_recurring_notify',
583 'contactId' => $contactID,
584 'tplParams' => array(
585 'recur_frequency_interval' => $recur->frequency_interval
,
586 'recur_frequency_unit' => $recur->frequency_unit
,
587 'recur_installments' => $recur->installments
,
588 'recur_start_date' => $recur->start_date
,
589 'recur_end_date' => $recur->end_date
,
590 'recur_amount' => $recur->amount
,
591 'recur_txnType' => $type,
592 'displayName' => $displayName,
593 'receipt_from_name' => $receiptFromName,
594 'receipt_from_email' => $receiptFromEmail,
595 'auto_renew_membership' => $autoRenewMembership,
597 'from' => $receiptFrom,
598 'toName' => $displayName,
603 $templatesParams['cc'] = CRM_Utils_Array
::value('cc_receipt', $value[$pageID]);
604 $templatesParams['bcc'] = CRM_Utils_Array
::value('bcc_receipt', $value[$pageID]);
607 // in some cases its just recurringNotify() thats called for the first time and these urls don't get set.
608 // like in PaypalPro, & therefore we set it here additionally.
609 $template = CRM_Core_Smarty
::singleton();
610 $paymentProcessor = CRM_Financial_BAO_PaymentProcessor
::getProcessorForEntity($recur->id
, 'recur', 'obj');
611 $url = $paymentProcessor->subscriptionURL($recur->id
, 'recur', 'cancel');
612 $template->assign('cancelSubscriptionUrl', $url);
614 $url = $paymentProcessor->subscriptionURL($recur->id
, 'recur', 'billing');
615 $template->assign('updateSubscriptionBillingUrl', $url);
617 $url = $paymentProcessor->subscriptionURL($recur->id
, 'recur', 'update');
618 $template->assign('updateSubscriptionUrl', $url);
621 list($sent) = CRM_Core_BAO_MessageTemplate
::sendTemplate($templatesParams);
624 CRM_Core_Error
::debug_log_message('Success: mail sent for recurring notification.');
627 CRM_Core_Error
::debug_log_message('Failure: mail not sent for recurring notification.');
633 * Add the custom fields for contribution page (ie profile).
635 * @deprecated assigning values to smarty like this is risky because
636 * - it is hard to debug since $name is used in the assign
637 * - it is potentially 'leaky' - it's better to do this on the form
638 * or close to where it is used / required. See CRM-17519 for leakage e.g.
642 * @param string $name
646 * @param array $params
647 * Params to build component whereclause.
649 * @param array|null $fieldTypes
651 public static function buildCustomDisplay($gid, $name, $cid, &$template, &$params, $fieldTypes = NULL) {
652 list($groupTitle, $values) = self
::getProfileNameAndFields($gid, $cid, $params, $fieldTypes);
653 if (!empty($values)) {
654 $template->assign($name, $values);
656 $template->assign($name . "_grouptitle", $groupTitle);
660 * Make a copy of a contribution page, including all the blocks in the page.
663 * The contribution page id to copy.
665 * @return CRM_Contribute_DAO_ContributionPage
667 public static function copy($id) {
670 'title' => ts('Copy of') . ' ',
673 $copy = &CRM_Core_DAO
::copyGeneric('CRM_Contribute_DAO_ContributionPage', array(
675 ), NULL, $fieldsFix);
677 //copying all the blocks pertaining to the contribution page
678 $copyPledgeBlock = &CRM_Core_DAO
::copyGeneric('CRM_Pledge_DAO_PledgeBlock', array(
680 'entity_table' => 'civicrm_contribution_page',
682 'entity_id' => $copy->id
,
685 $copyMembershipBlock = &CRM_Core_DAO
::copyGeneric('CRM_Member_DAO_MembershipBlock', array(
687 'entity_table' => 'civicrm_contribution_page',
689 'entity_id' => $copy->id
,
692 $copyUFJoin = &CRM_Core_DAO
::copyGeneric('CRM_Core_DAO_UFJoin', array(
694 'entity_table' => 'civicrm_contribution_page',
696 'entity_id' => $copy->id
,
699 $copyWidget = &CRM_Core_DAO
::copyGeneric('CRM_Contribute_DAO_Widget', array(
700 'contribution_page_id' => $id,
702 'contribution_page_id' => $copy->id
,
706 CRM_Price_BAO_PriceSet
::copyPriceSet('civicrm_contribution_page', $id, $copy->id
);
708 $copyTellFriend = &CRM_Core_DAO
::copyGeneric('CRM_Friend_DAO_Friend', array(
710 'entity_table' => 'civicrm_contribution_page',
712 'entity_id' => $copy->id
,
715 $copyPersonalCampaignPages = &CRM_Core_DAO
::copyGeneric('CRM_PCP_DAO_PCPBlock', array(
717 'entity_table' => 'civicrm_contribution_page',
719 'entity_id' => $copy->id
,
720 'target_entity_id' => $copy->id
,
723 $copyPremium = &CRM_Core_DAO
::copyGeneric('CRM_Contribute_DAO_Premium', array(
725 'entity_table' => 'civicrm_contribution_page',
727 'entity_id' => $copy->id
,
731 FROM civicrm_premiums
732 WHERE entity_table = 'civicrm_contribution_page'
733 AND entity_id ={$id}";
735 $premiumDao = CRM_Core_DAO
::executeQuery($premiumQuery, CRM_Core_DAO
::$_nullArray);
736 while ($premiumDao->fetch()) {
737 if ($premiumDao->id
) {
738 CRM_Core_DAO
::copyGeneric('CRM_Contribute_DAO_PremiumsProduct', array(
739 'premiums_id' => $premiumDao->id
,
741 'premiums_id' => $copyPremium->id
,
748 CRM_Utils_Hook
::copy('ContributionPage', $copy);
754 * Get info for all sections enable/disable.
756 * @param array $contribPageIds
758 * info regarding all sections.
760 public static function getSectionInfo($contribPageIds = array()) {
763 if (is_array($contribPageIds) && !empty($contribPageIds)) {
764 $whereClause = 'WHERE civicrm_contribution_page.id IN ( ' . implode(', ', $contribPageIds) . ' )';
779 SELECT civicrm_contribution_page.id as id,
780 civicrm_contribution_page.financial_type_id as settings,
781 amount_block_is_active as amount,
782 civicrm_membership_block.id as membership,
783 civicrm_uf_join.id as custom,
784 civicrm_contribution_page.thankyou_title as thankyou,
785 civicrm_tell_friend.id as friend,
786 civicrm_pcp_block.id as pcp,
787 civicrm_contribution_widget.id as widget,
788 civicrm_premiums.id as premium
789 FROM civicrm_contribution_page
790 LEFT JOIN civicrm_membership_block ON ( civicrm_membership_block.entity_id = civicrm_contribution_page.id
791 AND civicrm_membership_block.entity_table = 'civicrm_contribution_page'
792 AND civicrm_membership_block.is_active = 1 )
793 LEFT JOIN civicrm_uf_join ON ( civicrm_uf_join.entity_id = civicrm_contribution_page.id
794 AND civicrm_uf_join.entity_table = 'civicrm_contribution_page'
795 AND module = 'CiviContribute'
796 AND civicrm_uf_join.is_active = 1 )
797 LEFT JOIN civicrm_tell_friend ON ( civicrm_tell_friend.entity_id = civicrm_contribution_page.id
798 AND civicrm_tell_friend.entity_table = 'civicrm_contribution_page'
799 AND civicrm_tell_friend.is_active = 1)
800 LEFT JOIN civicrm_pcp_block ON ( civicrm_pcp_block.entity_id = civicrm_contribution_page.id
801 AND civicrm_pcp_block.entity_table = 'civicrm_contribution_page'
802 AND civicrm_pcp_block.is_active = 1 )
803 LEFT JOIN civicrm_contribution_widget ON ( civicrm_contribution_widget.contribution_page_id = civicrm_contribution_page.id
804 AND civicrm_contribution_widget.is_active = 1 )
805 LEFT JOIN civicrm_premiums ON ( civicrm_premiums.entity_id = civicrm_contribution_page.id
806 AND civicrm_premiums.entity_table = 'civicrm_contribution_page'
807 AND civicrm_premiums.premiums_active = 1 )
810 $contributionPage = CRM_Core_DAO
::executeQuery($query);
811 while ($contributionPage->fetch()) {
812 if (!isset($info[$contributionPage->id
]) ||
!is_array($info[$contributionPage->id
])) {
813 $info[$contributionPage->id
] = array_fill_keys(array_values($sections), FALSE);
815 foreach ($sections as $section) {
816 if ($contributionPage->$section) {
817 $info[$contributionPage->id
][$section] = TRUE;
826 * Get options for a given field.
827 * @see CRM_Core_DAO::buildOptions
829 * @param string $fieldName
830 * @param string $context : @see CRM_Core_DAO::buildOptionsContext
831 * @param array $props : whatever is known about this dao object
835 public static function buildOptions($fieldName, $context = NULL, $props = array()) {
837 // Special logic for fields whose options depend on context or properties
838 switch ($fieldName) {
839 case 'financial_type_id':
840 // Fixme - this is going to ignore context, better to get conditions, add params, and call PseudoConstant::get
841 return CRM_Financial_BAO_FinancialType
::getIncomeFinancialType();
845 return CRM_Core_PseudoConstant
::get(__CLASS__
, $fieldName, $params, $context);
849 * Get or Set honor/on_behalf params for processing module_data or setting default values.
851 * @param array $params :
852 * @param bool $setDefault : If yes then returns array to used for setting default value afterward
853 * @param string $module : processing module_data for which module? e.g. soft_credit, on_behalf
855 * @return array|string
857 public static function formatModuleData($params, $setDefault = FALSE, $module) {
859 $config = CRM_Core_Config
::singleton();
860 $json = $jsonDecode = NULL;
861 $domain = new CRM_Core_DAO_Domain();
864 $moduleDataFormat = array(
865 'soft_credit' => array(
866 1 => 'soft_credit_types',
867 'multilingual' => array(
872 'on_behalf' => array(
873 1 => 'is_for_organization',
874 'multilingual' => array(
880 //When we are fetching the honor params respecting both multi and mono lingual state
881 //and setting it to default param of Contribution Page's Main and Setting form
883 $jsonDecode = json_decode($params);
884 $jsonDecode = (array) $jsonDecode->$module;
885 if (!$domain->locales
&& !empty($jsonDecode['default'])) {
887 $jsonDecode +
= (array) $jsonDecode['default'];
888 unset($jsonDecode['default']);
890 elseif (!empty($jsonDecode[$tsLocale])) {
892 foreach ($jsonDecode[$tsLocale] as $column => $value) {
893 $jsonDecode[$column] = $value;
895 unset($jsonDecode[$tsLocale]);
900 //check and handle multilingual honoree params
901 if (!$domain->locales
) {
902 //if in singlelingual state simply return the array format
903 $json = array($module => NULL);
904 foreach ($moduleDataFormat[$module] as $key => $attribute) {
905 if ($key === 'multilingual') {
906 $json[$module]['default'] = array();
907 foreach ($attribute as $attr) {
908 $json[$module]['default'][$attr] = $params[$attr];
912 $json[$module][$attribute] = $params[$attribute];
915 $json = json_encode($json);
918 //if in multilingual state then retrieve the module_data against this contribution and
919 //merge with earlier module_data json data to current so not to lose earlier multilingual module_data information
920 $json = array($module => NULL);
921 foreach ($moduleDataFormat[$module] as $key => $attribute) {
922 if ($key === 'multilingual') {
923 $json[$module][$config->lcMessages
] = array();
924 foreach ($attribute as $attr) {
925 $json[$module][$config->lcMessages
][$attr] = $params[$attr];
929 $json[$module][$attribute] = $params[$attribute];
933 $ufJoinDAO = new CRM_Core_DAO_UFJoin();
934 $ufJoinDAO->module
= $module;
935 $ufJoinDAO->entity_id
= $params['id'];
936 $ufJoinDAO->find(TRUE);
937 $jsonData = json_decode($ufJoinDAO->module_data
);
939 $json[$module] = array_merge((array) $jsonData->$module, $json[$module]);
941 $json = json_encode($json);
947 * Generate html for pdf in confirmation receipt email attachment.
948 * @param int $contributionId
949 * Contribution Page Id.
951 * Contact id for contributor.
954 public static function addInvoicePdfToEmail($contributionId, $userID) {
955 $contributionID = array($contributionId);
956 $contactId = array($userID);
958 'output' => 'pdf_invoice',
959 'forPage' => 'confirmpage',
961 $pdfHtml = CRM_Contribute_Form_Task_Invoice
::printPDF($contributionID,
962 $pdfParams, $contactId, CRM_Core_DAO
::$_nullObject);
967 * Helper to determine if the page supports separate membership payments.
969 * @param int $id form id
972 * isSeparateMembershipPayment
974 public static function getIsMembershipPayment($id) {
975 $membershipBlocks = civicrm_api3('membership_block', 'get', array(
976 'entity_table' => 'civicrm_contribution_page',
978 'sequential' => TRUE,
980 if (!$membershipBlocks['count']) {
983 return $membershipBlocks['values'][0]['is_separate_payment'];