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 if ('Pending' === CRM_Core_PseudoConstant
::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $row['contribution_status_id'])) {
52 $row['buttons']['pay'] = [
54 'label' => ts('Pay Now'),
55 'url' => CRM_Utils_System
::url('civicrm/contribute/transact', [
57 'id' => Civi
::settings()->get('default_invoice_page'),
58 'ccid' => $row['contribution_id'],
59 'cs' => $this->getUserChecksum(),
60 'cid' => $row['contact_id'],
66 $this->assign('contribute_rows', $rows);
67 $this->assign('contributionSummary', ['total_amount' => civicrm_api3('Contribution', 'getcount', ['contact_id' => $this->_contactId
])]);
70 $params = CRM_Contribute_BAO_Contribution
::getHonorContacts($this->_contactId
);
72 if (!empty($params)) {
73 // assign vars to templates
74 $this->assign('honorRows', $params);
75 $this->assign('honor', TRUE);
78 $recur = new CRM_Contribute_DAO_ContributionRecur();
79 $recur->contact_id
= $this->_contactId
;
83 $recurStatus = CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'label');
87 while ($recur->fetch()) {
88 if (empty($recur->payment_processor_id
)) {
89 // it's not clear why we continue here as any without a processor id would likely
90 // be imported from another system & still seem valid.
94 require_once 'api/v3/utils.php';
95 //@todo calling api functions directly is not supported
96 _civicrm_api3_object_to_array($recur, $values);
98 $values['recur_status'] = $recurStatus[$values['contribution_status_id']];
99 $recurRow[$values['id']] = $values;
101 $action = array_sum(array_keys(CRM_Contribute_Page_Tab
::recurLinks($recur->id
, 'dashboard')));
103 $details = CRM_Contribute_BAO_ContributionRecur
::getSubscriptionDetails($recur->id
, 'recur');
104 $hideUpdate = $details->membership_id
& $details->auto_renew
;
107 $action -= CRM_Core_Action
::UPDATE
;
110 $recurRow[$values['id']]['action'] = CRM_Core_Action
::formLink(CRM_Contribute_Page_Tab
::recurLinks($recur->id
, 'dashboard'),
112 'cid' => $this->_contactId
,
113 'crid' => $values['id'],
114 'cxt' => 'contribution',
118 'contribution.dashboard.recurring',
123 $recurIDs[] = $values['id'];
125 if (is_array($recurIDs) && !empty($recurIDs)) {
126 $getCount = CRM_Contribute_BAO_ContributionRecur
::getCount($recurIDs);
127 foreach ($getCount as $key => $val) {
128 $recurRow[$key]['completed'] = $val;
129 $recurRow[$key]['link'] = CRM_Utils_System
::url('civicrm/contribute/search',
130 "reset=1&force=1&recur=$key"
135 $this->assign('recurRows', $recurRow);
136 if (!empty($recurRow)) {
137 $this->assign('recur', TRUE);
140 $this->assign('recur', FALSE);
145 * Should invoice links be displayed on the template.
147 * @todo This should be moved to a hook-like structure on the invoicing class
148 * (currently CRM_Utils_Invoicing) with a view to possible removal from core.
150 public function isIncludeInvoiceLinks() {
151 if (!CRM_Invoicing_Utils
::isInvoicingEnabled()) {
154 $dashboardOptions = CRM_Core_BAO_Setting
::valueOptions(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
155 'user_dashboard_options'
157 return $dashboardOptions['Invoices / Credit Notes'];
161 * the main function that is called when the page
162 * loads, it decides the which action has to be taken for the page.
164 public function run() {
165 $this->assign('isIncludeInvoiceLinks', $this->isIncludeInvoiceLinks());
166 parent
::preProcess();
167 $this->listContribution();