Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
6a488035 TO |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
6b83d5bd | 31 | * @copyright CiviCRM LLC (c) 2004-2019 |
6a488035 TO |
32 | */ |
33 | class CRM_Contribute_Page_UserDashboard extends CRM_Contact_Page_View_UserDashBoard { | |
34 | ||
35 | /** | |
fe482240 | 36 | * called when action is browse. |
6a488035 | 37 | */ |
00be9182 | 38 | public function listContribution() { |
8bfce657 | 39 | $rows = civicrm_api3('Contribution', 'get', [ |
4a94e641 AH |
40 | 'options' => [ |
41 | 'limit' => 12, | |
42 | 'sort' => 'receive_date DESC', | |
43 | ], | |
8bfce657 | 44 | 'sequential' => 1, |
45 | 'contact_id' => $this->_contactId, | |
46 | 'return' => [ | |
47 | 'total_amount', | |
48 | 'contribution_recur_id', | |
49 | 'financial_type', | |
50 | 'receive_date', | |
51 | 'receipt_date', | |
52 | 'contribution_status', | |
53 | 'currency', | |
54 | 'amount_level', | |
55 | 'contact_id,', | |
56 | 'contribution_source', | |
57 | ], | |
58 | ])['values']; | |
59 | ||
4a94e641 AH |
60 | // We want oldest first, just among the most recent contributions |
61 | $rows = array_reverse($rows); | |
62 | ||
10f949e6 | 63 | foreach ($rows as $index => &$row) { |
8bfce657 | 64 | // This is required for tpl logic. We should move away from hard-code this to adding an array of actions to the row |
65 | // which the tpl can iterate through - this should allow us to cope with competing attempts to add new buttons | |
66 | // and allow extensions to assign new ones through the pageRun hook | |
10f949e6 | 67 | if ('Pending' === CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $row['contribution_status_id'])) { |
68 | $row['buttons']['pay'] = [ | |
69 | 'class' => 'button', | |
70 | 'label' => ts('Pay Now'), | |
71 | 'url' => CRM_Utils_System::url('civicrm/contribute/transact', [ | |
72 | 'reset' => 1, | |
73 | 'id' => CRM_Invoicing_Utils::getDefaultPaymentPage(), | |
74 | 'ccid' => $row['contribution_id'], | |
75 | 'cs' => $this->getUserChecksum(), | |
76 | 'cid' => $row['contact_id'], | |
5ba7d840 | 77 | ]), |
10f949e6 | 78 | ]; |
79 | } | |
8bfce657 | 80 | } |
81 | ||
82 | $this->assign('contribute_rows', $rows); | |
83 | $this->assign('contributionSummary', ['total_amount' => civicrm_api3('Contribution', 'getcount', ['contact_id' => $this->_contactId])]); | |
6a488035 TO |
84 | |
85 | //add honor block | |
6a488035 TO |
86 | $params = CRM_Contribute_BAO_Contribution::getHonorContacts($this->_contactId); |
87 | ||
88 | if (!empty($params)) { | |
89 | // assign vars to templates | |
90 | $this->assign('honorRows', $params); | |
91 | $this->assign('honor', TRUE); | |
92 | } | |
93 | ||
353ffa53 | 94 | $recur = new CRM_Contribute_DAO_ContributionRecur(); |
6a488035 | 95 | $recur->contact_id = $this->_contactId; |
353ffa53 | 96 | $recur->is_test = 0; |
6a488035 TO |
97 | $recur->find(); |
98 | ||
6a488035 TO |
99 | $recurStatus = CRM_Contribute_PseudoConstant::contributionStatus(); |
100 | ||
be2fb01f CW |
101 | $recurRow = []; |
102 | $recurIDs = []; | |
6a488035 | 103 | while ($recur->fetch()) { |
1a18d24f | 104 | if (empty($recur->payment_processor_id)) { |
105 | // it's not clear why we continue here as any without a processor id would likely | |
106 | // be imported from another system & still seem valid. | |
6a488035 TO |
107 | continue; |
108 | } | |
109 | ||
6a488035 TO |
110 | require_once 'api/v3/utils.php'; |
111 | //@todo calling api functions directly is not supported | |
112 | _civicrm_api3_object_to_array($recur, $values); | |
113 | ||
114 | $values['recur_status'] = $recurStatus[$values['contribution_status_id']]; | |
115 | $recurRow[$values['id']] = $values; | |
116 | ||
117 | $action = array_sum(array_keys(CRM_Contribute_Page_Tab::recurLinks($recur->id, 'dashboard'))); | |
118 | ||
119 | $details = CRM_Contribute_BAO_ContributionRecur::getSubscriptionDetails($recur->id, 'recur'); | |
120 | $hideUpdate = $details->membership_id & $details->auto_renew; | |
121 | ||
122 | if ($hideUpdate) { | |
123 | $action -= CRM_Core_Action::UPDATE; | |
124 | } | |
125 | ||
126 | $recurRow[$values['id']]['action'] = CRM_Core_Action::formLink(CRM_Contribute_Page_Tab::recurLinks($recur->id, 'dashboard'), | |
be2fb01f | 127 | $action, [ |
6a488035 TO |
128 | 'cid' => $this->_contactId, |
129 | 'crid' => $values['id'], | |
130 | 'cxt' => 'contribution', | |
be2fb01f | 131 | ], |
87dab4a4 AH |
132 | ts('more'), |
133 | FALSE, | |
134 | 'contribution.dashboard.recurring', | |
135 | 'Contribution', | |
136 | $values['id'] | |
6a488035 TO |
137 | ); |
138 | ||
139 | $recurIDs[] = $values['id']; | |
6a488035 TO |
140 | } |
141 | if (is_array($recurIDs) && !empty($recurIDs)) { | |
142 | $getCount = CRM_Contribute_BAO_ContributionRecur::getCount($recurIDs); | |
143 | foreach ($getCount as $key => $val) { | |
144 | $recurRow[$key]['completed'] = $val; | |
145 | $recurRow[$key]['link'] = CRM_Utils_System::url('civicrm/contribute/search', | |
146 | "reset=1&force=1&recur=$key" | |
147 | ); | |
148 | } | |
149 | } | |
150 | ||
151 | $this->assign('recurRows', $recurRow); | |
152 | if (!empty($recurRow)) { | |
153 | $this->assign('recur', TRUE); | |
154 | } | |
155 | else { | |
156 | $this->assign('recur', FALSE); | |
157 | } | |
158 | } | |
159 | ||
10f949e6 | 160 | /** |
161 | * Should invoice links be displayed on the template. | |
162 | * | |
163 | * @todo This should be moved to a hook-like structure on the invoicing class | |
164 | * (currently CRM_Utils_Invoicing) with a view to possible removal from core. | |
165 | */ | |
166 | public function isIncludeInvoiceLinks() { | |
167 | if (!CRM_Invoicing_Utils::isInvoicingEnabled()) { | |
168 | return FALSE; | |
169 | } | |
170 | $dashboardOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, | |
171 | 'user_dashboard_options' | |
172 | ); | |
173 | return $dashboardOptions['Invoices / Credit Notes']; | |
174 | } | |
175 | ||
6a488035 | 176 | /** |
dc195289 | 177 | * the main function that is called when the page |
6a488035 | 178 | * loads, it decides the which action has to be taken for the page. |
6a488035 | 179 | */ |
00be9182 | 180 | public function run() { |
10f949e6 | 181 | $this->assign('isIncludeInvoiceLinks', $this->isIncludeInvoiceLinks()); |
6a488035 TO |
182 | parent::preProcess(); |
183 | $this->listContribution(); | |
184 | } | |
96025800 | 185 | |
6a488035 | 186 | } |