CRM-15678 hookable invalid page handling
[civicrm-core.git] / CRM / Contribute / Form / ContributionBase.php
index 2863ddce4a8332c7d74aea229c1e0896f7a0a854..31919c8314ace3f28778b55b2ee8c41447f6a38d 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
 class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
 
   /**
-   * the id of the contribution page that we are processsing
+   * The id of the contribution page that we are processsing
    *
    * @var int
-   * @public
    */
   public $_id;
 
   /**
-   * the mode that we are in
+   * The mode that we are in
    *
    * @var string
    * @protect
@@ -56,26 +55,23 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
   public $_mode;
 
   /**
-   * the contact id related to a membership
+   * The contact id related to a membership
    *
    * @var int
-   * @public
    */
   public $_membershipContactID;
 
   /**
-   * the values for the contribution db object
+   * The values for the contribution db object
    *
    * @var array
-   * @protected
    */
   public $_values;
 
   /**
-   * the paymentProcessor attributes for this page
+   * The paymentProcessor attributes for this page
    *
    * @var array
-   * @protected
    */
   public $_paymentProcessor;
   public $_paymentObject = NULL;
@@ -84,7 +80,6 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
    * The membership block for this page
    *
    * @var array
-   * @protected
    */
   public $_membershipBlock = NULL;
 
@@ -94,10 +89,9 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
    */
   protected $_separateMembershipPayment;
   /**
-   * the default values for the form
+   * The default values for the form
    *
    * @var array
-   * @protected
    */
   protected $_defaults;
 
@@ -105,7 +99,6 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
    * The params submitted by the form and computed by the app
    *
    * @var array
-   * @public
    */
   public $_params;
 
@@ -113,7 +106,6 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
    * The fields involved in this contribution page
    *
    * @var array
-   * @public
    */
   public $_fields = array();
 
@@ -121,7 +113,6 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
    * The billing location id for this contribiution page
    *
    * @var int
-   * @protected
    */
   public $_bltID;
 
@@ -129,31 +120,27 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
    * Cache the amount to make things easier
    *
    * @var float
-   * @public
    */
   public $_amount;
 
   /**
-   * pcp id
+   * Pcp id
    *
    * @var integer
-   * @public
    */
   public $_pcpId;
 
   /**
-   * pcp block
+   * Pcp block
    *
    * @var array
-   * @public
    */
   public $_pcpBlock;
 
   /**
-   * pcp info
+   * Pcp info
    *
    * @var array
-   * @public
    */
   public $_pcpInfo;
 
@@ -167,10 +154,9 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
   protected $_userID;
 
   /**
-   * the Membership ID for membership renewal
+   * The Membership ID for membership renewal
    *
    * @var int
-   * @public
    */
   public $_membershipId;
 
@@ -178,7 +164,6 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
    * Price Set ID, if the new price set method is used
    *
    * @var int
-   * @protected
    */
   public $_priceSetId;
 
@@ -186,7 +171,6 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
    * Array of fields for the price set
    *
    * @var array
-   * @protected
    */
   public $_priceSet;
 
@@ -196,7 +180,6 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
    * Is honor block is enabled for this contribution?
    *
    * @var boolean
-   * @protected
    */
   public $_honor_block_is_active = FALSE;
 
@@ -207,19 +190,20 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
   public $_contributeMode;
 
   /**
-   * contribution page supports memberships
+   * Contribution page supports memberships
    * @var boolean
    */
   public $_useForMember;
 
   public $_isBillingAddressRequiredForPayLater;
   /**
-   * set variables up before form is built
+   * Set variables up before form is built
    *
+   * @throws CRM_Contribution_Exception_InactiveContributionPageException
    * @return void
-   * @access public
    */
   public function preProcess() {
+
     $config = CRM_Core_Config::singleton();
     $session = CRM_Core_Session::singleton();
 
@@ -316,10 +300,8 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
 
       CRM_Contribute_BAO_ContributionPage::setValues($this->_id, $this->_values);
 
-      // check if form is active
       if (empty($this->_values['is_active'])) {
-        // form is inactive, die a fatal death
-        CRM_Core_Error::fatal(ts('The page you requested is currently unavailable.'));
+        throw new CRM_Contribute_Exception_InactiveContributionPageException(ts('The page you requested is currently unavailable.'), $this->_id);
       }
 
       // also check for billing informatin
@@ -537,22 +519,20 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
   }
 
   /**
-   * set the default values
+   * Set the default values
    *
    * @return void
-   * @access public
    */
-  function setDefaultValues() {
+  public function setDefaultValues() {
     return $this->_defaults;
   }
 
   /**
-   * assign the minimal set of variables to the template
+   * Assign the minimal set of variables to the template
    *
    * @return void
-   * @access public
    */
-  function assignToTemplate() {
+  public function assignToTemplate() {
     $name = CRM_Utils_Array::value('billing_first_name', $this->_params);
     if (!empty($this->_params['billing_middle_name'])) {
       $name .= " {$this->_params['billing_middle_name']}";
@@ -674,18 +654,17 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
   }
 
   /**
-   * add the custom fields
+   * Add the custom fields
    *
-   * @param $id
-   * @param $name
+   * @param int $id
+   * @param string $name
    * @param bool $viewOnly
    * @param null $profileContactType
    * @param null $fieldTypes
    *
    * @return void
-   * @access public
    */
-  function buildCustom($id, $name, $viewOnly = FALSE, $profileContactType = NULL, $fieldTypes = NULL) {
+  public function buildCustom($id, $name, $viewOnly = FALSE, $profileContactType = NULL, $fieldTypes = NULL) {
     if ($id) {
       $contactID = $this->getContactID();
 
@@ -799,7 +778,7 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
    *
    * @return null|string
    */
-  function checkTemplateFileExists($suffix = NULL) {
+  public function checkTemplateFileExists($suffix = NULL) {
     if ($this->_id) {
       $templateFile = "CRM/Contribute/Form/Contribution/{$this->_id}/{$this->_name}.{$suffix}tpl";
       $template = CRM_Core_Form::getTemplate();
@@ -814,12 +793,11 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
    * Use the form name to create the tpl file name
    *
    * @return string
-   * @access public
    */
   /**
    * @return string
    */
-  function getTemplateFileName() {
+  public function getTemplateFileName() {
     $fileName = $this->checkTemplateFileExists();
     return $fileName ? $fileName : parent::getTemplateFileName();
   }
@@ -829,20 +807,18 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
    * i.e. we dont override
    *
    * @return string
-   * @access public
    */
   /**
    * @return string
    */
-  function overrideExtraTemplateFileName() {
+  public function overrideExtraTemplateFileName() {
     $fileName = $this->checkTemplateFileExists('extra.');
     return $fileName ? $fileName : parent::overrideExtraTemplateFileName();
   }
 
   /**
-   * authenticate pledge user during online payment.
+   * Authenticate pledge user during online payment.
    *
-   * @access public
    *
    * @return void
    */
@@ -913,4 +889,3 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
     }
   }
 }
-