Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
8c9251b3 | 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
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 | |
8c9251b3 | 31 | * @copyright CiviCRM LLC (c) 2004-2018 |
6a488035 TO |
32 | */ |
33 | ||
34 | /** | |
35 | * Main page for viewing Recurring Contributions. | |
6a488035 TO |
36 | */ |
37 | class CRM_Contribute_Page_ContributionRecur extends CRM_Core_Page { | |
38 | ||
39 | static $_links = NULL; | |
40 | public $_permission = NULL; | |
41 | public $_contactId = NULL; | |
85b68a11 CR |
42 | public $_id = NULL; |
43 | public $_action = NULL; | |
6a488035 TO |
44 | |
45 | /** | |
fe482240 | 46 | * View details of a recurring contribution. |
95ea96be | 47 | */ |
d5cc0fc2 | 48 | public function view() { |
46097c9c MW |
49 | if (empty($this->_id)) { |
50 | CRM_Core_Error::statusBounce('Recurring contribution not found'); | |
51 | } | |
6a488035 | 52 | |
46097c9c MW |
53 | try { |
54 | $contributionRecur = civicrm_api3('ContributionRecur', 'getsingle', array( | |
55 | 'id' => $this->_id, | |
fadaea59 | 56 | )); |
46097c9c MW |
57 | } |
58 | catch (Exception $e) { | |
59 | CRM_Core_Error::statusBounce('Recurring contribution not found (ID: ' . $this->_id); | |
60 | } | |
61 | ||
85b68a11 CR |
62 | $contributionRecur['payment_processor'] = CRM_Financial_BAO_PaymentProcessor::getPaymentProcessorName( |
63 | CRM_Utils_Array::value('payment_processor_id', $contributionRecur) | |
64 | ); | |
46097c9c MW |
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]); | |
fadaea59 | 69 | } |
46097c9c | 70 | } |
fadaea59 | 71 | |
46097c9c MW |
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']; | |
6a488035 | 80 | } |
46097c9c | 81 | |
24eba103 MW |
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 | ||
46097c9c | 85 | $this->assign('recur', $contributionRecur); |
6a488035 TO |
86 | } |
87 | ||
00be9182 | 88 | public function preProcess() { |
353ffa53 TO |
89 | $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'view'); |
90 | $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); | |
6a488035 TO |
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 | ||
6a488035 TO |
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 | /** | |
dc195289 | 107 | * the main function that is called when the page loads, |
6a488035 TO |
108 | * it decides the which action has to be taken for the page. |
109 | * | |
76e7a76c | 110 | * @return null |
6a488035 | 111 | */ |
00be9182 | 112 | public function run() { |
6a488035 TO |
113 | $this->preProcess(); |
114 | ||
115 | if ($this->_action & CRM_Core_Action::VIEW) { | |
116 | $this->view(); | |
117 | } | |
118 | ||
119 | return parent::run(); | |
120 | } | |
96025800 | 121 | |
6a488035 | 122 | } |