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 // 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',
171 foreach ($valuesRequiredForTemplate as $valueRequiredForTemplate) {
172 if (!isset($values[$valueRequiredForTemplate])) {
173 $values[$valueRequiredForTemplate] = NULL;
177 if (isset($values['custom_pre_id'])) {
178 $preProfileType = CRM_Core_BAO_UFField
::getProfileType($values['custom_pre_id']);
179 if ($preProfileType == 'Membership' && !empty($values['membership_id'])) {
180 $params['custom_pre_id'] = array(
184 $values['membership_id'],
190 elseif ($preProfileType == 'Contribution' && !empty($values['contribution_id'])) {
191 $params['custom_pre_id'] = array(
195 $values['contribution_id'],
202 $gIds['custom_pre_id'] = $values['custom_pre_id'];
205 if (isset($values['custom_post_id'])) {
206 $postProfileType = CRM_Core_BAO_UFField
::getProfileType($values['custom_post_id']);
207 if ($postProfileType == 'Membership' && !empty($values['membership_id'])) {
208 $params['custom_post_id'] = array(
212 $values['membership_id'],
218 elseif ($postProfileType == 'Contribution' && !empty($values['contribution_id'])) {
219 $params['custom_post_id'] = array(
223 $values['contribution_id'],
230 $gIds['custom_post_id'] = $values['custom_post_id'];
233 if (!empty($values['is_for_organization'])) {
234 if (!empty($values['membership_id'])) {
235 $params['onbehalf_profile'] = array(
239 $values['membership_id'],
245 elseif (!empty($values['contribution_id'])) {
246 $params['onbehalf_profile'] = array(
250 $values['contribution_id'],
258 //check whether it is a test drive
259 if ($isTest && !empty($params['custom_pre_id'])) {
260 $params['custom_pre_id'][] = array(
269 if ($isTest && !empty($params['custom_post_id'])) {
270 $params['custom_post_id'][] = array(
279 if (!$returnMessageText && !empty($gIds)) {
280 //send notification email if field values are set (CRM-1941)
281 foreach ($gIds as $key => $gId) {
283 $email = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup', $gId, 'notify');
285 $val = CRM_Core_BAO_UFGroup
::checkFieldsEmptyValues($gId, $contactID, CRM_Utils_Array
::value($key, $params), TRUE);
286 CRM_Core_BAO_UFGroup
::commonSendMail($contactID, $val);
292 if (!empty($values['is_email_receipt']) ||
!empty($values['onbehalf_dupe_alert']) ||
295 $template = CRM_Core_Smarty
::singleton();
297 // get the billing location type
298 if (!array_key_exists('related_contact', $values)) {
299 $billingLocationTypeId = CRM_Core_BAO_LocationType
::getBilling();
302 // presence of related contact implies onbehalf of org case,
303 // where location type is set to default.
304 $locType = CRM_Core_BAO_LocationType
::getDefault();
305 $billingLocationTypeId = $locType->id
;
308 if (!array_key_exists('related_contact', $values)) {
309 list($displayName, $email) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contactID, FALSE, $billingLocationTypeId);
311 // get primary location email if no email exist( for billing location).
313 list($displayName, $email) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contactID);
315 if (empty($displayName)) {
316 list($displayName, $email) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contactID);
319 //for display profile need to get individual contact id,
320 //hence get it from related_contact if on behalf of org true CRM-3767
321 //CRM-5001 Contribution/Membership:: On Behalf of Organization,
322 //If profile GROUP contain the Individual type then consider the
323 //profile is of Individual ( including the custom data of membership/contribution )
324 //IF Individual type not present in profile then it is consider as Organization data.
325 $userID = $contactID;
326 if ($preID = CRM_Utils_Array
::value('custom_pre_id', $values)) {
327 if (!empty($values['related_contact'])) {
328 $preProfileTypes = CRM_Core_BAO_UFGroup
::profileGroups($preID);
329 //@todo - following line should not refer to undefined $postProfileTypes? figure out way to test
330 if (in_array('Individual', $preProfileTypes) ||
in_array('Contact', $postProfileTypes)) {
331 //Take Individual contact ID
332 $userID = CRM_Utils_Array
::value('related_contact', $values);
335 list($values['customPre_grouptitle'], $values['customPre']) = self
::getProfileNameAndFields($preID, $userID, $params['custom_pre_id']);
337 $userID = $contactID;
338 if ($postID = CRM_Utils_Array
::value('custom_post_id', $values)) {
339 if (!empty($values['related_contact'])) {
340 $postProfileTypes = CRM_Core_BAO_UFGroup
::profileGroups($postID);
341 if (in_array('Individual', $postProfileTypes) ||
in_array('Contact', $postProfileTypes)) {
342 //Take Individual contact ID
343 $userID = CRM_Utils_Array
::value('related_contact', $values);
346 list($values['customPost_grouptitle'], $values['customPost']) = self
::getProfileNameAndFields($postID, $userID, $params['custom_post_id']);
348 if (isset($values['honor'])) {
349 $honorValues = $values['honor'];
350 $template->_values
= array('honoree_profile_id' => $values['honoree_profile_id']);
351 CRM_Contribute_BAO_ContributionSoft
::formatHonoreeProfileFields(
353 $honorValues['honor_profile_values'],
354 $honorValues['honor_id']
358 $title = isset($values['title']) ?
$values['title'] : CRM_Contribute_PseudoConstant
::contributionPage($values['contribution_page_id']);
360 // Set email variables explicitly to avoid leaky smarty variables.
361 // All of these will be assigned to the template, replacing any that might be assigned elsewhere.
364 'receiptFromEmail' => CRM_Utils_Array
::value('receipt_from_email', $values),
365 'contactID' => $contactID,
366 'displayName' => $displayName,
367 'contributionID' => CRM_Utils_Array
::value('contribution_id', $values),
368 'contributionOtherID' => CRM_Utils_Array
::value('contribution_other_id', $values),
370 'lineItem' => CRM_Utils_Array
::value('lineItem', $values),
372 'priceSetID' => CRM_Utils_Array
::value('priceSetID', $values),
374 'isShare' => CRM_Utils_Array
::value('is_share', $values),
375 'thankyou_title' => CRM_Utils_Array
::value('thankyou_title', $values),
376 'customPre' => $values['customPre'],
377 'customPre_grouptitle' => $values['customPre_grouptitle'],
378 'customPost' => $values['customPost'],
379 'customPost_grouptitle' => $values['customPost_grouptitle'],
380 'useForMember' => $values['useForMember'],
381 'membership_assign' => $values['membership_assign'],
382 'amount' => $values['amount'],
385 if ($contributionTypeId = CRM_Utils_Array
::value('financial_type_id', $values)) {
386 $tplParams['financialTypeId'] = $contributionTypeId;
387 $tplParams['financialTypeName'] = CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_FinancialType',
388 $contributionTypeId);
390 $tplParams['contributionTypeName'] = $tplParams['financialTypeName'];
391 $tplParams['contributionTypeId'] = $contributionTypeId;
394 if ($contributionPageId = CRM_Utils_Array
::value('id', $values)) {
395 $tplParams['contributionPageId'] = $contributionPageId;
398 // address required during receipt processing (pdf and email receipt)
399 if ($displayAddress = CRM_Utils_Array
::value('address', $values)) {
400 $tplParams['address'] = $displayAddress;
404 $originalCCReceipt = CRM_Utils_Array
::value('cc_receipt', $values);
406 // cc to related contacts of contributor OR the one who
407 // signs up. Is used for cases like - on behalf of
408 // contribution / signup ..etc
409 if (array_key_exists('related_contact', $values)) {
410 list($ccDisplayName, $ccEmail) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($values['related_contact']);
411 $ccMailId = "{$ccDisplayName} <{$ccEmail}>";
413 //@todo - this is the only place in this function where $values is altered - but I can't find any evidence it is used
414 $values['cc_receipt'] = !empty($values['cc_receipt']) ?
($values['cc_receipt'] . ',' . $ccMailId) : $ccMailId;
416 // reset primary-email in the template
417 $tplParams['email'] = $ccEmail;
419 $tplParams['onBehalfName'] = $displayName;
420 $tplParams['onBehalfEmail'] = $email;
422 if (!empty($values['onbehalf_profile_id'])) {
423 self
::buildCustomDisplay($values['onbehalf_profile_id'], 'onBehalfProfile', $contactID, $template, $params['onbehalf_profile'], $fieldTypes);
427 // use either the contribution or membership receipt, based on whether it’s a membership-related contrib or not
428 $sendTemplateParams = array(
429 'groupName' => !empty($values['isMembership']) ?
'msg_tpl_workflow_membership' : 'msg_tpl_workflow_contribution',
430 'valueName' => !empty($values['isMembership']) ?
'membership_online_receipt' : 'contribution_online_receipt',
431 'contactId' => $contactID,
432 'tplParams' => $tplParams,
434 'PDFFilename' => 'receipt.pdf',
437 if ($returnMessageText) {
438 list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
440 'subject' => $subject,
442 'to' => $displayName,
447 if ($values['is_email_receipt']) {
448 $sendTemplateParams['from'] = CRM_Utils_Array
::value('receipt_from_name', $values) . ' <' . $values['receipt_from_email'] . '>';
449 $sendTemplateParams['toName'] = $displayName;
450 $sendTemplateParams['toEmail'] = $email;
451 $sendTemplateParams['cc'] = CRM_Utils_Array
::value('cc_receipt', $values);
452 $sendTemplateParams['bcc'] = CRM_Utils_Array
::value('bcc_receipt', $values);
453 //send email with pdf invoice
454 $template = CRM_Core_Smarty
::singleton();
455 $taxAmt = $template->get_template_vars('dataArray');
456 $prefixValue = Civi
::settings()->get('contribution_invoice_settings');
457 $invoicing = CRM_Utils_Array
::value('invoicing', $prefixValue);
458 if (isset($invoicing) && isset($prefixValue['is_email_pdf'])) {
459 $sendTemplateParams['isEmailPdf'] = TRUE;
460 $sendTemplateParams['contributionId'] = $values['contribution_id'];
462 list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
465 // send duplicate alert, if dupe match found during on-behalf-of processing.
466 if (!empty($values['onbehalf_dupe_alert'])) {
467 $sendTemplateParams['groupName'] = 'msg_tpl_workflow_contribution';
468 $sendTemplateParams['valueName'] = 'contribution_dupalert';
469 $sendTemplateParams['from'] = ts('Automatically Generated') . " <{$values['receipt_from_email']}>";
470 $sendTemplateParams['toName'] = CRM_Utils_Array
::value('receipt_from_name', $values);
471 $sendTemplateParams['toEmail'] = CRM_Utils_Array
::value('receipt_from_email', $values);
472 $sendTemplateParams['tplParams']['onBehalfID'] = $contactID;
473 $sendTemplateParams['tplParams']['receiptMessage'] = $message;
475 // fix cc and reset back to original, CRM-6976
476 $sendTemplateParams['cc'] = $originalCCReceipt;
478 CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
484 * Get the profile title and fields.
488 * @param array $params
489 * @param array $fieldTypes
493 protected static function getProfileNameAndFields($gid, $cid, &$params, $fieldTypes = array()) {
497 if (CRM_Core_BAO_UFGroup
::filterUFGroups($gid, $cid)) {
498 $fields = CRM_Core_BAO_UFGroup
::getFields($gid, FALSE, CRM_Core_Action
::VIEW
, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission
::CREATE
, NULL);
499 foreach ($fields as $k => $v) {
501 $groupTitle = $v["groupTitle"];
503 // suppress all file fields from display and formatting fields
505 CRM_Utils_Array
::value('data_type', $v, '') == 'File' ||
506 CRM_Utils_Array
::value('name', $v, '') == 'image_URL' ||
507 CRM_Utils_Array
::value('field_type', $v) == 'Formatting'
512 if (!empty($fieldTypes) && (!in_array($v['field_type'], $fieldTypes))) {
517 CRM_Core_BAO_UFGroup
::getValues($cid, $fields, $values, FALSE, $params);
520 return array($groupTitle, $values);
524 * Send the emails for Recurring Contribution Notification.
526 * @param string $type
528 * @param int $contactID
529 * Contact id for contributor.
531 * Contribution page id.
532 * @param object $recur
533 * Object of recurring contribution table.
534 * @param bool|object $autoRenewMembership is it a auto renew membership.
536 public static function recurringNotify($type, $contactID, $pageID, $recur, $autoRenewMembership = FALSE) {
538 $isEmailReceipt = FALSE;
540 CRM_Core_DAO
::commonRetrieveAll('CRM_Contribute_DAO_ContributionPage', 'id', $pageID, $value, array(
544 'receipt_from_email',
548 $isEmailReceipt = CRM_Utils_Array
::value('is_email_receipt', $value[$pageID]);
550 elseif ($recur->id
) {
551 // This means we are coming from back-office - ie. no page ID, but recurring.
552 // Ideally this information would be passed into the function clearly rather than guessing by convention.
553 $isEmailReceipt = TRUE;
556 if ($isEmailReceipt) {
558 $receiptFrom = '"' . CRM_Utils_Array
::value('receipt_from_name', $value[$pageID]) . '" <' . $value[$pageID]['receipt_from_email'] . '>';
560 $receiptFromName = $value[$pageID]['receipt_from_name'];
561 $receiptFromEmail = $value[$pageID]['receipt_from_email'];
564 $domainValues = CRM_Core_BAO_Domain
::getNameAndEmail();
565 $receiptFrom = "$domainValues[0] <$domainValues[1]>";
566 $receiptFromName = $domainValues[0];
567 $receiptFromEmail = $domainValues[1];
570 list($displayName, $email) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contactID, FALSE);
571 $templatesParams = array(
572 'groupName' => 'msg_tpl_workflow_contribution',
573 'valueName' => 'contribution_recurring_notify',
574 'contactId' => $contactID,
575 'tplParams' => array(
576 'recur_frequency_interval' => $recur->frequency_interval
,
577 'recur_frequency_unit' => $recur->frequency_unit
,
578 'recur_installments' => $recur->installments
,
579 'recur_start_date' => $recur->start_date
,
580 'recur_end_date' => $recur->end_date
,
581 'recur_amount' => $recur->amount
,
582 'recur_txnType' => $type,
583 'displayName' => $displayName,
584 'receipt_from_name' => $receiptFromName,
585 'receipt_from_email' => $receiptFromEmail,
586 'auto_renew_membership' => $autoRenewMembership,
588 'from' => $receiptFrom,
589 'toName' => $displayName,
594 $templatesParams['cc'] = CRM_Utils_Array
::value('cc_receipt', $value[$pageID]);
595 $templatesParams['bcc'] = CRM_Utils_Array
::value('bcc_receipt', $value[$pageID]);
598 // in some cases its just recurringNotify() thats called for the first time and these urls don't get set.
599 // like in PaypalPro, & therefore we set it here additionally.
600 $template = CRM_Core_Smarty
::singleton();
601 $paymentProcessor = CRM_Financial_BAO_PaymentProcessor
::getProcessorForEntity($recur->id
, 'recur', 'obj');
602 $url = $paymentProcessor->subscriptionURL($recur->id
, 'recur', 'cancel');
603 $template->assign('cancelSubscriptionUrl', $url);
605 $url = $paymentProcessor->subscriptionURL($recur->id
, 'recur', 'billing');
606 $template->assign('updateSubscriptionBillingUrl', $url);
608 $url = $paymentProcessor->subscriptionURL($recur->id
, 'recur', 'update');
609 $template->assign('updateSubscriptionUrl', $url);
612 list($sent) = CRM_Core_BAO_MessageTemplate
::sendTemplate($templatesParams);
615 CRM_Core_Error
::debug_log_message('Success: mail sent for recurring notification.');
618 CRM_Core_Error
::debug_log_message('Failure: mail not sent for recurring notification.');
624 * Add the custom fields for contribution page (ie profile).
626 * @deprecated assigning values to smarty like this is risky because
627 * - it is hard to debug since $name is used in the assign
628 * - it is potentially 'leaky' - it's better to do this on the form
629 * or close to where it is used / required. See CRM-17519 for leakage e.g.
633 * @param string $name
637 * @param array $params
638 * Params to build component whereclause.
640 * @param array|null $fieldTypes
642 public static function buildCustomDisplay($gid, $name, $cid, &$template, &$params, $fieldTypes = NULL) {
643 list($groupTitle, $values) = self
::getProfileNameAndFields($gid, $cid, $params, $fieldTypes);
644 if (!empty($values)) {
645 $template->assign($name, $values);
647 $template->assign($name . "_grouptitle", $groupTitle);
651 * Make a copy of a contribution page, including all the blocks in the page.
654 * The contribution page id to copy.
656 * @return CRM_Contribute_DAO_ContributionPage
658 public static function copy($id) {
661 'title' => ts('Copy of') . ' ',
664 $copy = &CRM_Core_DAO
::copyGeneric('CRM_Contribute_DAO_ContributionPage', array(
666 ), NULL, $fieldsFix);
668 //copying all the blocks pertaining to the contribution page
669 $copyPledgeBlock = &CRM_Core_DAO
::copyGeneric('CRM_Pledge_DAO_PledgeBlock', array(
671 'entity_table' => 'civicrm_contribution_page',
673 'entity_id' => $copy->id
,
676 $copyMembershipBlock = &CRM_Core_DAO
::copyGeneric('CRM_Member_DAO_MembershipBlock', array(
678 'entity_table' => 'civicrm_contribution_page',
680 'entity_id' => $copy->id
,
683 $copyUFJoin = &CRM_Core_DAO
::copyGeneric('CRM_Core_DAO_UFJoin', array(
685 'entity_table' => 'civicrm_contribution_page',
687 'entity_id' => $copy->id
,
690 $copyWidget = &CRM_Core_DAO
::copyGeneric('CRM_Contribute_DAO_Widget', array(
691 'contribution_page_id' => $id,
693 'contribution_page_id' => $copy->id
,
697 CRM_Price_BAO_PriceSet
::copyPriceSet('civicrm_contribution_page', $id, $copy->id
);
699 $copyTellFriend = &CRM_Core_DAO
::copyGeneric('CRM_Friend_DAO_Friend', array(
701 'entity_table' => 'civicrm_contribution_page',
703 'entity_id' => $copy->id
,
706 $copyPersonalCampaignPages = &CRM_Core_DAO
::copyGeneric('CRM_PCP_DAO_PCPBlock', array(
708 'entity_table' => 'civicrm_contribution_page',
710 'entity_id' => $copy->id
,
711 'target_entity_id' => $copy->id
,
714 $copyPremium = &CRM_Core_DAO
::copyGeneric('CRM_Contribute_DAO_Premium', array(
716 'entity_table' => 'civicrm_contribution_page',
718 'entity_id' => $copy->id
,
722 FROM civicrm_premiums
723 WHERE entity_table = 'civicrm_contribution_page'
724 AND entity_id ={$id}";
726 $premiumDao = CRM_Core_DAO
::executeQuery($premiumQuery, CRM_Core_DAO
::$_nullArray);
727 while ($premiumDao->fetch()) {
728 if ($premiumDao->id
) {
729 CRM_Core_DAO
::copyGeneric('CRM_Contribute_DAO_PremiumsProduct', array(
730 'premiums_id' => $premiumDao->id
,
732 'premiums_id' => $copyPremium->id
,
739 CRM_Utils_Hook
::copy('ContributionPage', $copy);
745 * Get info for all sections enable/disable.
747 * @param array $contribPageIds
749 * info regarding all sections.
751 public static function getSectionInfo($contribPageIds = array()) {
754 if (is_array($contribPageIds) && !empty($contribPageIds)) {
755 $whereClause = 'WHERE civicrm_contribution_page.id IN ( ' . implode(', ', $contribPageIds) . ' )';
770 SELECT civicrm_contribution_page.id as id,
771 civicrm_contribution_page.financial_type_id as settings,
772 amount_block_is_active as amount,
773 civicrm_membership_block.id as membership,
774 civicrm_uf_join.id as custom,
775 civicrm_contribution_page.thankyou_title as thankyou,
776 civicrm_tell_friend.id as friend,
777 civicrm_pcp_block.id as pcp,
778 civicrm_contribution_widget.id as widget,
779 civicrm_premiums.id as premium
780 FROM civicrm_contribution_page
781 LEFT JOIN civicrm_membership_block ON ( civicrm_membership_block.entity_id = civicrm_contribution_page.id
782 AND civicrm_membership_block.entity_table = 'civicrm_contribution_page'
783 AND civicrm_membership_block.is_active = 1 )
784 LEFT JOIN civicrm_uf_join ON ( civicrm_uf_join.entity_id = civicrm_contribution_page.id
785 AND civicrm_uf_join.entity_table = 'civicrm_contribution_page'
786 AND module = 'CiviContribute'
787 AND civicrm_uf_join.is_active = 1 )
788 LEFT JOIN civicrm_tell_friend ON ( civicrm_tell_friend.entity_id = civicrm_contribution_page.id
789 AND civicrm_tell_friend.entity_table = 'civicrm_contribution_page'
790 AND civicrm_tell_friend.is_active = 1)
791 LEFT JOIN civicrm_pcp_block ON ( civicrm_pcp_block.entity_id = civicrm_contribution_page.id
792 AND civicrm_pcp_block.entity_table = 'civicrm_contribution_page'
793 AND civicrm_pcp_block.is_active = 1 )
794 LEFT JOIN civicrm_contribution_widget ON ( civicrm_contribution_widget.contribution_page_id = civicrm_contribution_page.id
795 AND civicrm_contribution_widget.is_active = 1 )
796 LEFT JOIN civicrm_premiums ON ( civicrm_premiums.entity_id = civicrm_contribution_page.id
797 AND civicrm_premiums.entity_table = 'civicrm_contribution_page'
798 AND civicrm_premiums.premiums_active = 1 )
801 $contributionPage = CRM_Core_DAO
::executeQuery($query);
802 while ($contributionPage->fetch()) {
803 if (!isset($info[$contributionPage->id
]) ||
!is_array($info[$contributionPage->id
])) {
804 $info[$contributionPage->id
] = array_fill_keys(array_values($sections), FALSE);
806 foreach ($sections as $section) {
807 if ($contributionPage->$section) {
808 $info[$contributionPage->id
][$section] = TRUE;
817 * Get options for a given field.
818 * @see CRM_Core_DAO::buildOptions
820 * @param string $fieldName
821 * @param string $context : @see CRM_Core_DAO::buildOptionsContext
822 * @param array $props : whatever is known about this dao object
826 public static function buildOptions($fieldName, $context = NULL, $props = array()) {
828 // Special logic for fields whose options depend on context or properties
829 switch ($fieldName) {
830 case 'financial_type_id':
831 // Fixme - this is going to ignore context, better to get conditions, add params, and call PseudoConstant::get
832 return CRM_Financial_BAO_FinancialType
::getIncomeFinancialType();
836 return CRM_Core_PseudoConstant
::get(__CLASS__
, $fieldName, $params, $context);
840 * Get or Set honor/on_behalf params for processing module_data or setting default values.
842 * @param array $params :
843 * @param bool $setDefault : If yes then returns array to used for setting default value afterward
844 * @param string $module : processing module_data for which module? e.g. soft_credit, on_behalf
846 * @return array|string
848 public static function formatModuleData($params, $setDefault = FALSE, $module) {
850 $config = CRM_Core_Config
::singleton();
851 $json = $jsonDecode = NULL;
852 $domain = new CRM_Core_DAO_Domain();
855 $moduleDataFormat = array(
856 'soft_credit' => array(
857 1 => 'soft_credit_types',
858 'multilingual' => array(
863 'on_behalf' => array(
864 1 => 'is_for_organization',
865 'multilingual' => array(
871 //When we are fetching the honor params respecting both multi and mono lingual state
872 //and setting it to default param of Contribution Page's Main and Setting form
874 $jsonDecode = json_decode($params);
875 $jsonDecode = (array) $jsonDecode->$module;
876 if (!$domain->locales
&& !empty($jsonDecode['default'])) {
878 $jsonDecode +
= (array) $jsonDecode['default'];
879 unset($jsonDecode['default']);
881 elseif (!empty($jsonDecode[$tsLocale])) {
883 foreach ($jsonDecode[$tsLocale] as $column => $value) {
884 $jsonDecode[$column] = $value;
886 unset($jsonDecode[$tsLocale]);
891 //check and handle multilingual honoree params
892 if (!$domain->locales
) {
893 //if in singlelingual state simply return the array format
894 $json = array($module => NULL);
895 foreach ($moduleDataFormat[$module] as $key => $attribute) {
896 if ($key === 'multilingual') {
897 $json[$module]['default'] = array();
898 foreach ($attribute as $attr) {
899 $json[$module]['default'][$attr] = $params[$attr];
903 $json[$module][$attribute] = $params[$attribute];
906 $json = json_encode($json);
909 //if in multilingual state then retrieve the module_data against this contribution and
910 //merge with earlier module_data json data to current so not to lose earlier multilingual module_data information
911 $json = array($module => NULL);
912 foreach ($moduleDataFormat[$module] as $key => $attribute) {
913 if ($key === 'multilingual') {
914 $json[$module][$config->lcMessages
] = array();
915 foreach ($attribute as $attr) {
916 $json[$module][$config->lcMessages
][$attr] = $params[$attr];
920 $json[$module][$attribute] = $params[$attribute];
924 $ufJoinDAO = new CRM_Core_DAO_UFJoin();
925 $ufJoinDAO->module
= $module;
926 $ufJoinDAO->entity_id
= $params['id'];
927 $ufJoinDAO->find(TRUE);
928 $jsonData = json_decode($ufJoinDAO->module_data
);
930 $json[$module] = array_merge((array) $jsonData->$module, $json[$module]);
932 $json = json_encode($json);
938 * Generate html for pdf in confirmation receipt email attachment.
939 * @param int $contributionId
940 * Contribution Page Id.
942 * Contact id for contributor.
945 public static function addInvoicePdfToEmail($contributionId, $userID) {
946 $contributionID = array($contributionId);
947 $contactId = array($userID);
949 'output' => 'pdf_invoice',
950 'forPage' => 'confirmpage',
952 $pdfHtml = CRM_Contribute_Form_Task_Invoice
::printPDF($contributionID,
953 $pdfParams, $contactId, CRM_Core_DAO
::$_nullObject);
958 * Helper to determine if the page supports separate membership payments.
960 * @param int $id form id
963 * isSeparateMembershipPayment
965 public static function getIsMembershipPayment($id) {
966 $membershipBlocks = civicrm_api3('membership_block', 'get', array(
967 'entity_table' => 'civicrm_contribution_page',
969 'sequential' => TRUE,
971 if (!$membershipBlocks['count']) {
974 return $membershipBlocks['values'][0]['is_separate_payment'];