Merge branch '4.5' into master
[civicrm-core.git] / CRM / Contribute / Page / UserDashboard.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
32 * $Id$
33 *
34 */
35 class CRM_Contribute_Page_UserDashboard extends CRM_Contact_Page_View_UserDashBoard {
36
37 /**
38 * called when action is browse
39 *
40 * @return null
41 */
42 public function listContribution() {
43 $controller = new CRM_Core_Controller_Simple(
44 'CRM_Contribute_Form_Search',
45 ts('Contributions'),
46 NULL,
47 FALSE, FALSE, TRUE, FALSE
48 );
49 $controller->setEmbedded(TRUE);
50 $controller->reset();
51 $controller->set('limit', 12);
52 $controller->set('cid', $this->_contactId);
53 $controller->set('context', 'user');
54 $controller->set('force', 1);
55 $controller->process();
56 $controller->run();
57
58 //add honor block
59 $params = array();
60 $params = CRM_Contribute_BAO_Contribution::getHonorContacts($this->_contactId);
61
62 if (!empty($params)) {
63 // assign vars to templates
64 $this->assign('honorRows', $params);
65 $this->assign('honor', TRUE);
66 }
67
68 $recur = new CRM_Contribute_DAO_ContributionRecur();
69 $recur->contact_id = $this->_contactId;
70 $recur->is_test = 0;
71 $recur->find();
72
73 $config = CRM_Core_Config::singleton();
74
75 $recurStatus = CRM_Contribute_PseudoConstant::contributionStatus();
76
77 $recurRow = array();
78 $recurIDs = array();
79 while ($recur->fetch()) {
80 $mode = $recur->is_test ? 'test' : 'live';
81 $paymentProcessor = CRM_Contribute_BAO_ContributionRecur::getPaymentProcessor($recur->id,
82 $mode
83 );
84 if (!$paymentProcessor) {
85 continue;
86 }
87
88 // note that we are passing a CRM_Core_Page object ($this) as if it were a form here:
89 $paymentObject = CRM_Core_Payment::singleton($mode, $paymentProcessor, $this);
90
91 require_once 'api/v3/utils.php';
92 //@todo calling api functions directly is not supported
93 _civicrm_api3_object_to_array($recur, $values);
94
95 $values['recur_status'] = $recurStatus[$values['contribution_status_id']];
96 $recurRow[$values['id']] = $values;
97
98 $action = array_sum(array_keys(CRM_Contribute_Page_Tab::recurLinks($recur->id, 'dashboard')));
99
100 $details = CRM_Contribute_BAO_ContributionRecur::getSubscriptionDetails($recur->id, 'recur');
101 $hideUpdate = $details->membership_id & $details->auto_renew;
102
103 if ($hideUpdate) {
104 $action -= CRM_Core_Action::UPDATE;
105 }
106
107 $recurRow[$values['id']]['action'] = CRM_Core_Action::formLink(CRM_Contribute_Page_Tab::recurLinks($recur->id, 'dashboard'),
108 $action, array(
109 'cid' => $this->_contactId,
110 'crid' => $values['id'],
111 'cxt' => 'contribution',
112 ),
113 ts('more'),
114 FALSE,
115 'contribution.dashboard.recurring',
116 'Contribution',
117 $values['id']
118 );
119
120 $recurIDs[] = $values['id'];
121
122 //reset $paymentObject for checking other paymenet processor
123 //recurring url
124 $paymentObject = NULL;
125 }
126 if (is_array($recurIDs) && !empty($recurIDs)) {
127 $getCount = CRM_Contribute_BAO_ContributionRecur::getCount($recurIDs);
128 foreach ($getCount as $key => $val) {
129 $recurRow[$key]['completed'] = $val;
130 $recurRow[$key]['link'] = CRM_Utils_System::url('civicrm/contribute/search',
131 "reset=1&force=1&recur=$key"
132 );
133 }
134 }
135
136 $this->assign('recurRows', $recurRow);
137 if (!empty($recurRow)) {
138 $this->assign('recur', TRUE);
139 }
140 else {
141 $this->assign('recur', FALSE);
142 }
143 }
144
145 /**
146 * the main function that is called when the page
147 * loads, it decides the which action has to be taken for the page.
148 *
149 * @return null
150 */
151 public function run() {
152 $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
153 $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
154 $this->assign('invoicing', $invoicing);
155 parent::preProcess();
156 $this->listContribution();
157 }
158 }