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 object
50 public static function &create(&$params) {
51 $financialTypeId = NULL;
52 if (!empty($params['id']) && !CRM_Price_BAO_PriceSet
::getFor('civicrm_contribution_page', $params['id'], NULL, 1)) {
53 $financialTypeId = CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_ContributionPage', $params['id'], 'financial_type_id');
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
71 * Id of the database record.
72 * @param bool $is_active
73 * Value we want to set the is_active field.
75 * @return Object DAO object on success, null otherwise
78 public static function setIsActive($id, $is_active) {
79 return CRM_Core_DAO
::setFieldValue('CRM_Contribute_DAO_ContributionPage', $id, 'is_active', $is_active);
86 public static function setValues($id, &$values) {
91 CRM_Core_DAO
::commonRetrieve('CRM_Contribute_DAO_ContributionPage', $params, $values);
93 // get the profile ids
94 $ufJoinParams = array(
95 'module' => 'CiviContribute',
96 'entity_table' => 'civicrm_contribution_page',
99 list($values['custom_pre_id'], $customPostIds) = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
101 if (!empty($customPostIds)) {
102 $values['custom_post_id'] = $customPostIds[0];
105 $values['custom_post_id'] = '';
107 // // add an accounting code also
108 // if ($values ['financial_type_id']) {
109 // $values ['accountingCode'] = CRM_Core_DAO::getFieldValue( 'CRM_Financial_DAO_FinancialType', $values ['financial_type_id'], 'accounting_code' );
116 * @param int $contactID
118 * @param array $values
119 * Associated array of fields.
120 * @param bool $isTest
122 * @param bool $returnMessageText
123 * Return the message text instead of sending the mail.
125 * @param null $fieldTypes
130 public static function sendMail($contactID, $values, $isTest = FALSE, $returnMessageText = FALSE, $fieldTypes = NULL) {
131 $gIds = $params = array();
133 if (isset($values['custom_pre_id'])) {
134 $preProfileType = CRM_Core_BAO_UFField
::getProfileType($values['custom_pre_id']);
135 if ($preProfileType == 'Membership' && !empty($values['membership_id'])) {
136 $params['custom_pre_id'] = array(
140 $values['membership_id'],
146 elseif ($preProfileType == 'Contribution' && !empty($values['contribution_id'])) {
147 $params['custom_pre_id'] = array(
151 $values['contribution_id'],
158 $gIds['custom_pre_id'] = $values['custom_pre_id'];
161 if (isset($values['custom_post_id'])) {
162 $postProfileType = CRM_Core_BAO_UFField
::getProfileType($values['custom_post_id']);
163 if ($postProfileType == 'Membership' && !empty($values['membership_id'])) {
164 $params['custom_post_id'] = array(
168 $values['membership_id'],
174 elseif ($postProfileType == 'Contribution' && !empty($values['contribution_id'])) {
175 $params['custom_post_id'] = array(
179 $values['contribution_id'],
186 $gIds['custom_post_id'] = $values['custom_post_id'];
189 if (!empty($values['is_for_organization'])) {
190 if (!empty($values['membership_id'])) {
191 $params['onbehalf_profile'] = array(
195 $values['membership_id'],
201 elseif (!empty($values['contribution_id'])) {
202 $params['onbehalf_profile'] = array(
206 $values['contribution_id'],
214 //check whether it is a test drive
215 if ($isTest && !empty($params['custom_pre_id'])) {
216 $params['custom_pre_id'][] = array(
225 if ($isTest && !empty($params['custom_post_id'])) {
226 $params['custom_post_id'][] = array(
235 if (!$returnMessageText && !empty($gIds)) {
236 //send notification email if field values are set (CRM-1941)
237 foreach ($gIds as $key => $gId) {
239 $email = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup', $gId, 'notify');
241 $val = CRM_Core_BAO_UFGroup
::checkFieldsEmptyValues($gId, $contactID, CRM_Utils_Array
::value($key, $params), TRUE);
242 CRM_Core_BAO_UFGroup
::commonSendMail($contactID, $val);
248 if (!empty($values['is_email_receipt']) ||
!empty($values['onbehalf_dupe_alert']) ||
251 $template = CRM_Core_Smarty
::singleton();
253 // get the billing location type
254 if (!array_key_exists('related_contact', $values)) {
255 $locationTypes = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
256 $billingLocationTypeId = array_search('Billing', $locationTypes);
259 // presence of related contact implies onbehalf of org case,
260 // where location type is set to default.
261 $locType = CRM_Core_BAO_LocationType
::getDefault();
262 $billingLocationTypeId = $locType->id
;
265 if (!array_key_exists('related_contact', $values)) {
266 list($displayName, $email) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contactID, FALSE, $billingLocationTypeId);
268 // get primary location email if no email exist( for billing location).
270 list($displayName, $email) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contactID);
272 if (empty($displayName)) {
273 list($displayName, $email) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contactID);
276 //for display profile need to get individual contact id,
277 //hence get it from related_contact if on behalf of org true CRM-3767
278 //CRM-5001 Contribution/Membership:: On Behalf of Organization,
279 //If profile GROUP contain the Individual type then consider the
280 //profile is of Individual ( including the custom data of membership/contribution )
281 //IF Individual type not present in profile then it is consider as Organization data.
282 $userID = $contactID;
283 if ($preID = CRM_Utils_Array
::value('custom_pre_id', $values)) {
284 if (!empty($values['related_contact'])) {
285 $preProfileTypes = CRM_Core_BAO_UFGroup
::profileGroups($preID);
286 //@todo - following line should not refer to undefined $postProfileTypes? figure out way to test
287 if (in_array('Individual', $preProfileTypes) ||
in_array('Contact', $postProfileTypes)) {
288 //Take Individual contact ID
289 $userID = CRM_Utils_Array
::value('related_contact', $values);
292 self
::buildCustomDisplay($preID, 'customPre', $userID, $template, $params['custom_pre_id']);
294 $userID = $contactID;
295 if ($postID = CRM_Utils_Array
::value('custom_post_id', $values)) {
296 if (!empty($values['related_contact'])) {
297 $postProfileTypes = CRM_Core_BAO_UFGroup
::profileGroups($postID);
298 if (in_array('Individual', $postProfileTypes) ||
in_array('Contact', $postProfileTypes)) {
299 //Take Individual contact ID
300 $userID = CRM_Utils_Array
::value('related_contact', $values);
303 self
::buildCustomDisplay($postID, 'customPost', $userID, $template, $params['custom_post_id']);
305 if (isset($values['honor'])) {
306 $honorValues = $values['honor'];
307 CRM_Contribute_BAO_ContributionSoft
::formatHonoreeProfileFields(
309 $honorValues['honor_profile_values'],
310 $honorValues['honor_profile_id'],
311 $honorValues['honor_id']
315 $title = isset($values['title']) ?
$values['title'] : CRM_Contribute_PseudoConstant
::contributionPage($values['contribution_page_id']);
317 // set email in the template here
320 'receiptFromEmail' => CRM_Utils_Array
::value('receipt_from_email', $values),
321 'contactID' => $contactID,
322 'displayName' => $displayName,
323 'contributionID' => CRM_Utils_Array
::value('contribution_id', $values),
324 'contributionOtherID' => CRM_Utils_Array
::value('contribution_other_id', $values),
326 'lineItem' => CRM_Utils_Array
::value('lineItem', $values),
328 'priceSetID' => CRM_Utils_Array
::value('priceSetID', $values),
330 'isShare' => CRM_Utils_Array
::value('is_share', $values),
333 if ($contributionTypeId = CRM_Utils_Array
::value('financial_type_id', $values)) {
334 $tplParams['contributionTypeId'] = $contributionTypeId;
335 $tplParams['contributionTypeName'] = CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_FinancialType',
336 $contributionTypeId);
339 if ($contributionPageId = CRM_Utils_Array
::value('id', $values)) {
340 $tplParams['contributionPageId'] = $contributionPageId;
343 // address required during receipt processing (pdf and email receipt)
344 if ($displayAddress = CRM_Utils_Array
::value('address', $values)) {
345 $tplParams['address'] = $displayAddress;
349 $originalCCReceipt = CRM_Utils_Array
::value('cc_receipt', $values);
351 // cc to related contacts of contributor OR the one who
352 // signs up. Is used for cases like - on behalf of
353 // contribution / signup ..etc
354 if (array_key_exists('related_contact', $values)) {
355 list($ccDisplayName, $ccEmail) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($values['related_contact']);
356 $ccMailId = "{$ccDisplayName} <{$ccEmail}>";
358 //@todo - this is the only place in this function where $values is altered - but I can't find any evidence it is used
359 $values['cc_receipt'] = !empty($values['cc_receipt']) ?
($values['cc_receipt'] . ',' . $ccMailId) : $ccMailId;
361 // reset primary-email in the template
362 $tplParams['email'] = $ccEmail;
364 $tplParams['onBehalfName'] = $displayName;
365 $tplParams['onBehalfEmail'] = $email;
367 $ufJoinParams = array(
368 'module' => 'onBehalf',
369 'entity_table' => 'civicrm_contribution_page',
370 'entity_id' => $values['id'],
372 $OnBehalfProfile = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
373 $profileId = $OnBehalfProfile[0];
374 $userID = $contactID;
375 self
::buildCustomDisplay($profileId, 'onBehalfProfile', $userID, $template, $params['onbehalf_profile'], $fieldTypes);
378 // use either the contribution or membership receipt, based on whether it’s a membership-related contrib or not
379 $sendTemplateParams = array(
380 'groupName' => !empty($values['isMembership']) ?
'msg_tpl_workflow_membership' : 'msg_tpl_workflow_contribution',
381 'valueName' => !empty($values['isMembership']) ?
'membership_online_receipt' : 'contribution_online_receipt',
382 'contactId' => $contactID,
383 'tplParams' => $tplParams,
385 'PDFFilename' => 'receipt.pdf',
388 if ($returnMessageText) {
389 list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
391 'subject' => $subject,
393 'to' => $displayName,
398 if ($values['is_email_receipt']) {
399 $sendTemplateParams['from'] = CRM_Utils_Array
::value('receipt_from_name', $values) . ' <' . $values['receipt_from_email'] . '>';
400 $sendTemplateParams['toName'] = $displayName;
401 $sendTemplateParams['toEmail'] = $email;
402 $sendTemplateParams['cc'] = CRM_Utils_Array
::value('cc_receipt', $values);
403 $sendTemplateParams['bcc'] = CRM_Utils_Array
::value('bcc_receipt', $values);
404 //send email with pdf invoice
405 $template = CRM_Core_Smarty
::singleton();
406 $taxAmt = $template->get_template_vars('dataArray');
407 $prefixValue = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
, 'contribution_invoice_settings');
408 $invoicing = CRM_Utils_Array
::value('invoicing', $prefixValue);
409 if (count($taxAmt) > 0 && (isset($invoicing) && isset($prefixValue['is_email_pdf']))) {
410 $sendTemplateParams['isEmailPdf'] = TRUE;
411 $sendTemplateParams['contributionId'] = $values['contribution_id'];
413 list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
416 // send duplicate alert, if dupe match found during on-behalf-of processing.
417 if (!empty($values['onbehalf_dupe_alert'])) {
418 $sendTemplateParams['groupName'] = 'msg_tpl_workflow_contribution';
419 $sendTemplateParams['valueName'] = 'contribution_dupalert';
420 $sendTemplateParams['from'] = ts('Automatically Generated') . " <{$values['receipt_from_email']}>";
421 $sendTemplateParams['toName'] = CRM_Utils_Array
::value('receipt_from_name', $values);
422 $sendTemplateParams['toEmail'] = CRM_Utils_Array
::value('receipt_from_email', $values);
423 $sendTemplateParams['tplParams']['onBehalfID'] = $contactID;
424 $sendTemplateParams['tplParams']['receiptMessage'] = $message;
426 // fix cc and reset back to original, CRM-6976
427 $sendTemplateParams['cc'] = $originalCCReceipt;
429 CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
435 * Construct the message to be sent by the send function
437 * @param array $tplParams
438 * @param int $contactID
443 public function composeMessage($tplParams, $contactID, $isTest) {
444 $sendTemplateParams = array(
445 'groupName' => $tplParams['membershipID'] ?
'msg_tpl_workflow_membership' : 'msg_tpl_workflow_contribution',
446 'valueName' => $tplParams['membershipID'] ?
'membership_online_receipt' : 'contribution_online_receipt',
447 'contactId' => $contactID,
448 'tplParams' => $tplParams,
450 'PDFFilename' => 'receipt.pdf',
452 if ($returnMessageText) {
453 list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
455 'subject' => $subject,
457 'to' => $displayName,
464 * Send the emails for Recurring Contribution Notication
466 * @param string $type
468 * @param int $contactID
469 * Contact id for contributor.
471 * Contribution page id.
472 * @param object $recur
473 * Object of recurring contribution table.
474 * @param bool|object $autoRenewMembership is it a auto renew membership.
479 public static function recurringNotify($type, $contactID, $pageID, $recur, $autoRenewMembership = FALSE) {
482 CRM_Core_DAO
::commonRetrieveAll('CRM_Contribute_DAO_ContributionPage', 'id', $pageID, $value, array(
486 'receipt_from_email',
492 $isEmailReceipt = CRM_Utils_Array
::value('is_email_receipt', $value[$pageID]);
493 $isOfflineRecur = FALSE;
494 if (!$pageID && $recur->id
) {
495 $isOfflineRecur = TRUE;
497 if ($isEmailReceipt ||
$isOfflineRecur) {
499 $receiptFrom = '"' . CRM_Utils_Array
::value('receipt_from_name', $value[$pageID]) . '" <' . $value[$pageID]['receipt_from_email'] . '>';
501 $receiptFromName = $value[$pageID]['receipt_from_name'];
502 $receiptFromEmail = $value[$pageID]['receipt_from_email'];
505 $domainValues = CRM_Core_BAO_Domain
::getNameAndEmail();
506 $receiptFrom = "$domainValues[0] <$domainValues[1]>";
507 $receiptFromName = $domainValues[0];
508 $receiptFromEmail = $domainValues[1];
511 list($displayName, $email) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contactID, FALSE);
512 $templatesParams = array(
513 'groupName' => 'msg_tpl_workflow_contribution',
514 'valueName' => 'contribution_recurring_notify',
515 'contactId' => $contactID,
516 'tplParams' => array(
517 'recur_frequency_interval' => $recur->frequency_interval
,
518 'recur_frequency_unit' => $recur->frequency_unit
,
519 'recur_installments' => $recur->installments
,
520 'recur_start_date' => $recur->start_date
,
521 'recur_end_date' => $recur->end_date
,
522 'recur_amount' => $recur->amount
,
523 'recur_txnType' => $type,
524 'displayName' => $displayName,
525 'receipt_from_name' => $receiptFromName,
526 'receipt_from_email' => $receiptFromEmail,
527 'auto_renew_membership' => $autoRenewMembership,
529 'from' => $receiptFrom,
530 'toName' => $displayName,
535 $templatesParams['cc'] = CRM_Utils_Array
::value('cc_receipt', $value[$pageID]);
536 $templatesParams['bcc'] = CRM_Utils_Array
::value('bcc_receipt', $value[$pageID]);
539 // in some cases its just recurringNotify() thats called for the first time and these urls don't get set.
540 // like in PaypalPro, & therefore we set it here additionally.
541 $template = CRM_Core_Smarty
::singleton();
542 $paymentProcessor = CRM_Financial_BAO_PaymentProcessor
::getProcessorForEntity($recur->id
, 'recur', 'obj');
543 $url = $paymentProcessor->subscriptionURL($recur->id
, 'recur');
544 $template->assign('cancelSubscriptionUrl', $url);
546 $url = $paymentProcessor->subscriptionURL($recur->id
, 'recur', 'billing');
547 $template->assign('updateSubscriptionBillingUrl', $url);
549 $url = $paymentProcessor->subscriptionURL($recur->id
, 'recur', 'update');
550 $template->assign('updateSubscriptionUrl', $url);
553 list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($templatesParams);
556 CRM_Core_Error
::debug_log_message('Success: mail sent for recurring notification.');
559 CRM_Core_Error
::debug_log_message('Failure: mail not sent for recurring notification.');
565 * Add the custom fields for contribution page (ie profile)
569 * @param string $name
573 * @param array $params
574 * Params to build component whereclause.
576 * @param null $fieldTypes
581 public static function buildCustomDisplay($gid, $name, $cid, &$template, &$params, $fieldTypes = NULL) {
583 if (CRM_Core_BAO_UFGroup
::filterUFGroups($gid, $cid)) {
586 $fields = CRM_Core_BAO_UFGroup
::getFields($gid, FALSE, CRM_Core_Action
::VIEW
, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission
::CREATE
, NULL);
587 foreach ($fields as $k => $v) {
589 $groupTitle = $v["groupTitle"];
591 // suppress all file fields from display and formatting fields
593 CRM_Utils_Array
::value('data_type', $v, '') == 'File' ||
594 CRM_Utils_Array
::value('name', $v, '') == 'image_URL' ||
595 CRM_Utils_Array
::value('field_type', $v) == 'Formatting'
600 if (!empty($fieldTypes) && (!in_array($v['field_type'], $fieldTypes))) {
606 $template->assign($name . "_grouptitle", $groupTitle);
609 CRM_Core_BAO_UFGroup
::getValues($cid, $fields, $values, FALSE, $params);
611 if (count($values)) {
612 $template->assign($name, $values);
619 * This function is to make a copy of a contribution page, including
620 * all the blocks in the page
623 * The contribution page id to copy.
625 * @return the copy object
628 public static function copy($id) {
631 'title' => ts('Copy of') . ' ',
634 $copy = &CRM_Core_DAO
::copyGeneric('CRM_Contribute_DAO_ContributionPage', array(
636 ), NULL, $fieldsFix);
638 //copying all the blocks pertaining to the contribution page
639 $copyPledgeBlock = &CRM_Core_DAO
::copyGeneric('CRM_Pledge_DAO_PledgeBlock', array(
641 'entity_table' => 'civicrm_contribution_page',
643 'entity_id' => $copy->id
,
646 $copyMembershipBlock = &CRM_Core_DAO
::copyGeneric('CRM_Member_DAO_MembershipBlock', array(
648 'entity_table' => 'civicrm_contribution_page',
650 'entity_id' => $copy->id
,
653 $copyUFJoin = &CRM_Core_DAO
::copyGeneric('CRM_Core_DAO_UFJoin', array(
655 'entity_table' => 'civicrm_contribution_page',
657 'entity_id' => $copy->id
,
660 $copyWidget = &CRM_Core_DAO
::copyGeneric('CRM_Contribute_DAO_Widget', array(
661 'contribution_page_id' => $id,
663 'contribution_page_id' => $copy->id
,
667 CRM_Price_BAO_PriceSet
::copyPriceSet('civicrm_contribution_page', $id, $copy->id
);
669 $copyTellFriend = &CRM_Core_DAO
::copyGeneric('CRM_Friend_DAO_Friend', array(
671 'entity_table' => 'civicrm_contribution_page',
673 'entity_id' => $copy->id
,
676 $copyPersonalCampaignPages = &CRM_Core_DAO
::copyGeneric('CRM_PCP_DAO_PCPBlock', array(
678 'entity_table' => 'civicrm_contribution_page',
680 'entity_id' => $copy->id
,
683 $copyPremium = &CRM_Core_DAO
::copyGeneric('CRM_Contribute_DAO_Premium', array(
685 'entity_table' => 'civicrm_contribution_page',
687 'entity_id' => $copy->id
,
691 FROM civicrm_premiums
692 WHERE entity_table = 'civicrm_contribution_page'
693 AND entity_id ={$id}";
695 $premiumDao = CRM_Core_DAO
::executeQuery($premiumQuery, CRM_Core_DAO
::$_nullArray);
696 while ($premiumDao->fetch()) {
697 if ($premiumDao->id
) {
698 $copyPremiumProduct = & CRM_Core_DAO
::copyGeneric('CRM_Contribute_DAO_PremiumsProduct', array(
699 'premiums_id' => $premiumDao->id
,
701 'premiums_id' => $copyPremium->id
,
708 CRM_Utils_Hook
::copy('ContributionPage', $copy);
714 * Check if contribution page contains payment
715 * processor that supports recurring payment
717 * @param int $contributionPageId
718 * Contribution Page Id.
720 * @return boolean true if payment processor supports recurring
725 public static function checkRecurPaymentProcessor($contributionPageId) {
729 FROM civicrm_contribution_page cp,
730 civicrm_payment_processor pp
731 WHERE cp.payment_processor = pp.id
732 AND cp.id = {$contributionPageId}
735 if ($recurring = &CRM_Core_DAO
::singleValueQuery($sql, CRM_Core_DAO
::$_nullArray)) {
742 * Get info for all sections enable/disable.
744 * @param array $contribPageIds
745 * @return array $info info regarding all sections.
748 public static function getSectionInfo($contribPageIds = array()) {
751 if (is_array($contribPageIds) && !empty($contribPageIds)) {
752 $whereClause = 'WHERE civicrm_contribution_page.id IN ( ' . implode(', ', $contribPageIds) . ' )';
767 SELECT civicrm_contribution_page.id as id,
768 civicrm_contribution_page.financial_type_id as settings,
769 amount_block_is_active as amount,
770 civicrm_membership_block.id as membership,
771 civicrm_uf_join.id as custom,
772 civicrm_contribution_page.thankyou_title as thankyou,
773 civicrm_tell_friend.id as friend,
774 civicrm_pcp_block.id as pcp,
775 civicrm_contribution_widget.id as widget,
776 civicrm_premiums.id as premium
777 FROM civicrm_contribution_page
778 LEFT JOIN civicrm_membership_block ON ( civicrm_membership_block.entity_id = civicrm_contribution_page.id
779 AND civicrm_membership_block.entity_table = 'civicrm_contribution_page'
780 AND civicrm_membership_block.is_active = 1 )
781 LEFT JOIN civicrm_uf_join ON ( civicrm_uf_join.entity_id = civicrm_contribution_page.id
782 AND civicrm_uf_join.entity_table = 'civicrm_contribution_page'
783 AND module = 'CiviContribute'
784 AND civicrm_uf_join.is_active = 1 )
785 LEFT JOIN civicrm_tell_friend ON ( civicrm_tell_friend.entity_id = civicrm_contribution_page.id
786 AND civicrm_tell_friend.entity_table = 'civicrm_contribution_page'
787 AND civicrm_tell_friend.is_active = 1)
788 LEFT JOIN civicrm_pcp_block ON ( civicrm_pcp_block.entity_id = civicrm_contribution_page.id
789 AND civicrm_pcp_block.entity_table = 'civicrm_contribution_page'
790 AND civicrm_pcp_block.is_active = 1 )
791 LEFT JOIN civicrm_contribution_widget ON ( civicrm_contribution_widget.contribution_page_id = civicrm_contribution_page.id
792 AND civicrm_contribution_widget.is_active = 1 )
793 LEFT JOIN civicrm_premiums ON ( civicrm_premiums.entity_id = civicrm_contribution_page.id
794 AND civicrm_premiums.entity_table = 'civicrm_contribution_page'
795 AND civicrm_premiums.premiums_active = 1 )
798 $contributionPage = CRM_Core_DAO
::executeQuery($query);
799 while ($contributionPage->fetch()) {
800 if (!isset($info[$contributionPage->id
]) ||
!is_array($info[$contributionPage->id
])) {
801 $info[$contributionPage->id
] = array_fill_keys(array_values($sections), FALSE);
803 foreach ($sections as $section) {
804 if ($contributionPage->$section) {
805 $info[$contributionPage->id
][$section] = TRUE;
814 * Get options for a given field.
815 * @see CRM_Core_DAO::buildOptions
817 * @param string $fieldName
818 * @param string $context: @see CRM_Core_DAO::buildOptionsContext
819 * @param array $props: whatever is known about this dao object
823 public static function buildOptions($fieldName, $context = NULL, $props = array()) {
825 // Special logic for fields whose options depend on context or properties
826 switch ($fieldName) {
827 case 'financial_type_id':
828 // Fixme - this is going to ignore context, better to get conditions, add params, and call PseudoConstant::get
829 return CRM_Financial_BAO_FinancialType
::getIncomeFinancialType();
833 return CRM_Core_PseudoConstant
::get(__CLASS__
, $fieldName, $params, $context);
837 * Get or Set multilingually affected honor params for processing module_data or setting default values.
839 * @param string $params:
840 * @param bool $setDefault: If yes then returns array to used for setting default value afterward
842 * @return array|string
844 public static function formatMultilingualHonorParams($params, $setDefault = FALSE) {
845 $config = CRM_Core_Config
::singleton();
846 $sctJson = $sctJsonDecode = NULL;
847 $domain = new CRM_Core_DAO_Domain();
850 //When we are fetching the honor params respecting both multi and mono lingual state
851 //and setting it to default param of Contribution Page's Main and Setting form
853 $sctJsonDecode = json_decode($params);
854 $sctJsonDecode = (array) $sctJsonDecode->soft_credit
;
855 if (!$domain->locales
&& !empty($sctJsonDecode['default'])) {
857 $sctJsonDecode +
= (array) $sctJsonDecode['default'];
859 elseif (!empty($sctJsonDecode[$config->lcMessages
])) {
861 foreach ($sctJsonDecode[$config->lcMessages
] as $column => $value) {
862 $sctJsonDecode[$column] = $value;
864 unset($sctJsonDecode[$config->lcMessages
]);
866 return $sctJsonDecode;
869 //check and handle multilingual honoree params
870 if (!$domain->locales
) {
871 //if in singlelingual state simply return the array format
872 $sctJson = json_encode(
874 'soft_credit' => array(
875 'soft_credit_types' => $params['soft_credit_types'],
877 'honor_block_title' => $params['honor_block_title'],
878 'honor_block_text' => $params['honor_block_text'],
885 //if in multilingual state then retrieve the module_data against this contribution and
886 //merge with earlier module_data json data to current so not to lose earlier multilingual module_data information
888 'soft_credit' => array(
889 'soft_credit_types' => $params['soft_credit_types'],
890 $config->lcMessages
=> array(
891 'honor_block_title' => $params['honor_block_title'],
892 'honor_block_text' => $params['honor_block_text'],
897 $ufJoinDAO = new CRM_Core_DAO_UFJoin();
898 $ufJoinDAO->module
= 'soft_credit';
899 $ufJoinDAO->entity_id
= $params['id'];
900 $ufJoinDAO->find(TRUE);
901 $jsonData = json_decode($ufJoinDAO->module_data
);
903 $sctJson['soft_credit'] = array_merge((array) $jsonData->soft_credit
, $sctJson['soft_credit']);
905 $sctJson = json_encode($sctJson);
911 * Generate html for pdf in confirmation receipt email attachment
912 * @param int $contributionId
913 * Contribution Page Id.
915 * Contact id for contributor.
916 * @return array $pdfHtml
918 public static function addInvoicePdfToEmail($contributionId, $userID) {
919 $contributionID = array($contributionId);
920 $contactId = array($userID);
922 'output' => 'pdf_invoice',
923 'forPage' => 'confirmpage',
925 $pdfHtml = CRM_Contribute_Form_Task_Invoice
::printPDF($contributionID,
926 $pdfParams, $contactId, CRM_Core_DAO
::$_nullObject);
931 * Helper to determine if the page supports separate membership payments
932 * @param int id form id
934 * @return bool isSeparateMembershipPayment
936 public static function getIsMembershipPayment($id) {
937 $membershipBlocks = civicrm_api3('membership_block', 'get', array('entity_table' => 'civicrm_contribution_page', 'entity_id' => $id, 'sequential' => TRUE));
938 if (!$membershipBlocks['count']) {
941 return $membershipBlocks['values'][0]['is_separate_payment'];