Merge pull request #15813 from eileenmcnaughton/fee
[civicrm-core.git] / CRM / Contribute / Page / Tab.php
index f87dff5bbc7857455714a6b6fd4f4d24eee5837e..c84e1198b80806aa04ba44633426a39271494d7b 100644 (file)
@@ -1,46 +1,38 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 5                                                  |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2019                                |
- +--------------------------------------------------------------------+
- | This file is a part of CiviCRM.                                    |
- |                                                                    |
- | CiviCRM is free software; you can copy, modify, and distribute it  |
- | under the terms of the GNU Affero General Public License           |
- | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ | Copyright CiviCRM LLC. All rights reserved.                        |
  |                                                                    |
- | CiviCRM is distributed in the hope that it will be useful, but     |
- | WITHOUT ANY WARRANTY; without even the implied warranty of         |
- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
- | See the GNU Affero General Public License for more details.        |
- |                                                                    |
- | You should have received a copy of the GNU Affero General Public   |
- | License and the CiviCRM Licensing Exception along                  |
- | with this program; if not, contact CiviCRM LLC                     |
- | at info[AT]civicrm[DOT]org. If you have questions about the        |
- | GNU Affero General Public License or the licensing of CiviCRM,     |
- | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ | This work is published under the GNU AGPLv3 license with some      |
+ | permitted exceptions and without any warranty. For full license    |
+ | and copyright information, see https://civicrm.org/licensing       |
  +--------------------------------------------------------------------+
  */
 
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2019
+ * @copyright CiviCRM LLC https://civicrm.org/licensing
  */
 class CRM_Contribute_Page_Tab extends CRM_Core_Page {
 
   /**
-   * The action links that we need to display for the browse screen.
+   * The permission we have on this contact
    *
-   * @var array
+   * @var string
    */
-  static $_links = NULL;
-  static $_recurLinks = NULL;
   public $_permission = NULL;
+
+  /**
+   * The contact ID for the contributions we are acting on
+   * @var int
+   */
   public $_contactId = NULL;
+
+  /**
+   * The recurring contribution ID (if any)
+   * @var int
+   */
   public $_crid = NULL;
 
   /**
@@ -55,59 +47,56 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page {
    *
    * @return array
    */
-  public static function &recurLinks($recurID = FALSE, $context = 'contribution') {
-    if (!(self::$_links)) {
-      self::$_links = [
-        CRM_Core_Action::VIEW => [
-          'name' => ts('View'),
-          'title' => ts('View Recurring Payment'),
-          'url' => 'civicrm/contact/view/contributionrecur',
-          'qs' => "reset=1&id=%%crid%%&cid=%%cid%%&context={$context}",
-        ],
-        CRM_Core_Action::UPDATE => [
-          'name' => ts('Edit'),
-          'title' => ts('Edit Recurring Payment'),
-          'url' => 'civicrm/contribute/updaterecur',
-          'qs' => "reset=1&action=update&crid=%%crid%%&cid=%%cid%%&context={$context}",
-        ],
-        CRM_Core_Action::DISABLE => [
-          'name' => ts('Cancel'),
-          'title' => ts('Cancel'),
-          'ref' => 'crm-enable-disable',
-        ],
-      ];
-    }
+  public static function recurLinks($recurID = FALSE, $context = 'contribution') {
+    $links = [
+      CRM_Core_Action::VIEW => [
+        'name' => ts('View'),
+        'title' => ts('View Recurring Payment'),
+        'url' => 'civicrm/contact/view/contributionrecur',
+        'qs' => "reset=1&id=%%crid%%&cid=%%cid%%&context={$context}",
+      ],
+      CRM_Core_Action::UPDATE => [
+        'name' => ts('Edit'),
+        'title' => ts('Edit Recurring Payment'),
+        'url' => 'civicrm/contribute/updaterecur',
+        'qs' => "reset=1&action=update&crid=%%crid%%&cid=%%cid%%&context={$context}",
+      ],
+      CRM_Core_Action::DISABLE => [
+        'name' => ts('Cancel'),
+        'title' => ts('Cancel'),
+        'ref' => 'crm-enable-disable',
+      ],
+    ];
 
     if ($recurID) {
-      $links = self::$_links;
       $paymentProcessorObj = CRM_Contribute_BAO_ContributionRecur::getPaymentProcessorObject($recurID);
-      if (!$paymentProcessorObj) {
-        unset($links[CRM_Core_Action::DISABLE]);
-        unset($links[CRM_Core_Action::UPDATE]);
-        return $links;
-      }
-      if ($paymentProcessorObj->supports('cancelRecurring')) {
-        unset($links[CRM_Core_Action::DISABLE]['extra'], $links[CRM_Core_Action::DISABLE]['ref']);
-        $links[CRM_Core_Action::DISABLE]['url'] = "civicrm/contribute/unsubscribe";
-        $links[CRM_Core_Action::DISABLE]['qs'] = "reset=1&crid=%%crid%%&cid=%%cid%%&context={$context}";
-      }
+      if ($paymentProcessorObj) {
+        if ($paymentProcessorObj->supports('cancelRecurring')) {
+          unset($links[CRM_Core_Action::DISABLE]['extra'], $links[CRM_Core_Action::DISABLE]['ref']);
+          $links[CRM_Core_Action::DISABLE]['url'] = "civicrm/contribute/unsubscribe";
+          $links[CRM_Core_Action::DISABLE]['qs'] = "reset=1&crid=%%crid%%&cid=%%cid%%&context={$context}";
+        }
 
-      if ($paymentProcessorObj->supports('UpdateSubscriptionBillingInfo')) {
-        $links[CRM_Core_Action::RENEW] = [
-          'name' => ts('Change Billing Details'),
-          'title' => ts('Change Billing Details'),
-          'url' => 'civicrm/contribute/updatebilling',
-          'qs' => "reset=1&crid=%%crid%%&cid=%%cid%%&context={$context}",
-        ];
-      }
+        if ($paymentProcessorObj->supports('UpdateSubscriptionBillingInfo')) {
+          $links[CRM_Core_Action::RENEW] = [
+            'name' => ts('Change Billing Details'),
+            'title' => ts('Change Billing Details'),
+            'url' => 'civicrm/contribute/updatebilling',
+            'qs' => "reset=1&crid=%%crid%%&cid=%%cid%%&context={$context}",
+          ];
+        }
 
-      if (!$paymentProcessorObj->supports('ChangeSubscriptionAmount') && !$paymentProcessorObj->supports('EditRecurringContribution')) {
+        if (!$paymentProcessorObj->supports('ChangeSubscriptionAmount') && !$paymentProcessorObj->supports('EditRecurringContribution')) {
+          unset($links[CRM_Core_Action::UPDATE]);
+        }
+      }
+      else {
+        unset($links[CRM_Core_Action::DISABLE]);
         unset($links[CRM_Core_Action::UPDATE]);
       }
-      return $links;
     }
 
-    return self::$_links;
+    return $links;
   }
 
   /**
@@ -157,7 +146,8 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page {
         $softCreditTotals['cancel']['count'],
         $softCreditTotals['amount'],
         $softCreditTotals['avg'],
-        $softCreditTotals['cancel']['amount'] // to get cancel amount
+        // to get cancel amount
+        $softCreditTotals['cancel']['amount']
         ) = CRM_Contribute_BAO_ContributionSoft::getSoftContributionTotals($this->_contactId, $isTest);
 
       $this->assign('softCredit', TRUE);
@@ -195,7 +185,7 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page {
    * Loads active recurring contributions for the current contact and formats
    * them to be used on the form.
    *
-   * @return array;
+   * @return array
    */
   private function getActiveRecurringContributions() {
     try {
@@ -217,7 +207,7 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page {
    * Loads inactive recurring contributions for the current contact and formats
    * them to be used on the form.
    *
-   * @return array;
+   * @return array
    */
   private function getInactiveRecurringContributions() {
     try {
@@ -238,7 +228,7 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page {
   /**
    * @param $recurContributions
    *
-   * @return mixed
+   * @return array
    */
   private function buildRecurringContributionsArray($recurContributions) {
     $liveRecurringContributionCount = 0;
@@ -326,6 +316,10 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page {
     return $controller->run();
   }
 
+  /**
+   * @throws \CRM_Core_Exception
+   * @throws \CiviCRM_API3_Exception
+   */
   public function preProcess() {
     $context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this);
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
@@ -338,9 +332,9 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page {
       $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, empty($this->_id));
       if (empty($this->_contactId)) {
         $this->_contactId = civicrm_api3('contribution', 'getvalue', [
-            'id' => $this->_id,
-            'return' => 'contact_id',
-          ]);
+          'id' => $this->_id,
+          'return' => 'contact_id',
+        ]);
       }
       $this->assign('contactId', $this->_contactId);
 
@@ -360,7 +354,8 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page {
    * the main function that is called when the page
    * loads, it decides the which action has to be taken for the page.
    *
-   * @return null
+   * @throws \CRM_Core_Exception
+   * @throws \CiviCRM_API3_Exception
    */
   public function run() {
     $this->preProcess();
@@ -380,9 +375,12 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page {
       $this->browse();
     }
 
-    return parent::run();
+    parent::run();
   }
 
+  /**
+   * @throws \CRM_Core_Exception
+   */
   public function setContext() {
     $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this);
     $context = CRM_Utils_Request::retrieve('context', 'Alphanumeric',