Merge pull request #13890 from aydun/joomla#6
[civicrm-core.git] / CRM / Contribute / Page / ContributionRecur.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
34 /**
35 * Main page for viewing Recurring Contributions.
36 */
37 class CRM_Contribute_Page_ContributionRecur extends CRM_Core_Page {
38
39 public static $_links = NULL;
40 public $_permission = NULL;
41 public $_contactId = NULL;
42 public $_id = NULL;
43 public $_action = NULL;
44
45 /**
46 * View details of a recurring contribution.
47 */
48 public function view() {
49 if (empty($this->_id)) {
50 CRM_Core_Error::statusBounce('Recurring contribution not found');
51 }
52
53 try {
54 $contributionRecur = civicrm_api3('ContributionRecur', 'getsingle', [
55 'id' => $this->_id,
56 ]);
57 }
58 catch (Exception $e) {
59 CRM_Core_Error::statusBounce('Recurring contribution not found (ID: ' . $this->_id);
60 }
61
62 $contributionRecur['payment_processor'] = CRM_Financial_BAO_PaymentProcessor::getPaymentProcessorName(
63 CRM_Utils_Array::value('payment_processor_id', $contributionRecur)
64 );
65 $idFields = ['contribution_status_id', 'campaign_id', 'financial_type_id'];
66 foreach ($idFields as $idField) {
67 if (!empty($contributionRecur[$idField])) {
68 $contributionRecur[substr($idField, 0, -3)] = CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_ContributionRecur', $idField, $contributionRecur[$idField]);
69 }
70 }
71
72 // Add linked membership
73 $membership = civicrm_api3('Membership', 'get', [
74 'contribution_recur_id' => $contributionRecur['id'],
75 ]);
76 if (!empty($membership['count'])) {
77 $membershipDetails = reset($membership['values']);
78 $contributionRecur['membership_id'] = $membershipDetails['id'];
79 $contributionRecur['membership_name'] = $membershipDetails['membership_name'];
80 }
81
82 $groupTree = CRM_Core_BAO_CustomGroup::getTree('ContributionRecur', NULL, $contributionRecur['id']);
83 CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $contributionRecur['id']);
84
85 $this->assign('recur', $contributionRecur);
86
87 $displayName = CRM_Contact_BAO_Contact::displayName($contributionRecur['contact_id']);
88 $this->assign('displayName', $displayName);
89
90 // Check if this is default domain contact CRM-10482
91 if (CRM_Contact_BAO_Contact::checkDomainContact($contributionRecur['contact_id'])) {
92 $displayName .= ' (' . ts('default organization') . ')';
93 }
94
95 // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container
96 CRM_Utils_System::setTitle(ts('View Recurring Contribution from') . ' ' . $displayName);
97 }
98
99 public function preProcess() {
100 $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'view');
101 $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
102 $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
103 $this->assign('contactId', $this->_contactId);
104
105 // check logged in url permission
106 CRM_Contact_Page_View::checkUserPermission($this);
107
108 $this->assign('action', $this->_action);
109
110 if ($this->_permission == CRM_Core_Permission::EDIT && !CRM_Core_Permission::check('edit contributions')) {
111 // demote to view since user does not have edit contrib rights
112 $this->_permission = CRM_Core_Permission::VIEW;
113 $this->assign('permission', 'view');
114 }
115 }
116
117 /**
118 * the main function that is called when the page loads,
119 * it decides the which action has to be taken for the page.
120 *
121 * @return null
122 */
123 public function run() {
124 $this->preProcess();
125
126 if ($this->_action & CRM_Core_Action::VIEW) {
127 $this->view();
128 }
129
130 return parent::run();
131 }
132
133 }