Merge pull request #12760 from civicrm/5.5
[civicrm-core.git] / CRM / Contribute / Page / ContributionRecur.php
... / ...
CommitLineData
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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-2018
32 */
33
34/**
35 * Main page for viewing Recurring Contributions.
36 */
37class CRM_Contribute_Page_ContributionRecur extends CRM_Core_Page {
38
39 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', array(
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 = array('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', array(
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
88 public function preProcess() {
89 $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'view');
90 $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
91 $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
92 $this->assign('contactId', $this->_contactId);
93
94 // check logged in url permission
95 CRM_Contact_Page_View::checkUserPermission($this);
96
97 $this->assign('action', $this->_action);
98
99 if ($this->_permission == CRM_Core_Permission::EDIT && !CRM_Core_Permission::check('edit contributions')) {
100 // demote to view since user does not have edit contrib rights
101 $this->_permission = CRM_Core_Permission::VIEW;
102 $this->assign('permission', 'view');
103 }
104 }
105
106 /**
107 * the main function that is called when the page loads,
108 * it decides the which action has to be taken for the page.
109 *
110 * @return null
111 */
112 public function run() {
113 $this->preProcess();
114
115 if ($this->_action & CRM_Core_Action::VIEW) {
116 $this->view();
117 }
118
119 return parent::run();
120 }
121
122}