Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
f299f7db | 6 | | Copyright CiviCRM LLC (c) 2004-2020 | |
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 | |
f299f7db | 31 | * @copyright CiviCRM LLC (c) 2004-2020 |
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 | ||
1330f57a | 39 | public static $_links = NULL; |
6a488035 TO |
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 | 53 | try { |
be2fb01f | 54 | $contributionRecur = civicrm_api3('ContributionRecur', 'getsingle', [ |
46097c9c | 55 | 'id' => $this->_id, |
be2fb01f | 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 | ); | |
be2fb01f | 65 | $idFields = ['contribution_status_id', 'campaign_id', 'financial_type_id']; |
46097c9c MW |
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 | 72 | // Add linked membership |
be2fb01f | 73 | $membership = civicrm_api3('Membership', 'get', [ |
46097c9c | 74 | 'contribution_recur_id' => $contributionRecur['id'], |
be2fb01f | 75 | ]); |
46097c9c MW |
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); |
0e52367e MWMC |
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); | |
6a488035 TO |
97 | } |
98 | ||
00be9182 | 99 | public function preProcess() { |
353ffa53 TO |
100 | $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'view'); |
101 | $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); | |
6a488035 TO |
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 | ||
6a488035 TO |
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 | /** | |
dc195289 | 118 | * the main function that is called when the page loads, |
6a488035 TO |
119 | * it decides the which action has to be taken for the page. |
120 | * | |
76e7a76c | 121 | * @return null |
6a488035 | 122 | */ |
00be9182 | 123 | public function run() { |
6a488035 TO |
124 | $this->preProcess(); |
125 | ||
126 | if ($this->_action & CRM_Core_Action::VIEW) { | |
127 | $this->view(); | |
128 | } | |
129 | ||
130 | return parent::run(); | |
131 | } | |
96025800 | 132 | |
6a488035 | 133 | } |