Switch userDashboard from using selector object to using the api to get contributions...
authoreileen <emcnaughton@wikimedia.org>
Wed, 13 Feb 2019 01:21:57 +0000 (14:21 +1300)
committereileen <emcnaughton@wikimedia.org>
Wed, 13 Feb 2019 18:41:43 +0000 (07:41 +1300)
Note that preliminary tests for this were written & merged some time ago.

Reasons for the change are

1) readability - most devs are much more comfortable with reading the api code than the selector
2) performance - the contribute selector code is deeply unperformant - mostly due to the summary function which in
this case is somewhat mitigated by the limit of 12 but we are still doing something slow for no reason
3) test stability - the test for this turned out to have poor stability & hopefully this will help
4) preliminary cleanup - there are 2 existing PRs that attempt to add new buttons to this & moving towards
a cleaner tpl / php layer will help with those. In addition there is a serious performance issue to
address on the contribution summary function. Reducing use of that function should help with the cleanup effort

CRM/Contribute/Page/UserDashboard.php
templates/CRM/Contribute/Page/UserDashboard.tpl
tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php

index 68af603cf224374cf2f5248578bad7cf987a7d3c..608d0060bcbef7f4fe5f5c9f27d27847aa68b497 100644 (file)
@@ -36,20 +36,33 @@ class CRM_Contribute_Page_UserDashboard extends CRM_Contact_Page_View_UserDashBo
    * called when action is browse.
    */
   public function listContribution() {
-    $controller = new CRM_Core_Controller_Simple(
-      'CRM_Contribute_Form_Search',
-      ts('Contributions'),
-      NULL,
-      FALSE, FALSE, TRUE, FALSE
-    );
-    $controller->setEmbedded(TRUE);
-    $controller->reset();
-    $controller->set('limit', 12);
-    $controller->set('cid', $this->_contactId);
-    $controller->set('context', 'user');
-    $controller->set('force', 1);
-    $controller->process();
-    $controller->run();
+    $rows = civicrm_api3('Contribution', 'get', [
+      'options' => ['limit' => 12],
+      'sequential' => 1,
+      'contact_id' => $this->_contactId,
+      'return' => [
+        'total_amount',
+        'contribution_recur_id',
+        'financial_type',
+        'receive_date',
+        'receipt_date',
+        'contribution_status',
+        'currency',
+        'amount_level',
+        'contact_id,',
+        'contribution_source',
+      ],
+    ])['values'];
+
+    foreach ($rows as $index => $row) {
+      // This is required for tpl logic. We should move away from hard-code this to adding an array of actions to the row
+      // which the tpl can iterate through - this should allow us to cope with competing attempts to add new buttons
+      // and allow extensions to assign new ones through the pageRun hook
+      $row[0]['contribution_status_name'] = CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $row['contribution_status_id']);;
+    }
+
+    $this->assign('contribute_rows', $rows);
+    $this->assign('contributionSummary', ['total_amount' => civicrm_api3('Contribution', 'getcount', ['contact_id' => $this->_contactId])]);
 
     //add honor block
     $params = CRM_Contribute_BAO_Contribution::getHonorContacts($this->_contactId);
@@ -65,8 +78,6 @@ class CRM_Contribute_Page_UserDashboard extends CRM_Contact_Page_View_UserDashBo
     $recur->is_test = 0;
     $recur->find();
 
-    $config = CRM_Core_Config::singleton();
-
     $recurStatus = CRM_Contribute_PseudoConstant::contributionStatus();
 
     $recurRow = array();
index 182dd22679ae45caa38830416805c005d99574eb..0c25b8f39366cb9a1662f08380fe05e61e4e86d0 100644 (file)
@@ -58,6 +58,7 @@
                         <td>{$row.contribution_status}</td>
                         {if $invoicing && $invoices}
                           <td>
+                            {* @todo Instead of this tpl handling assign actions as an array attached the row, iterate through - will better accomodate extension overrides and competition for scarce real estate on this page*}
                             {assign var='id' value=$row.contribution_id}
                             {assign var='contact_id' value=$row.contact_id}
                             {assign var='urlParams' value="reset=1&id=$id&cid=$contact_id"}
@@ -75,6 +76,7 @@
                           </td>
                         {/if}
                         {if $defaultInvoicePage && $row.contribution_status_name == 'Pending' }
+                          {* @todo Instead of this tpl handling assign actions as an array attached the row, iterate through - will better accomodate extension overrides and competition for scarce real estate on this page*}
                           <td>
                             {assign var='checksum_url' value=""}
                             {if $userChecksum}
index d8e7625797967726e92157dfdf2511df55490a24..d699dbf5729b0fa6f03b5f2c100ecbe50b3eac21 100644 (file)
@@ -134,7 +134,7 @@ class CRM_Contact_Page_View_UserDashBoardTest extends CiviUnitTestCase {
       'receive_date' => '2018-11-21 00:00:00',
       'contribution_status' => 'Completed',
       'currency' => 'USD',
-      //'receipt_date' => '2018-11-22 00:00:00',
+      'receipt_date' => '2018-11-22 00:00:00',
     ]);
 
   }