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