Merge pull request #12639 from aniesshsethh/issue_314
[civicrm-core.git] / CRM / Contribute / Page / UserDashboard.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2019
32 */
33 class CRM_Contribute_Page_UserDashboard extends CRM_Contact_Page_View_UserDashBoard {
34
35 /**
36 * called when action is browse.
37 */
38 public function listContribution() {
39 $rows = civicrm_api3('Contribution', 'get', [
40 'options' => ['limit' => 12],
41 'sequential' => 1,
42 'contact_id' => $this->_contactId,
43 'return' => [
44 'total_amount',
45 'contribution_recur_id',
46 'financial_type',
47 'receive_date',
48 'receipt_date',
49 'contribution_status',
50 'currency',
51 'amount_level',
52 'contact_id,',
53 'contribution_source',
54 ],
55 ])['values'];
56
57 foreach ($rows as $index => $row) {
58 // This is required for tpl logic. We should move away from hard-code this to adding an array of actions to the row
59 // which the tpl can iterate through - this should allow us to cope with competing attempts to add new buttons
60 // and allow extensions to assign new ones through the pageRun hook
61 $row[0]['contribution_status_name'] = CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $row['contribution_status_id']);;
62 }
63
64 $this->assign('contribute_rows', $rows);
65 $this->assign('contributionSummary', ['total_amount' => civicrm_api3('Contribution', 'getcount', ['contact_id' => $this->_contactId])]);
66
67 //add honor block
68 $params = CRM_Contribute_BAO_Contribution::getHonorContacts($this->_contactId);
69
70 if (!empty($params)) {
71 // assign vars to templates
72 $this->assign('honorRows', $params);
73 $this->assign('honor', TRUE);
74 }
75
76 $recur = new CRM_Contribute_DAO_ContributionRecur();
77 $recur->contact_id = $this->_contactId;
78 $recur->is_test = 0;
79 $recur->find();
80
81 $recurStatus = CRM_Contribute_PseudoConstant::contributionStatus();
82
83 $recurRow = array();
84 $recurIDs = array();
85 while ($recur->fetch()) {
86 if (empty($recur->payment_processor_id)) {
87 // it's not clear why we continue here as any without a processor id would likely
88 // be imported from another system & still seem valid.
89 continue;
90 }
91
92 require_once 'api/v3/utils.php';
93 //@todo calling api functions directly is not supported
94 _civicrm_api3_object_to_array($recur, $values);
95
96 $values['recur_status'] = $recurStatus[$values['contribution_status_id']];
97 $recurRow[$values['id']] = $values;
98
99 $action = array_sum(array_keys(CRM_Contribute_Page_Tab::recurLinks($recur->id, 'dashboard')));
100
101 $details = CRM_Contribute_BAO_ContributionRecur::getSubscriptionDetails($recur->id, 'recur');
102 $hideUpdate = $details->membership_id & $details->auto_renew;
103
104 if ($hideUpdate) {
105 $action -= CRM_Core_Action::UPDATE;
106 }
107
108 $recurRow[$values['id']]['action'] = CRM_Core_Action::formLink(CRM_Contribute_Page_Tab::recurLinks($recur->id, 'dashboard'),
109 $action, array(
110 'cid' => $this->_contactId,
111 'crid' => $values['id'],
112 'cxt' => 'contribution',
113 ),
114 ts('more'),
115 FALSE,
116 'contribution.dashboard.recurring',
117 'Contribution',
118 $values['id']
119 );
120
121 $recurIDs[] = $values['id'];
122 }
123 if (is_array($recurIDs) && !empty($recurIDs)) {
124 $getCount = CRM_Contribute_BAO_ContributionRecur::getCount($recurIDs);
125 foreach ($getCount as $key => $val) {
126 $recurRow[$key]['completed'] = $val;
127 $recurRow[$key]['link'] = CRM_Utils_System::url('civicrm/contribute/search',
128 "reset=1&force=1&recur=$key"
129 );
130 }
131 }
132
133 $this->assign('recurRows', $recurRow);
134 if (!empty($recurRow)) {
135 $this->assign('recur', TRUE);
136 }
137 else {
138 $this->assign('recur', FALSE);
139 }
140 }
141
142 /**
143 * the main function that is called when the page
144 * loads, it decides the which action has to be taken for the page.
145 */
146 public function run() {
147 $this->assign('invoicing', CRM_Invoicing_Utils::isInvoicingEnabled());
148 $this->assign('defaultInvoicePage', CRM_Invoicing_Utils::getDefaultPaymentPage());
149 parent::preProcess();
150 $this->listContribution();
151 }
152
153 }