Merge remote-tracking branch 'upstream/4.5' into 4.5-master-2014-12-16-01-08-03
[civicrm-core.git] / CRM / Contribute / BAO / ContributionPage.php
index da921d378e668a3c361548f791fb4489c88c31aa..d8b1ed153320d78d002313fbeea3a2a159ed4896 100644 (file)
 class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_ContributionPage {
 
   /**
-   * takes an associative array and creates a contribution page object
+   * Takes an associative array and creates a contribution page object
    *
    * @param array $params (reference ) an assoc array of name/value pairs
    *
-   * @return object CRM_Contribute_DAO_ContributionPage object
+   * @return CRM_Contribute_DAO_ContributionPage object
    * @access public
    * @static
    */
@@ -52,17 +52,20 @@ class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_Contributio
     if (!empty($params['id']) && !CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $params['id'], NULL, 1)) {
       $financialTypeId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $params['id'], 'financial_type_id');
     }
+    $hook = empty($params['id']) ? 'create' : 'edit';
+    CRM_Utils_Hook::pre($hook, 'ContributionPage', CRM_Utils_Array::value('id', $params), $params);
     $dao = new CRM_Contribute_DAO_ContributionPage();
     $dao->copyValues($params);
     $dao->save();
     if ($financialTypeId && !empty($params['financial_type_id']) && $financialTypeId != $params['financial_type_id']) {
       CRM_Price_BAO_PriceFieldValue::updateFinancialType($params['id'], 'civicrm_contribution_page', $params['financial_type_id']);
     }
+    CRM_Utils_Hook::post($hook, 'ContributionPage', $dao->id, $dao);
     return $dao;
   }
 
   /**
-   * update the is_active flag in the db
+   * Update the is_active flag in the db
    *
    * @param int      $id        id of the database record
    * @param boolean  $is_active value we want to set the is_active field
@@ -75,7 +78,7 @@ class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_Contributio
   }
 
   /**
-   * @param $id
+   * @param int $id
    * @param $values
    */
   static function setValues($id, &$values) {
@@ -106,7 +109,7 @@ class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_Contributio
     }
 
   /**
-   * Function to send the emails
+   * Send the emails
    *
    * @param int $contactID contact id
    * @param array $values associated array of fields
@@ -393,6 +396,15 @@ class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_Contributio
         $sendTemplateParams['toEmail'] = $email;
         $sendTemplateParams['cc'] = CRM_Utils_Array::value('cc_receipt', $values);
         $sendTemplateParams['bcc'] = CRM_Utils_Array::value('bcc_receipt', $values);
+        //send email with pdf invoice
+        $template = CRM_Core_Smarty::singleton( );
+        $taxAmt = $template->get_template_vars('dataArray');
+        $prefixValue = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
+        $invoicing = CRM_Utils_Array::value('invoicing', $prefixValue);
+        if (count($taxAmt) > 0 && (isset($invoicing) && isset($prefixValue['is_email_pdf']))) {
+          $sendTemplateParams['isEmailPdf'] = True;
+          $sendTemplateParams['contributionId'] = $values['contribution_id'];
+        }
         list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
       }
 
@@ -414,13 +426,11 @@ class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_Contributio
     }
   }
 
-  /*
-     * Construct the message to be sent by the send function
-     *
-     */
   /**
-   * @param $tplParams
-   * @param $contactID
+   * Construct the message to be sent by the send function
+   *
+   * @param array $tplParams
+   * @param int $contactID
    * @param $isTest
    *
    * @return array
@@ -446,7 +456,7 @@ class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_Contributio
   }
 
   /**
-   * Function to send the emails for Recurring Contribution Notication
+   * Send the emails for Recurring Contribution Notication
    *
    * @param string $type txnType
    * @param int $contactID contact id for contributor
@@ -544,7 +554,7 @@ class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_Contributio
   }
 
   /**
-   * Function to add the custom fields for contribution page (ie profile)
+   * Add the custom fields for contribution page (ie profile)
    *
    * @param int $gid uf group id
    * @param string $name
@@ -691,7 +701,7 @@ WHERE entity_table = 'civicrm_contribution_page'
   }
 
   /**
-   * Function to check if contribution page contains payment
+   * Check if contribution page contains payment
    * processor that supports recurring payment
    *
    * @param int $contributionPageId Contribution Page Id
@@ -719,7 +729,7 @@ WHERE entity_table = 'civicrm_contribution_page'
   }
 
   /**
-   * Function to get info for all sections enable/disable.
+   * Get info for all sections enable/disable.
    *
    * @param array $contribPageIds
    * @return array $info info regarding all sections.
@@ -887,9 +897,26 @@ LEFT JOIN  civicrm_premiums            ON ( civicrm_premiums.entity_id = civicrm
     return $sctJson;
   }
 
+   /**
+   * Generate html for pdf in confirmation receipt email  attachment
+   * @param int $contributionId Contribution Page Id
+   * @param int $userID contact id for contributor
+   * @return array $pdfHtml
+   */
+  static function addInvoicePdfToEmail($contributionId, $userID) {
+    $contributionID = array($contributionId);
+    $contactId = array($userID);
+    $pdfParams = array(
+      'output' => 'pdf_invoice',
+      'forPage' => 'confirmpage'
+    );
+    $pdfHtml = CRM_Contribute_Form_Task_Invoice::printPDF($contributionID,
+      $pdfParams, $contactId, CRM_Core_DAO::$_nullObject);
+    return $pdfHtml;
+  }
 
   /**
-   * helper to determine if the page supports separate membership payments
+   * Helper to determine if the page supports separate membership payments
    * @param integer id form id
    *
    * @return bool isSeparateMembershipPayment