Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
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; | |
42 | ||
43 | /** | |
fe482240 | 44 | * View details of a recurring contribution. |
95ea96be | 45 | */ |
d5cc0fc2 | 46 | public function view() { |
46097c9c MW |
47 | if (empty($this->_id)) { |
48 | CRM_Core_Error::statusBounce('Recurring contribution not found'); | |
49 | } | |
6a488035 | 50 | |
46097c9c MW |
51 | try { |
52 | $contributionRecur = civicrm_api3('ContributionRecur', 'getsingle', array( | |
53 | 'id' => $this->_id, | |
fadaea59 | 54 | )); |
46097c9c MW |
55 | } |
56 | catch (Exception $e) { | |
57 | CRM_Core_Error::statusBounce('Recurring contribution not found (ID: ' . $this->_id); | |
58 | } | |
59 | ||
60 | $contributionRecur['payment_processor'] = CRM_Financial_BAO_PaymentProcessor::getPaymentProcessorName($contributionRecur['payment_processor_id']); | |
61 | $idFields = array('contribution_status_id', 'campaign_id', 'financial_type_id'); | |
62 | foreach ($idFields as $idField) { | |
63 | if (!empty($contributionRecur[$idField])) { | |
64 | $contributionRecur[substr($idField, 0, -3)] = CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_ContributionRecur', $idField, $contributionRecur[$idField]); | |
fadaea59 | 65 | } |
46097c9c | 66 | } |
fadaea59 | 67 | |
46097c9c MW |
68 | // Add linked membership |
69 | $membership = civicrm_api3('Membership', 'get', array( | |
70 | 'contribution_recur_id' => $contributionRecur['id'], | |
71 | )); | |
72 | if (!empty($membership['count'])) { | |
73 | $membershipDetails = reset($membership['values']); | |
74 | $contributionRecur['membership_id'] = $membershipDetails['id']; | |
75 | $contributionRecur['membership_name'] = $membershipDetails['membership_name']; | |
6a488035 | 76 | } |
46097c9c | 77 | |
24eba103 MW |
78 | $groupTree = CRM_Core_BAO_CustomGroup::getTree('ContributionRecur', NULL, $contributionRecur['id']); |
79 | CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $contributionRecur['id']); | |
80 | ||
46097c9c | 81 | $this->assign('recur', $contributionRecur); |
6a488035 TO |
82 | } |
83 | ||
00be9182 | 84 | public function preProcess() { |
353ffa53 TO |
85 | $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'view'); |
86 | $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); | |
6a488035 TO |
87 | $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); |
88 | $this->assign('contactId', $this->_contactId); | |
89 | ||
90 | // check logged in url permission | |
91 | CRM_Contact_Page_View::checkUserPermission($this); | |
92 | ||
6a488035 TO |
93 | $this->assign('action', $this->_action); |
94 | ||
95 | if ($this->_permission == CRM_Core_Permission::EDIT && !CRM_Core_Permission::check('edit contributions')) { | |
96 | // demote to view since user does not have edit contrib rights | |
97 | $this->_permission = CRM_Core_Permission::VIEW; | |
98 | $this->assign('permission', 'view'); | |
99 | } | |
100 | } | |
101 | ||
102 | /** | |
dc195289 | 103 | * the main function that is called when the page loads, |
6a488035 TO |
104 | * it decides the which action has to be taken for the page. |
105 | * | |
76e7a76c | 106 | * @return null |
6a488035 | 107 | */ |
00be9182 | 108 | public function run() { |
6a488035 TO |
109 | $this->preProcess(); |
110 | ||
111 | if ($this->_action & CRM_Core_Action::VIEW) { | |
112 | $this->view(); | |
113 | } | |
114 | ||
115 | return parent::run(); | |
116 | } | |
96025800 | 117 | |
6a488035 | 118 | } |