From: eileen Date: Wed, 13 Feb 2019 01:21:57 +0000 (+1300) Subject: Switch userDashboard from using selector object to using the api to get contributions... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=8bfce657bc212f3b5288b6b5c3535fad7323dbfc;p=civicrm-core.git Switch userDashboard from using selector object to using the api to get contributions to display. 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 --- diff --git a/CRM/Contribute/Page/UserDashboard.php b/CRM/Contribute/Page/UserDashboard.php index 68af603cf2..608d0060bc 100644 --- a/CRM/Contribute/Page/UserDashboard.php +++ b/CRM/Contribute/Page/UserDashboard.php @@ -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(); diff --git a/templates/CRM/Contribute/Page/UserDashboard.tpl b/templates/CRM/Contribute/Page/UserDashboard.tpl index 182dd22679..0c25b8f393 100644 --- a/templates/CRM/Contribute/Page/UserDashboard.tpl +++ b/templates/CRM/Contribute/Page/UserDashboard.tpl @@ -58,6 +58,7 @@ {$row.contribution_status} {if $invoicing && $invoices} + {* @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 @@ {/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*} {assign var='checksum_url' value=""} {if $userChecksum} diff --git a/tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php b/tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php index d8e7625797..d699dbf572 100644 --- a/tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php +++ b/tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php @@ -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', ]); }