3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
37 * This class contains Contribution Page related functions.
39 class CRM_Contribute_BAO_ContributionPage
extends CRM_Contribute_DAO_ContributionPage
{
42 * Takes an associative array and creates a contribution page object
44 * @param array $params
45 * (reference ) an assoc array of name/value pairs.
47 * @return CRM_Contribute_DAO_ContributionPage
49 public static function &create(&$params) {
50 $financialTypeId = NULL;
51 if (!empty($params['id']) && !CRM_Price_BAO_PriceSet
::getFor('civicrm_contribution_page', $params['id'], NULL, 1)) {
52 $financialTypeId = CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_ContributionPage', $params['id'], 'financial_type_id');
54 $hook = empty($params['id']) ?
'create' : 'edit';
55 CRM_Utils_Hook
::pre($hook, 'ContributionPage', CRM_Utils_Array
::value('id', $params), $params);
56 $dao = new CRM_Contribute_DAO_ContributionPage();
57 $dao->copyValues($params);
59 if ($financialTypeId && !empty($params['financial_type_id']) && $financialTypeId != $params['financial_type_id']) {
60 CRM_Price_BAO_PriceFieldValue
::updateFinancialType($params['id'], 'civicrm_contribution_page', $params['financial_type_id']);
62 CRM_Utils_Hook
::post($hook, 'ContributionPage', $dao->id
, $dao);
67 * Update the is_active flag in the db
70 * Id of the database record.
71 * @param bool $is_active
72 * Value we want to set the is_active field.
75 * DAO object on success, null otherwise
77 public static function setIsActive($id, $is_active) {
78 return CRM_Core_DAO
::setFieldValue('CRM_Contribute_DAO_ContributionPage', $id, 'is_active', $is_active);
85 public static function setValues($id, &$values) {
90 CRM_Core_DAO
::commonRetrieve('CRM_Contribute_DAO_ContributionPage', $params, $values);
92 // get the profile ids
93 $ufJoinParams = array(
94 'module' => 'CiviContribute',
95 'entity_table' => 'civicrm_contribution_page',
98 list($values['custom_pre_id'], $customPostIds) = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
100 if (!empty($customPostIds)) {
101 $values['custom_post_id'] = $customPostIds[0];
104 $values['custom_post_id'] = '';
106 // // add an accounting code also
107 // if ($values ['financial_type_id']) {
108 // $values ['accountingCode'] = CRM_Core_DAO::getFieldValue( 'CRM_Financial_DAO_FinancialType', $values ['financial_type_id'], 'accounting_code' );
115 * @param int $contactID
117 * @param array $values
118 * Associated array of fields.
119 * @param bool $isTest
121 * @param bool $returnMessageText
122 * Return the message text instead of sending the mail.
124 * @param null $fieldTypes
128 public static function sendMail($contactID, $values, $isTest = FALSE, $returnMessageText = FALSE, $fieldTypes = NULL) {
129 $gIds = $params = array();
131 if (isset($values['custom_pre_id'])) {
132 $preProfileType = CRM_Core_BAO_UFField
::getProfileType($values['custom_pre_id']);
133 if ($preProfileType == 'Membership' && !empty($values['membership_id'])) {
134 $params['custom_pre_id'] = array(
138 $values['membership_id'],
144 elseif ($preProfileType == 'Contribution' && !empty($values['contribution_id'])) {
145 $params['custom_pre_id'] = array(
149 $values['contribution_id'],
156 $gIds['custom_pre_id'] = $values['custom_pre_id'];
159 if (isset($values['custom_post_id'])) {
160 $postProfileType = CRM_Core_BAO_UFField
::getProfileType($values['custom_post_id']);
161 if ($postProfileType == 'Membership' && !empty($values['membership_id'])) {
162 $params['custom_post_id'] = array(
166 $values['membership_id'],
172 elseif ($postProfileType == 'Contribution' && !empty($values['contribution_id'])) {
173 $params['custom_post_id'] = array(
177 $values['contribution_id'],
184 $gIds['custom_post_id'] = $values['custom_post_id'];
187 if (!empty($values['is_for_organization'])) {
188 if (!empty($values['membership_id'])) {
189 $params['onbehalf_profile'] = array(
193 $values['membership_id'],
199 elseif (!empty($values['contribution_id'])) {
200 $params['onbehalf_profile'] = array(
204 $values['contribution_id'],
212 //check whether it is a test drive
213 if ($isTest && !empty($params['custom_pre_id'])) {
214 $params['custom_pre_id'][] = array(
223 if ($isTest && !empty($params['custom_post_id'])) {
224 $params['custom_post_id'][] = array(
233 if (!$returnMessageText && !empty($gIds)) {
234 //send notification email if field values are set (CRM-1941)
235 foreach ($gIds as $key => $gId) {
237 $email = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup', $gId, 'notify');
239 $val = CRM_Core_BAO_UFGroup
::checkFieldsEmptyValues($gId, $contactID, CRM_Utils_Array
::value($key, $params), TRUE);
240 CRM_Core_BAO_UFGroup
::commonSendMail($contactID, $val);
246 if (!empty($values['is_email_receipt']) ||
!empty($values['onbehalf_dupe_alert']) ||
249 $template = CRM_Core_Smarty
::singleton();
251 // get the billing location type
252 if (!array_key_exists('related_contact', $values)) {
253 $locationTypes = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
254 $billingLocationTypeId = array_search('Billing', $locationTypes);
257 // presence of related contact implies onbehalf of org case,
258 // where location type is set to default.
259 $locType = CRM_Core_BAO_LocationType
::getDefault();
260 $billingLocationTypeId = $locType->id
;
263 if (!array_key_exists('related_contact', $values)) {
264 list($displayName, $email) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contactID, FALSE, $billingLocationTypeId);
266 // get primary location email if no email exist( for billing location).
268 list($displayName, $email) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contactID);
270 if (empty($displayName)) {
271 list($displayName, $email) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contactID);
274 //for display profile need to get individual contact id,
275 //hence get it from related_contact if on behalf of org true CRM-3767
276 //CRM-5001 Contribution/Membership:: On Behalf of Organization,
277 //If profile GROUP contain the Individual type then consider the
278 //profile is of Individual ( including the custom data of membership/contribution )
279 //IF Individual type not present in profile then it is consider as Organization data.
280 $userID = $contactID;
281 if ($preID = CRM_Utils_Array
::value('custom_pre_id', $values)) {
282 if (!empty($values['related_contact'])) {
283 $preProfileTypes = CRM_Core_BAO_UFGroup
::profileGroups($preID);
284 //@todo - following line should not refer to undefined $postProfileTypes? figure out way to test
285 if (in_array('Individual', $preProfileTypes) ||
in_array('Contact', $postProfileTypes)) {
286 //Take Individual contact ID
287 $userID = CRM_Utils_Array
::value('related_contact', $values);
290 self
::buildCustomDisplay($preID, 'customPre', $userID, $template, $params['custom_pre_id']);
292 $userID = $contactID;
293 if ($postID = CRM_Utils_Array
::value('custom_post_id', $values)) {
294 if (!empty($values['related_contact'])) {
295 $postProfileTypes = CRM_Core_BAO_UFGroup
::profileGroups($postID);
296 if (in_array('Individual', $postProfileTypes) ||
in_array('Contact', $postProfileTypes)) {
297 //Take Individual contact ID
298 $userID = CRM_Utils_Array
::value('related_contact', $values);
301 self
::buildCustomDisplay($postID, 'customPost', $userID, $template, $params['custom_post_id']);
303 if (isset($values['honor'])) {
304 $honorValues = $values['honor'];
305 CRM_Contribute_BAO_ContributionSoft
::formatHonoreeProfileFields(
307 $honorValues['honor_profile_values'],
308 $honorValues['honor_profile_id'],
309 $honorValues['honor_id']
313 $title = isset($values['title']) ?
$values['title'] : CRM_Contribute_PseudoConstant
::contributionPage($values['contribution_page_id']);
315 // set email in the template here
318 'receiptFromEmail' => CRM_Utils_Array
::value('receipt_from_email', $values),
319 'contactID' => $contactID,
320 'displayName' => $displayName,
321 'contributionID' => CRM_Utils_Array
::value('contribution_id', $values),
322 'contributionOtherID' => CRM_Utils_Array
::value('contribution_other_id', $values),
324 'lineItem' => CRM_Utils_Array
::value('lineItem', $values),
326 'priceSetID' => CRM_Utils_Array
::value('priceSetID', $values),
328 'isShare' => CRM_Utils_Array
::value('is_share', $values),
329 'thankyou_title' => CRM_Utils_Array
::value('thankyou_title', $values),
332 if ($contributionTypeId = CRM_Utils_Array
::value('financial_type_id', $values)) {
333 $tplParams['contributionTypeId'] = $contributionTypeId;
334 $tplParams['contributionTypeName'] = CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_FinancialType',
335 $contributionTypeId);
338 if ($contributionPageId = CRM_Utils_Array
::value('id', $values)) {
339 $tplParams['contributionPageId'] = $contributionPageId;
342 // address required during receipt processing (pdf and email receipt)
343 if ($displayAddress = CRM_Utils_Array
::value('address', $values)) {
344 $tplParams['address'] = $displayAddress;
348 $originalCCReceipt = CRM_Utils_Array
::value('cc_receipt', $values);
350 // cc to related contacts of contributor OR the one who
351 // signs up. Is used for cases like - on behalf of
352 // contribution / signup ..etc
353 if (array_key_exists('related_contact', $values)) {
354 list($ccDisplayName, $ccEmail) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($values['related_contact']);
355 $ccMailId = "{$ccDisplayName} <{$ccEmail}>";
357 //@todo - this is the only place in this function where $values is altered - but I can't find any evidence it is used
358 $values['cc_receipt'] = !empty($values['cc_receipt']) ?
($values['cc_receipt'] . ',' . $ccMailId) : $ccMailId;
360 // reset primary-email in the template
361 $tplParams['email'] = $ccEmail;
363 $tplParams['onBehalfName'] = $displayName;
364 $tplParams['onBehalfEmail'] = $email;
366 $ufJoinParams = array(
367 'module' => 'onBehalf',
368 'entity_table' => 'civicrm_contribution_page',
369 'entity_id' => $values['id'],
371 $OnBehalfProfile = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
372 $profileId = $OnBehalfProfile[0];
373 $userID = $contactID;
374 self
::buildCustomDisplay($profileId, 'onBehalfProfile', $userID, $template, $params['onbehalf_profile'], $fieldTypes);
377 // use either the contribution or membership receipt, based on whether it’s a membership-related contrib or not
378 $sendTemplateParams = array(
379 'groupName' => !empty($values['isMembership']) ?
'msg_tpl_workflow_membership' : 'msg_tpl_workflow_contribution',
380 'valueName' => !empty($values['isMembership']) ?
'membership_online_receipt' : 'contribution_online_receipt',
381 'contactId' => $contactID,
382 'tplParams' => $tplParams,
384 'PDFFilename' => 'receipt.pdf',
387 if ($returnMessageText) {
388 list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
390 'subject' => $subject,
392 'to' => $displayName,
397 if ($values['is_email_receipt']) {
398 $sendTemplateParams['from'] = CRM_Utils_Array
::value('receipt_from_name', $values) . ' <' . $values['receipt_from_email'] . '>';
399 $sendTemplateParams['toName'] = $displayName;
400 $sendTemplateParams['toEmail'] = $email;
401 $sendTemplateParams['cc'] = CRM_Utils_Array
::value('cc_receipt', $values);
402 $sendTemplateParams['bcc'] = CRM_Utils_Array
::value('bcc_receipt', $values);
403 //send email with pdf invoice
404 $template = CRM_Core_Smarty
::singleton();
405 $taxAmt = $template->get_template_vars('dataArray');
406 $prefixValue = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
, 'contribution_invoice_settings');
407 $invoicing = CRM_Utils_Array
::value('invoicing', $prefixValue);
408 if (count($taxAmt) > 0 && (isset($invoicing) && isset($prefixValue['is_email_pdf']))) {
409 $sendTemplateParams['isEmailPdf'] = TRUE;
410 $sendTemplateParams['contributionId'] = $values['contribution_id'];
412 list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
415 // send duplicate alert, if dupe match found during on-behalf-of processing.
416 if (!empty($values['onbehalf_dupe_alert'])) {
417 $sendTemplateParams['groupName'] = 'msg_tpl_workflow_contribution';
418 $sendTemplateParams['valueName'] = 'contribution_dupalert';
419 $sendTemplateParams['from'] = ts('Automatically Generated') . " <{$values['receipt_from_email']}>";
420 $sendTemplateParams['toName'] = CRM_Utils_Array
::value('receipt_from_name', $values);
421 $sendTemplateParams['toEmail'] = CRM_Utils_Array
::value('receipt_from_email', $values);
422 $sendTemplateParams['tplParams']['onBehalfID'] = $contactID;
423 $sendTemplateParams['tplParams']['receiptMessage'] = $message;
425 // fix cc and reset back to original, CRM-6976
426 $sendTemplateParams['cc'] = $originalCCReceipt;
428 CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
434 * Construct the message to be sent by the send function
436 * @param array $tplParams
437 * @param int $contactID
442 public function composeMessage($tplParams, $contactID, $isTest) {
443 $sendTemplateParams = array(
444 'groupName' => $tplParams['membershipID'] ?
'msg_tpl_workflow_membership' : 'msg_tpl_workflow_contribution',
445 'valueName' => $tplParams['membershipID'] ?
'membership_online_receipt' : 'contribution_online_receipt',
446 'contactId' => $contactID,
447 'tplParams' => $tplParams,
449 'PDFFilename' => 'receipt.pdf',
451 if ($returnMessageText) {
452 list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
454 'subject' => $subject,
456 'to' => $displayName,
463 * Send the emails for Recurring Contribution Notication
465 * @param string $type
467 * @param int $contactID
468 * Contact id for contributor.
470 * Contribution page id.
471 * @param object $recur
472 * Object of recurring contribution table.
473 * @param bool|object $autoRenewMembership is it a auto renew membership.
477 public static function recurringNotify($type, $contactID, $pageID, $recur, $autoRenewMembership = FALSE) {
480 CRM_Core_DAO
::commonRetrieveAll('CRM_Contribute_DAO_ContributionPage', 'id', $pageID, $value, array(
484 'receipt_from_email',
490 $isEmailReceipt = CRM_Utils_Array
::value('is_email_receipt', $value[$pageID]);
491 $isOfflineRecur = FALSE;
492 if (!$pageID && $recur->id
) {
493 $isOfflineRecur = TRUE;
495 if ($isEmailReceipt ||
$isOfflineRecur) {
497 $receiptFrom = '"' . CRM_Utils_Array
::value('receipt_from_name', $value[$pageID]) . '" <' . $value[$pageID]['receipt_from_email'] . '>';
499 $receiptFromName = $value[$pageID]['receipt_from_name'];
500 $receiptFromEmail = $value[$pageID]['receipt_from_email'];
503 $domainValues = CRM_Core_BAO_Domain
::getNameAndEmail();
504 $receiptFrom = "$domainValues[0] <$domainValues[1]>";
505 $receiptFromName = $domainValues[0];
506 $receiptFromEmail = $domainValues[1];
509 list($displayName, $email) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contactID, FALSE);
510 $templatesParams = array(
511 'groupName' => 'msg_tpl_workflow_contribution',
512 'valueName' => 'contribution_recurring_notify',
513 'contactId' => $contactID,
514 'tplParams' => array(
515 'recur_frequency_interval' => $recur->frequency_interval
,
516 'recur_frequency_unit' => $recur->frequency_unit
,
517 'recur_installments' => $recur->installments
,
518 'recur_start_date' => $recur->start_date
,
519 'recur_end_date' => $recur->end_date
,
520 'recur_amount' => $recur->amount
,
521 'recur_txnType' => $type,
522 'displayName' => $displayName,
523 'receipt_from_name' => $receiptFromName,
524 'receipt_from_email' => $receiptFromEmail,
525 'auto_renew_membership' => $autoRenewMembership,
527 'from' => $receiptFrom,
528 'toName' => $displayName,
533 $templatesParams['cc'] = CRM_Utils_Array
::value('cc_receipt', $value[$pageID]);
534 $templatesParams['bcc'] = CRM_Utils_Array
::value('bcc_receipt', $value[$pageID]);
537 // in some cases its just recurringNotify() thats called for the first time and these urls don't get set.
538 // like in PaypalPro, & therefore we set it here additionally.
539 $template = CRM_Core_Smarty
::singleton();
540 $paymentProcessor = CRM_Financial_BAO_PaymentProcessor
::getProcessorForEntity($recur->id
, 'recur', 'obj');
541 $url = $paymentProcessor->subscriptionURL($recur->id
, 'recur');
542 $template->assign('cancelSubscriptionUrl', $url);
544 $url = $paymentProcessor->subscriptionURL($recur->id
, 'recur', 'billing');
545 $template->assign('updateSubscriptionBillingUrl', $url);
547 $url = $paymentProcessor->subscriptionURL($recur->id
, 'recur', 'update');
548 $template->assign('updateSubscriptionUrl', $url);
551 list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($templatesParams);
554 CRM_Core_Error
::debug_log_message('Success: mail sent for recurring notification.');
557 CRM_Core_Error
::debug_log_message('Failure: mail not sent for recurring notification.');
563 * Add the custom fields for contribution page (ie profile)
567 * @param string $name
571 * @param array $params
572 * Params to build component whereclause.
574 * @param null $fieldTypes
578 public static function buildCustomDisplay($gid, $name, $cid, &$template, &$params, $fieldTypes = NULL) {
580 if (CRM_Core_BAO_UFGroup
::filterUFGroups($gid, $cid)) {
583 $fields = CRM_Core_BAO_UFGroup
::getFields($gid, FALSE, CRM_Core_Action
::VIEW
, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission
::CREATE
, NULL);
584 foreach ($fields as $k => $v) {
586 $groupTitle = $v["groupTitle"];
588 // suppress all file fields from display and formatting fields
590 CRM_Utils_Array
::value('data_type', $v, '') == 'File' ||
591 CRM_Utils_Array
::value('name', $v, '') == 'image_URL' ||
592 CRM_Utils_Array
::value('field_type', $v) == 'Formatting'
597 if (!empty($fieldTypes) && (!in_array($v['field_type'], $fieldTypes))) {
603 $template->assign($name . "_grouptitle", $groupTitle);
606 CRM_Core_BAO_UFGroup
::getValues($cid, $fields, $values, FALSE, $params);
608 if (count($values)) {
609 $template->assign($name, $values);
616 * make a copy of a contribution page, including
617 * all the blocks in the page
620 * The contribution page id to copy.
622 * @return CRM_Contribute_DAO_ContributionPage
624 public static function copy($id) {
627 'title' => ts('Copy of') . ' ',
630 $copy = &CRM_Core_DAO
::copyGeneric('CRM_Contribute_DAO_ContributionPage', array(
632 ), NULL, $fieldsFix);
634 //copying all the blocks pertaining to the contribution page
635 $copyPledgeBlock = &CRM_Core_DAO
::copyGeneric('CRM_Pledge_DAO_PledgeBlock', array(
637 'entity_table' => 'civicrm_contribution_page',
639 'entity_id' => $copy->id
,
642 $copyMembershipBlock = &CRM_Core_DAO
::copyGeneric('CRM_Member_DAO_MembershipBlock', array(
644 'entity_table' => 'civicrm_contribution_page',
646 'entity_id' => $copy->id
,
649 $copyUFJoin = &CRM_Core_DAO
::copyGeneric('CRM_Core_DAO_UFJoin', array(
651 'entity_table' => 'civicrm_contribution_page',
653 'entity_id' => $copy->id
,
656 $copyWidget = &CRM_Core_DAO
::copyGeneric('CRM_Contribute_DAO_Widget', array(
657 'contribution_page_id' => $id,
659 'contribution_page_id' => $copy->id
,
663 CRM_Price_BAO_PriceSet
::copyPriceSet('civicrm_contribution_page', $id, $copy->id
);
665 $copyTellFriend = &CRM_Core_DAO
::copyGeneric('CRM_Friend_DAO_Friend', array(
667 'entity_table' => 'civicrm_contribution_page',
669 'entity_id' => $copy->id
,
672 $copyPersonalCampaignPages = &CRM_Core_DAO
::copyGeneric('CRM_PCP_DAO_PCPBlock', array(
674 'entity_table' => 'civicrm_contribution_page',
676 'entity_id' => $copy->id
,
679 $copyPremium = &CRM_Core_DAO
::copyGeneric('CRM_Contribute_DAO_Premium', array(
681 'entity_table' => 'civicrm_contribution_page',
683 'entity_id' => $copy->id
,
687 FROM civicrm_premiums
688 WHERE entity_table = 'civicrm_contribution_page'
689 AND entity_id ={$id}";
691 $premiumDao = CRM_Core_DAO
::executeQuery($premiumQuery, CRM_Core_DAO
::$_nullArray);
692 while ($premiumDao->fetch()) {
693 if ($premiumDao->id
) {
694 $copyPremiumProduct = &CRM_Core_DAO
::copyGeneric('CRM_Contribute_DAO_PremiumsProduct', array(
695 'premiums_id' => $premiumDao->id
,
697 'premiums_id' => $copyPremium->id
,
704 CRM_Utils_Hook
::copy('ContributionPage', $copy);
710 * Check if contribution page contains payment
711 * processor that supports recurring payment
713 * @param int $contributionPageId
714 * Contribution Page Id.
717 * true if payment processor supports recurring
721 public static function checkRecurPaymentProcessor($contributionPageId) {
725 FROM civicrm_contribution_page cp,
726 civicrm_payment_processor pp
727 WHERE cp.payment_processor = pp.id
728 AND cp.id = {$contributionPageId}
731 if ($recurring = &CRM_Core_DAO
::singleValueQuery($sql, CRM_Core_DAO
::$_nullArray)) {
738 * Get info for all sections enable/disable.
740 * @param array $contribPageIds
742 * info regarding all sections.
744 public static function getSectionInfo($contribPageIds = array()) {
747 if (is_array($contribPageIds) && !empty($contribPageIds)) {
748 $whereClause = 'WHERE civicrm_contribution_page.id IN ( ' . implode(', ', $contribPageIds) . ' )';
763 SELECT civicrm_contribution_page.id as id,
764 civicrm_contribution_page.financial_type_id as settings,
765 amount_block_is_active as amount,
766 civicrm_membership_block.id as membership,
767 civicrm_uf_join.id as custom,
768 civicrm_contribution_page.thankyou_title as thankyou,
769 civicrm_tell_friend.id as friend,
770 civicrm_pcp_block.id as pcp,
771 civicrm_contribution_widget.id as widget,
772 civicrm_premiums.id as premium
773 FROM civicrm_contribution_page
774 LEFT JOIN civicrm_membership_block ON ( civicrm_membership_block.entity_id = civicrm_contribution_page.id
775 AND civicrm_membership_block.entity_table = 'civicrm_contribution_page'
776 AND civicrm_membership_block.is_active = 1 )
777 LEFT JOIN civicrm_uf_join ON ( civicrm_uf_join.entity_id = civicrm_contribution_page.id
778 AND civicrm_uf_join.entity_table = 'civicrm_contribution_page'
779 AND module = 'CiviContribute'
780 AND civicrm_uf_join.is_active = 1 )
781 LEFT JOIN civicrm_tell_friend ON ( civicrm_tell_friend.entity_id = civicrm_contribution_page.id
782 AND civicrm_tell_friend.entity_table = 'civicrm_contribution_page'
783 AND civicrm_tell_friend.is_active = 1)
784 LEFT JOIN civicrm_pcp_block ON ( civicrm_pcp_block.entity_id = civicrm_contribution_page.id
785 AND civicrm_pcp_block.entity_table = 'civicrm_contribution_page'
786 AND civicrm_pcp_block.is_active = 1 )
787 LEFT JOIN civicrm_contribution_widget ON ( civicrm_contribution_widget.contribution_page_id = civicrm_contribution_page.id
788 AND civicrm_contribution_widget.is_active = 1 )
789 LEFT JOIN civicrm_premiums ON ( civicrm_premiums.entity_id = civicrm_contribution_page.id
790 AND civicrm_premiums.entity_table = 'civicrm_contribution_page'
791 AND civicrm_premiums.premiums_active = 1 )
794 $contributionPage = CRM_Core_DAO
::executeQuery($query);
795 while ($contributionPage->fetch()) {
796 if (!isset($info[$contributionPage->id
]) ||
!is_array($info[$contributionPage->id
])) {
797 $info[$contributionPage->id
] = array_fill_keys(array_values($sections), FALSE);
799 foreach ($sections as $section) {
800 if ($contributionPage->$section) {
801 $info[$contributionPage->id
][$section] = TRUE;
810 * Get options for a given field.
811 * @see CRM_Core_DAO::buildOptions
813 * @param string $fieldName
814 * @param string $context : @see CRM_Core_DAO::buildOptionsContext
815 * @param array $props : whatever is known about this dao object
819 public static function buildOptions($fieldName, $context = NULL, $props = array()) {
821 // Special logic for fields whose options depend on context or properties
822 switch ($fieldName) {
823 case 'financial_type_id':
824 // Fixme - this is going to ignore context, better to get conditions, add params, and call PseudoConstant::get
825 return CRM_Financial_BAO_FinancialType
::getIncomeFinancialType();
829 return CRM_Core_PseudoConstant
::get(__CLASS__
, $fieldName, $params, $context);
833 * Get or Set multilingually affected honor params for processing module_data or setting default values.
835 * @param string $params :
836 * @param bool $setDefault : If yes then returns array to used for setting default value afterward
838 * @return array|string
840 public static function formatMultilingualHonorParams($params, $setDefault = FALSE) {
841 $config = CRM_Core_Config
::singleton();
842 $sctJson = $sctJsonDecode = NULL;
843 $domain = new CRM_Core_DAO_Domain();
846 //When we are fetching the honor params respecting both multi and mono lingual state
847 //and setting it to default param of Contribution Page's Main and Setting form
849 $sctJsonDecode = json_decode($params);
850 $sctJsonDecode = (array) $sctJsonDecode->soft_credit
;
851 if (!$domain->locales
&& !empty($sctJsonDecode['default'])) {
853 $sctJsonDecode +
= (array) $sctJsonDecode['default'];
855 elseif (!empty($sctJsonDecode[$config->lcMessages
])) {
857 foreach ($sctJsonDecode[$config->lcMessages
] as $column => $value) {
858 $sctJsonDecode[$column] = $value;
860 unset($sctJsonDecode[$config->lcMessages
]);
862 return $sctJsonDecode;
865 //check and handle multilingual honoree params
866 if (!$domain->locales
) {
867 //if in singlelingual state simply return the array format
868 $sctJson = json_encode(
870 'soft_credit' => array(
871 'soft_credit_types' => $params['soft_credit_types'],
873 'honor_block_title' => $params['honor_block_title'],
874 'honor_block_text' => $params['honor_block_text'],
881 //if in multilingual state then retrieve the module_data against this contribution and
882 //merge with earlier module_data json data to current so not to lose earlier multilingual module_data information
884 'soft_credit' => array(
885 'soft_credit_types' => $params['soft_credit_types'],
886 $config->lcMessages
=> array(
887 'honor_block_title' => $params['honor_block_title'],
888 'honor_block_text' => $params['honor_block_text'],
893 $ufJoinDAO = new CRM_Core_DAO_UFJoin();
894 $ufJoinDAO->module
= 'soft_credit';
895 $ufJoinDAO->entity_id
= $params['id'];
896 $ufJoinDAO->find(TRUE);
897 $jsonData = json_decode($ufJoinDAO->module_data
);
899 $sctJson['soft_credit'] = array_merge((array) $jsonData->soft_credit
, $sctJson['soft_credit']);
901 $sctJson = json_encode($sctJson);
907 * Generate html for pdf in confirmation receipt email attachment
908 * @param int $contributionId
909 * Contribution Page Id.
911 * Contact id for contributor.
914 public static function addInvoicePdfToEmail($contributionId, $userID) {
915 $contributionID = array($contributionId);
916 $contactId = array($userID);
918 'output' => 'pdf_invoice',
919 'forPage' => 'confirmpage',
921 $pdfHtml = CRM_Contribute_Form_Task_Invoice
::printPDF($contributionID,
922 $pdfParams, $contactId, CRM_Core_DAO
::$_nullObject);
927 * Helper to determine if the page supports separate membership payments
928 * @param int $id form id
931 * isSeparateMembershipPayment
933 public static function getIsMembershipPayment($id) {
934 $membershipBlocks = civicrm_api3('membership_block', 'get', array(
935 'entity_table' => 'civicrm_contribution_page',
937 'sequential' => TRUE,
939 if (!$membershipBlocks['count']) {
942 return $membershipBlocks['values'][0]['is_separate_payment'];