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) {
153 $gIds = $params = array();
155 if (isset($values['custom_pre_id'])) {
156 $preProfileType = CRM_Core_BAO_UFField
::getProfileType($values['custom_pre_id']);
157 if ($preProfileType == 'Membership' && !empty($values['membership_id'])) {
158 $params['custom_pre_id'] = array(
162 $values['membership_id'],
168 elseif ($preProfileType == 'Contribution' && !empty($values['contribution_id'])) {
169 $params['custom_pre_id'] = array(
173 $values['contribution_id'],
180 $gIds['custom_pre_id'] = $values['custom_pre_id'];
183 if (isset($values['custom_post_id'])) {
184 $postProfileType = CRM_Core_BAO_UFField
::getProfileType($values['custom_post_id']);
185 if ($postProfileType == 'Membership' && !empty($values['membership_id'])) {
186 $params['custom_post_id'] = array(
190 $values['membership_id'],
196 elseif ($postProfileType == 'Contribution' && !empty($values['contribution_id'])) {
197 $params['custom_post_id'] = array(
201 $values['contribution_id'],
208 $gIds['custom_post_id'] = $values['custom_post_id'];
211 if (!empty($values['is_for_organization'])) {
212 if (!empty($values['membership_id'])) {
213 $params['onbehalf_profile'] = array(
217 $values['membership_id'],
223 elseif (!empty($values['contribution_id'])) {
224 $params['onbehalf_profile'] = array(
228 $values['contribution_id'],
236 //check whether it is a test drive
237 if ($isTest && !empty($params['custom_pre_id'])) {
238 $params['custom_pre_id'][] = array(
247 if ($isTest && !empty($params['custom_post_id'])) {
248 $params['custom_post_id'][] = array(
257 if (!$returnMessageText && !empty($gIds)) {
258 //send notification email if field values are set (CRM-1941)
259 foreach ($gIds as $key => $gId) {
261 $email = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup', $gId, 'notify');
263 $val = CRM_Core_BAO_UFGroup
::checkFieldsEmptyValues($gId, $contactID, CRM_Utils_Array
::value($key, $params), TRUE);
264 CRM_Core_BAO_UFGroup
::commonSendMail($contactID, $val);
270 if (!empty($values['is_email_receipt']) ||
!empty($values['onbehalf_dupe_alert']) ||
273 $template = CRM_Core_Smarty
::singleton();
275 // get the billing location type
276 if (!array_key_exists('related_contact', $values)) {
277 $locationTypes = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
278 $billingLocationTypeId = array_search('Billing', $locationTypes);
281 // presence of related contact implies onbehalf of org case,
282 // where location type is set to default.
283 $locType = CRM_Core_BAO_LocationType
::getDefault();
284 $billingLocationTypeId = $locType->id
;
287 if (!array_key_exists('related_contact', $values)) {
288 list($displayName, $email) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contactID, FALSE, $billingLocationTypeId);
290 // get primary location email if no email exist( for billing location).
292 list($displayName, $email) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contactID);
294 if (empty($displayName)) {
295 list($displayName, $email) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contactID);
298 //for display profile need to get individual contact id,
299 //hence get it from related_contact if on behalf of org true CRM-3767
300 //CRM-5001 Contribution/Membership:: On Behalf of Organization,
301 //If profile GROUP contain the Individual type then consider the
302 //profile is of Individual ( including the custom data of membership/contribution )
303 //IF Individual type not present in profile then it is consider as Organization data.
304 $userID = $contactID;
305 if ($preID = CRM_Utils_Array
::value('custom_pre_id', $values)) {
306 if (!empty($values['related_contact'])) {
307 $preProfileTypes = CRM_Core_BAO_UFGroup
::profileGroups($preID);
308 //@todo - following line should not refer to undefined $postProfileTypes? figure out way to test
309 if (in_array('Individual', $preProfileTypes) ||
in_array('Contact', $postProfileTypes)) {
310 //Take Individual contact ID
311 $userID = CRM_Utils_Array
::value('related_contact', $values);
314 self
::buildCustomDisplay($preID, 'customPre', $userID, $template, $params['custom_pre_id']);
316 $userID = $contactID;
317 if ($postID = CRM_Utils_Array
::value('custom_post_id', $values)) {
318 if (!empty($values['related_contact'])) {
319 $postProfileTypes = CRM_Core_BAO_UFGroup
::profileGroups($postID);
320 if (in_array('Individual', $postProfileTypes) ||
in_array('Contact', $postProfileTypes)) {
321 //Take Individual contact ID
322 $userID = CRM_Utils_Array
::value('related_contact', $values);
325 self
::buildCustomDisplay($postID, 'customPost', $userID, $template, $params['custom_post_id']);
327 if (isset($values['honor'])) {
328 $honorValues = $values['honor'];
329 $template->_values
= array('honoree_profile_id' => $values['honoree_profile_id']);
330 CRM_Contribute_BAO_ContributionSoft
::formatHonoreeProfileFields(
332 $honorValues['honor_profile_values'],
333 $honorValues['honor_id']
337 $title = isset($values['title']) ?
$values['title'] : CRM_Contribute_PseudoConstant
::contributionPage($values['contribution_page_id']);
339 // set email in the template here
342 'receiptFromEmail' => CRM_Utils_Array
::value('receipt_from_email', $values),
343 'contactID' => $contactID,
344 'displayName' => $displayName,
345 'contributionID' => CRM_Utils_Array
::value('contribution_id', $values),
346 'contributionOtherID' => CRM_Utils_Array
::value('contribution_other_id', $values),
348 'lineItem' => CRM_Utils_Array
::value('lineItem', $values),
350 'priceSetID' => CRM_Utils_Array
::value('priceSetID', $values),
352 'isShare' => CRM_Utils_Array
::value('is_share', $values),
353 'thankyou_title' => CRM_Utils_Array
::value('thankyou_title', $values),
356 if ($contributionTypeId = CRM_Utils_Array
::value('financial_type_id', $values)) {
357 $tplParams['contributionTypeId'] = $contributionTypeId;
358 $tplParams['contributionTypeName'] = CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_FinancialType',
359 $contributionTypeId);
362 if ($contributionPageId = CRM_Utils_Array
::value('id', $values)) {
363 $tplParams['contributionPageId'] = $contributionPageId;
366 // address required during receipt processing (pdf and email receipt)
367 if ($displayAddress = CRM_Utils_Array
::value('address', $values)) {
368 $tplParams['address'] = $displayAddress;
372 $originalCCReceipt = CRM_Utils_Array
::value('cc_receipt', $values);
374 // cc to related contacts of contributor OR the one who
375 // signs up. Is used for cases like - on behalf of
376 // contribution / signup ..etc
377 if (array_key_exists('related_contact', $values)) {
378 list($ccDisplayName, $ccEmail) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($values['related_contact']);
379 $ccMailId = "{$ccDisplayName} <{$ccEmail}>";
381 //@todo - this is the only place in this function where $values is altered - but I can't find any evidence it is used
382 $values['cc_receipt'] = !empty($values['cc_receipt']) ?
($values['cc_receipt'] . ',' . $ccMailId) : $ccMailId;
384 // reset primary-email in the template
385 $tplParams['email'] = $ccEmail;
387 $tplParams['onBehalfName'] = $displayName;
388 $tplParams['onBehalfEmail'] = $email;
390 if (!empty($values['onbehalf_profile_id'])) {
391 self
::buildCustomDisplay($values['onbehalf_profile_id'], 'onBehalfProfile', $contactID, $template, $params['onbehalf_profile'], $fieldTypes);
395 // use either the contribution or membership receipt, based on whether it’s a membership-related contrib or not
396 $sendTemplateParams = array(
397 'groupName' => !empty($values['isMembership']) ?
'msg_tpl_workflow_membership' : 'msg_tpl_workflow_contribution',
398 'valueName' => !empty($values['isMembership']) ?
'membership_online_receipt' : 'contribution_online_receipt',
399 'contactId' => $contactID,
400 'tplParams' => $tplParams,
402 'PDFFilename' => 'receipt.pdf',
405 if ($returnMessageText) {
406 list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
408 'subject' => $subject,
410 'to' => $displayName,
415 if ($values['is_email_receipt']) {
416 $sendTemplateParams['from'] = CRM_Utils_Array
::value('receipt_from_name', $values) . ' <' . $values['receipt_from_email'] . '>';
417 $sendTemplateParams['toName'] = $displayName;
418 $sendTemplateParams['toEmail'] = $email;
419 $sendTemplateParams['cc'] = CRM_Utils_Array
::value('cc_receipt', $values);
420 $sendTemplateParams['bcc'] = CRM_Utils_Array
::value('bcc_receipt', $values);
421 //send email with pdf invoice
422 $template = CRM_Core_Smarty
::singleton();
423 $taxAmt = $template->get_template_vars('dataArray');
424 $prefixValue = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
, 'contribution_invoice_settings');
425 $invoicing = CRM_Utils_Array
::value('invoicing', $prefixValue);
426 if (isset($invoicing) && isset($prefixValue['is_email_pdf'])) {
427 $sendTemplateParams['isEmailPdf'] = TRUE;
428 $sendTemplateParams['contributionId'] = $values['contribution_id'];
430 list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
433 // send duplicate alert, if dupe match found during on-behalf-of processing.
434 if (!empty($values['onbehalf_dupe_alert'])) {
435 $sendTemplateParams['groupName'] = 'msg_tpl_workflow_contribution';
436 $sendTemplateParams['valueName'] = 'contribution_dupalert';
437 $sendTemplateParams['from'] = ts('Automatically Generated') . " <{$values['receipt_from_email']}>";
438 $sendTemplateParams['toName'] = CRM_Utils_Array
::value('receipt_from_name', $values);
439 $sendTemplateParams['toEmail'] = CRM_Utils_Array
::value('receipt_from_email', $values);
440 $sendTemplateParams['tplParams']['onBehalfID'] = $contactID;
441 $sendTemplateParams['tplParams']['receiptMessage'] = $message;
443 // fix cc and reset back to original, CRM-6976
444 $sendTemplateParams['cc'] = $originalCCReceipt;
446 CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
452 * Send the emails for Recurring Contribution Notification.
454 * @param string $type
456 * @param int $contactID
457 * Contact id for contributor.
459 * Contribution page id.
460 * @param object $recur
461 * Object of recurring contribution table.
462 * @param bool|object $autoRenewMembership is it a auto renew membership.
464 public static function recurringNotify($type, $contactID, $pageID, $recur, $autoRenewMembership = FALSE) {
466 $isEmailReceipt = FALSE;
468 CRM_Core_DAO
::commonRetrieveAll('CRM_Contribute_DAO_ContributionPage', 'id', $pageID, $value, array(
472 'receipt_from_email',
476 $isEmailReceipt = CRM_Utils_Array
::value('is_email_receipt', $value[$pageID]);
478 elseif ($recur->id
) {
479 // This means we are coming from back-office - ie. no page ID, but recurring.
480 // Ideally this information would be passed into the function clearly rather than guessing by convention.
481 $isEmailReceipt = TRUE;
484 if ($isEmailReceipt) {
486 $receiptFrom = '"' . CRM_Utils_Array
::value('receipt_from_name', $value[$pageID]) . '" <' . $value[$pageID]['receipt_from_email'] . '>';
488 $receiptFromName = $value[$pageID]['receipt_from_name'];
489 $receiptFromEmail = $value[$pageID]['receipt_from_email'];
492 $domainValues = CRM_Core_BAO_Domain
::getNameAndEmail();
493 $receiptFrom = "$domainValues[0] <$domainValues[1]>";
494 $receiptFromName = $domainValues[0];
495 $receiptFromEmail = $domainValues[1];
498 list($displayName, $email) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contactID, FALSE);
499 $templatesParams = array(
500 'groupName' => 'msg_tpl_workflow_contribution',
501 'valueName' => 'contribution_recurring_notify',
502 'contactId' => $contactID,
503 'tplParams' => array(
504 'recur_frequency_interval' => $recur->frequency_interval
,
505 'recur_frequency_unit' => $recur->frequency_unit
,
506 'recur_installments' => $recur->installments
,
507 'recur_start_date' => $recur->start_date
,
508 'recur_end_date' => $recur->end_date
,
509 'recur_amount' => $recur->amount
,
510 'recur_txnType' => $type,
511 'displayName' => $displayName,
512 'receipt_from_name' => $receiptFromName,
513 'receipt_from_email' => $receiptFromEmail,
514 'auto_renew_membership' => $autoRenewMembership,
516 'from' => $receiptFrom,
517 'toName' => $displayName,
522 $templatesParams['cc'] = CRM_Utils_Array
::value('cc_receipt', $value[$pageID]);
523 $templatesParams['bcc'] = CRM_Utils_Array
::value('bcc_receipt', $value[$pageID]);
526 // in some cases its just recurringNotify() thats called for the first time and these urls don't get set.
527 // like in PaypalPro, & therefore we set it here additionally.
528 $template = CRM_Core_Smarty
::singleton();
529 $paymentProcessor = CRM_Financial_BAO_PaymentProcessor
::getProcessorForEntity($recur->id
, 'recur', 'obj');
530 $url = $paymentProcessor->subscriptionURL($recur->id
, 'recur');
531 $template->assign('cancelSubscriptionUrl', $url);
533 $url = $paymentProcessor->subscriptionURL($recur->id
, 'recur', 'billing');
534 $template->assign('updateSubscriptionBillingUrl', $url);
536 $url = $paymentProcessor->subscriptionURL($recur->id
, 'recur', 'update');
537 $template->assign('updateSubscriptionUrl', $url);
540 list($sent) = CRM_Core_BAO_MessageTemplate
::sendTemplate($templatesParams);
543 CRM_Core_Error
::debug_log_message('Success: mail sent for recurring notification.');
546 CRM_Core_Error
::debug_log_message('Failure: mail not sent for recurring notification.');
552 * Add the custom fields for contribution page (ie profile)
556 * @param string $name
560 * @param array $params
561 * Params to build component whereclause.
563 * @param array $fieldTypes
565 public static function buildCustomDisplay($gid, $name, $cid, &$template, &$params, $fieldTypes = array()) {
567 if (CRM_Core_BAO_UFGroup
::filterUFGroups($gid, $cid)) {
570 $fields = CRM_Core_BAO_UFGroup
::getFields($gid, FALSE, CRM_Core_Action
::VIEW
, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission
::CREATE
, NULL);
571 foreach ($fields as $k => $v) {
573 $groupTitle = $v["groupTitle"];
575 // suppress all file fields from display and formatting fields
577 CRM_Utils_Array
::value('data_type', $v, '') == 'File' ||
578 CRM_Utils_Array
::value('name', $v, '') == 'image_URL' ||
579 CRM_Utils_Array
::value('field_type', $v) == 'Formatting'
584 if (!empty($fieldTypes) && (!in_array($v['field_type'], $fieldTypes))) {
590 $template->assign($name . "_grouptitle", $groupTitle);
593 CRM_Core_BAO_UFGroup
::getValues($cid, $fields, $values, FALSE, $params);
595 if (count($values)) {
596 $template->assign($name, $values);
603 * Make a copy of a contribution page, including all the blocks in the page.
606 * The contribution page id to copy.
608 * @return CRM_Contribute_DAO_ContributionPage
610 public static function copy($id) {
613 'title' => ts('Copy of') . ' ',
616 $copy = &CRM_Core_DAO
::copyGeneric('CRM_Contribute_DAO_ContributionPage', array(
618 ), NULL, $fieldsFix);
620 //copying all the blocks pertaining to the contribution page
621 $copyPledgeBlock = &CRM_Core_DAO
::copyGeneric('CRM_Pledge_DAO_PledgeBlock', array(
623 'entity_table' => 'civicrm_contribution_page',
625 'entity_id' => $copy->id
,
628 $copyMembershipBlock = &CRM_Core_DAO
::copyGeneric('CRM_Member_DAO_MembershipBlock', array(
630 'entity_table' => 'civicrm_contribution_page',
632 'entity_id' => $copy->id
,
635 $copyUFJoin = &CRM_Core_DAO
::copyGeneric('CRM_Core_DAO_UFJoin', array(
637 'entity_table' => 'civicrm_contribution_page',
639 'entity_id' => $copy->id
,
642 $copyWidget = &CRM_Core_DAO
::copyGeneric('CRM_Contribute_DAO_Widget', array(
643 'contribution_page_id' => $id,
645 'contribution_page_id' => $copy->id
,
649 CRM_Price_BAO_PriceSet
::copyPriceSet('civicrm_contribution_page', $id, $copy->id
);
651 $copyTellFriend = &CRM_Core_DAO
::copyGeneric('CRM_Friend_DAO_Friend', array(
653 'entity_table' => 'civicrm_contribution_page',
655 'entity_id' => $copy->id
,
658 $copyPersonalCampaignPages = &CRM_Core_DAO
::copyGeneric('CRM_PCP_DAO_PCPBlock', array(
660 'entity_table' => 'civicrm_contribution_page',
662 'entity_id' => $copy->id
,
663 'target_entity_id' => $copy->id
,
666 $copyPremium = &CRM_Core_DAO
::copyGeneric('CRM_Contribute_DAO_Premium', array(
668 'entity_table' => 'civicrm_contribution_page',
670 'entity_id' => $copy->id
,
674 FROM civicrm_premiums
675 WHERE entity_table = 'civicrm_contribution_page'
676 AND entity_id ={$id}";
678 $premiumDao = CRM_Core_DAO
::executeQuery($premiumQuery, CRM_Core_DAO
::$_nullArray);
679 while ($premiumDao->fetch()) {
680 if ($premiumDao->id
) {
681 CRM_Core_DAO
::copyGeneric('CRM_Contribute_DAO_PremiumsProduct', array(
682 'premiums_id' => $premiumDao->id
,
684 'premiums_id' => $copyPremium->id
,
691 CRM_Utils_Hook
::copy('ContributionPage', $copy);
697 * Get info for all sections enable/disable.
699 * @param array $contribPageIds
701 * info regarding all sections.
703 public static function getSectionInfo($contribPageIds = array()) {
706 if (is_array($contribPageIds) && !empty($contribPageIds)) {
707 $whereClause = 'WHERE civicrm_contribution_page.id IN ( ' . implode(', ', $contribPageIds) . ' )';
722 SELECT civicrm_contribution_page.id as id,
723 civicrm_contribution_page.financial_type_id as settings,
724 amount_block_is_active as amount,
725 civicrm_membership_block.id as membership,
726 civicrm_uf_join.id as custom,
727 civicrm_contribution_page.thankyou_title as thankyou,
728 civicrm_tell_friend.id as friend,
729 civicrm_pcp_block.id as pcp,
730 civicrm_contribution_widget.id as widget,
731 civicrm_premiums.id as premium
732 FROM civicrm_contribution_page
733 LEFT JOIN civicrm_membership_block ON ( civicrm_membership_block.entity_id = civicrm_contribution_page.id
734 AND civicrm_membership_block.entity_table = 'civicrm_contribution_page'
735 AND civicrm_membership_block.is_active = 1 )
736 LEFT JOIN civicrm_uf_join ON ( civicrm_uf_join.entity_id = civicrm_contribution_page.id
737 AND civicrm_uf_join.entity_table = 'civicrm_contribution_page'
738 AND module = 'CiviContribute'
739 AND civicrm_uf_join.is_active = 1 )
740 LEFT JOIN civicrm_tell_friend ON ( civicrm_tell_friend.entity_id = civicrm_contribution_page.id
741 AND civicrm_tell_friend.entity_table = 'civicrm_contribution_page'
742 AND civicrm_tell_friend.is_active = 1)
743 LEFT JOIN civicrm_pcp_block ON ( civicrm_pcp_block.entity_id = civicrm_contribution_page.id
744 AND civicrm_pcp_block.entity_table = 'civicrm_contribution_page'
745 AND civicrm_pcp_block.is_active = 1 )
746 LEFT JOIN civicrm_contribution_widget ON ( civicrm_contribution_widget.contribution_page_id = civicrm_contribution_page.id
747 AND civicrm_contribution_widget.is_active = 1 )
748 LEFT JOIN civicrm_premiums ON ( civicrm_premiums.entity_id = civicrm_contribution_page.id
749 AND civicrm_premiums.entity_table = 'civicrm_contribution_page'
750 AND civicrm_premiums.premiums_active = 1 )
753 $contributionPage = CRM_Core_DAO
::executeQuery($query);
754 while ($contributionPage->fetch()) {
755 if (!isset($info[$contributionPage->id
]) ||
!is_array($info[$contributionPage->id
])) {
756 $info[$contributionPage->id
] = array_fill_keys(array_values($sections), FALSE);
758 foreach ($sections as $section) {
759 if ($contributionPage->$section) {
760 $info[$contributionPage->id
][$section] = TRUE;
769 * Get options for a given field.
770 * @see CRM_Core_DAO::buildOptions
772 * @param string $fieldName
773 * @param string $context : @see CRM_Core_DAO::buildOptionsContext
774 * @param array $props : whatever is known about this dao object
778 public static function buildOptions($fieldName, $context = NULL, $props = array()) {
780 // Special logic for fields whose options depend on context or properties
781 switch ($fieldName) {
782 case 'financial_type_id':
783 // Fixme - this is going to ignore context, better to get conditions, add params, and call PseudoConstant::get
784 return CRM_Financial_BAO_FinancialType
::getIncomeFinancialType();
788 return CRM_Core_PseudoConstant
::get(__CLASS__
, $fieldName, $params, $context);
792 * Get or Set honor/on_behalf params for processing module_data or setting default values.
794 * @param array $params :
795 * @param bool $setDefault : If yes then returns array to used for setting default value afterward
796 * @param string $module : processing module_data for which module? e.g. soft_credit, on_behalf
798 * @return array|string
800 public static function formatModuleData($params, $setDefault = FALSE, $module) {
801 $config = CRM_Core_Config
::singleton();
802 $json = $jsonDecode = NULL;
803 $domain = new CRM_Core_DAO_Domain();
806 $moduleDataFormat = array(
807 'soft_credit' => array(
808 1 => 'soft_credit_types',
809 'multilingual' => array(
814 'on_behalf' => array(
815 1 => 'is_for_organization',
816 'multilingual' => array(
822 //When we are fetching the honor params respecting both multi and mono lingual state
823 //and setting it to default param of Contribution Page's Main and Setting form
825 $jsonDecode = json_decode($params);
826 $jsonDecode = (array) $jsonDecode->$module;
827 if (!$domain->locales
&& !empty($jsonDecode['default'])) {
829 $jsonDecode +
= (array) $jsonDecode['default'];
830 unset($jsonDecode['default']);
832 elseif (!empty($jsonDecode[$config->lcMessages
])) {
834 foreach ($jsonDecode[$config->lcMessages
] as $column => $value) {
835 $jsonDecode[$column] = $value;
837 unset($jsonDecode[$config->lcMessages
]);
842 //check and handle multilingual honoree params
843 if (!$domain->locales
) {
844 //if in singlelingual state simply return the array format
845 $json = array($module => NULL);
846 foreach ($moduleDataFormat[$module] as $key => $attribute) {
847 if ($key === 'multilingual') {
848 $json[$module]['default'] = array();
849 foreach ($attribute as $attr) {
850 $json[$module]['default'][$attr] = $params[$attr];
854 $json[$module][$attribute] = $params[$attribute];
857 $json = json_encode($json);
860 //if in multilingual state then retrieve the module_data against this contribution and
861 //merge with earlier module_data json data to current so not to lose earlier multilingual module_data information
862 $json = array($module => NULL);
863 foreach ($moduleDataFormat[$module] as $key => $attribute) {
864 if ($key === 'multilingual') {
865 $json[$module][$config->lcMessages
] = array();
866 foreach ($attribute as $attr) {
867 $json[$module][$config->lcMessages
][$attr] = $params[$attr];
871 $json[$module][$attribute] = $params[$attribute];
875 $ufJoinDAO = new CRM_Core_DAO_UFJoin();
876 $ufJoinDAO->module
= $module;
877 $ufJoinDAO->entity_id
= $params['id'];
878 $ufJoinDAO->find(TRUE);
879 $jsonData = json_decode($ufJoinDAO->module_data
);
881 $json[$module] = array_merge((array) $jsonData->$module, $json[$module]);
883 $json = json_encode($json);
889 * Generate html for pdf in confirmation receipt email attachment.
890 * @param int $contributionId
891 * Contribution Page Id.
893 * Contact id for contributor.
896 public static function addInvoicePdfToEmail($contributionId, $userID) {
897 $contributionID = array($contributionId);
898 $contactId = array($userID);
900 'output' => 'pdf_invoice',
901 'forPage' => 'confirmpage',
903 $pdfHtml = CRM_Contribute_Form_Task_Invoice
::printPDF($contributionID,
904 $pdfParams, $contactId, CRM_Core_DAO
::$_nullObject);
909 * Helper to determine if the page supports separate membership payments.
911 * @param int $id form id
914 * isSeparateMembershipPayment
916 public static function getIsMembershipPayment($id) {
917 $membershipBlocks = civicrm_api3('membership_block', 'get', array(
918 'entity_table' => 'civicrm_contribution_page',
920 'sequential' => TRUE,
922 if (!$membershipBlocks['count']) {
925 return $membershipBlocks['values'][0]['is_separate_payment'];