3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 class CRM_Contribute_Page_UserDashboard
extends CRM_Contact_Page_View_UserDashBoard
{
20 * called when action is browse.
22 public function listContribution() {
23 $rows = civicrm_api3('Contribution', 'get', [
26 'sort' => 'receive_date DESC',
29 'contact_id' => $this->_contactId
,
32 'contribution_recur_id',
36 'contribution_status',
40 'contribution_source',
44 // We want oldest first, just among the most recent contributions
45 $rows = array_reverse($rows);
47 foreach ($rows as $index => &$row) {
48 // This is required for tpl logic. We should move away from hard-code this to adding an array of actions to the row
49 // which the tpl can iterate through - this should allow us to cope with competing attempts to add new buttons
50 // and allow extensions to assign new ones through the pageRun hook
51 $row['balance_amount'] = CRM_Contribute_BAO_Contribution
::getContributionBalance($row['contribution_id']);
52 $contributionStatus = CRM_Core_PseudoConstant
::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $row['contribution_status_id']);
54 if (in_array($contributionStatus, ['Pending', 'Partially paid'])) {
55 $row['buttons']['pay'] = [
57 'label' => ts('Pay Now'),
58 'url' => CRM_Utils_System
::url('civicrm/contribute/transact', [
60 'id' => Civi
::settings()->get('default_invoice_page'),
61 'ccid' => $row['contribution_id'],
62 'cs' => $this->getUserChecksum(),
63 'cid' => $row['contact_id'],
69 $this->assign('contribute_rows', $rows);
70 $this->assign('contributionSummary', ['total_amount' => civicrm_api3('Contribution', 'getcount', ['contact_id' => $this->_contactId
])]);
73 $params = CRM_Contribute_BAO_Contribution
::getHonorContacts($this->_contactId
);
75 if (!empty($params)) {
76 // assign vars to templates
77 $this->assign('honorRows', $params);
78 $this->assign('honor', TRUE);
81 $recur = new CRM_Contribute_DAO_ContributionRecur();
82 $recur->contact_id
= $this->_contactId
;
86 $recurStatus = CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'label');
90 while ($recur->fetch()) {
91 if (empty($recur->payment_processor_id
)) {
92 // it's not clear why we continue here as any without a processor id would likely
93 // be imported from another system & still seem valid.
97 require_once 'api/v3/utils.php';
98 //@todo calling api functions directly is not supported
99 _civicrm_api3_object_to_array($recur, $values);
101 $values['recur_status'] = $recurStatus[$values['contribution_status_id']];
102 $recurRow[$values['id']] = $values;
104 $action = array_sum(array_keys(CRM_Contribute_Page_Tab
::dashboardRecurLinks((int) $recur->id
, (int) $recur->contact_id
)));
106 $details = CRM_Contribute_BAO_ContributionRecur
::getSubscriptionDetails($recur->id
, 'recur');
107 $hideUpdate = $details->membership_id
& $details->auto_renew
;
110 $action -= CRM_Core_Action
::UPDATE
;
113 $recurRow[$values['id']]['action'] = CRM_Core_Action
::formLink(CRM_Contribute_Page_Tab
::dashboardRecurLinks((int) $recur->id
, (int) $this->_contactId
),
115 'cid' => $this->_contactId
,
116 'crid' => $values['id'],
117 'cxt' => 'contribution',
121 'contribution.dashboard.recurring',
126 $recurIDs[] = $values['id'];
128 if (is_array($recurIDs) && !empty($recurIDs)) {
129 $getCount = CRM_Contribute_BAO_ContributionRecur
::getCount($recurIDs);
130 foreach ($getCount as $key => $val) {
131 $recurRow[$key]['completed'] = $val;
132 $recurRow[$key]['link'] = CRM_Utils_System
::url('civicrm/contribute/search',
133 "reset=1&force=1&recur=$key"
138 $this->assign('recurRows', $recurRow);
139 if (!empty($recurRow)) {
140 $this->assign('recur', TRUE);
143 $this->assign('recur', FALSE);
148 * Should invoice links be displayed on the template.
150 * @todo This should be moved to a hook-like structure on the invoicing class
151 * (currently CRM_Utils_Invoicing) with a view to possible removal from core.
153 public function isIncludeInvoiceLinks() {
154 if (!CRM_Invoicing_Utils
::isInvoicingEnabled()) {
157 $dashboardOptions = CRM_Core_BAO_Setting
::valueOptions(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
158 'user_dashboard_options'
160 return $dashboardOptions['Invoices / Credit Notes'];
164 * the main function that is called when the page
165 * loads, it decides the which action has to be taken for the page.
167 public function run() {
168 $this->assign('isIncludeInvoiceLinks', $this->isIncludeInvoiceLinks());
169 parent
::preProcess();
170 $this->listContribution();