Skip to content

Commit

Permalink
Switch userDashboard from using selector object to using the api to g…
Browse files Browse the repository at this point in the history
…et 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
  • Loading branch information
eileenmcnaughton committed Feb 13, 2019
1 parent cbadec7 commit 8bfce65
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
43 changes: 27 additions & 16 deletions CRM/Contribute/Page/UserDashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -65,8 +78,6 @@ public function listContribution() {
$recur->is_test = 0;
$recur->find();

$config = CRM_Core_Config::singleton();

$recurStatus = CRM_Contribute_PseudoConstant::contributionStatus();

$recurRow = array();
Expand Down
2 changes: 2 additions & 0 deletions templates/CRM/Contribute/Page/UserDashboard.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand All @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function testDashboardContentContributionsWithInvoicingEnabled() {
'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',
]);

}
Expand Down

0 comments on commit 8bfce65

Please sign in to comment.