Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
18 | /** | |
19 | * Main page for viewing Recurring Contributions. | |
6a488035 TO |
20 | */ |
21 | class CRM_Contribute_Page_ContributionRecur extends CRM_Core_Page { | |
22 | ||
1330f57a | 23 | public static $_links = NULL; |
6a488035 TO |
24 | public $_permission = NULL; |
25 | public $_contactId = NULL; | |
85b68a11 CR |
26 | public $_id = NULL; |
27 | public $_action = NULL; | |
6a488035 TO |
28 | |
29 | /** | |
fe482240 | 30 | * View details of a recurring contribution. |
95ea96be | 31 | */ |
d5cc0fc2 | 32 | public function view() { |
46097c9c MW |
33 | if (empty($this->_id)) { |
34 | CRM_Core_Error::statusBounce('Recurring contribution not found'); | |
35 | } | |
6a488035 | 36 | |
46097c9c | 37 | try { |
be2fb01f | 38 | $contributionRecur = civicrm_api3('ContributionRecur', 'getsingle', [ |
46097c9c | 39 | 'id' => $this->_id, |
be2fb01f | 40 | ]); |
46097c9c MW |
41 | } |
42 | catch (Exception $e) { | |
43 | CRM_Core_Error::statusBounce('Recurring contribution not found (ID: ' . $this->_id); | |
44 | } | |
45 | ||
85b68a11 CR |
46 | $contributionRecur['payment_processor'] = CRM_Financial_BAO_PaymentProcessor::getPaymentProcessorName( |
47 | CRM_Utils_Array::value('payment_processor_id', $contributionRecur) | |
48 | ); | |
be2fb01f | 49 | $idFields = ['contribution_status_id', 'campaign_id', 'financial_type_id']; |
46097c9c MW |
50 | foreach ($idFields as $idField) { |
51 | if (!empty($contributionRecur[$idField])) { | |
52 | $contributionRecur[substr($idField, 0, -3)] = CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_ContributionRecur', $idField, $contributionRecur[$idField]); | |
fadaea59 | 53 | } |
46097c9c | 54 | } |
fadaea59 | 55 | |
46097c9c | 56 | // Add linked membership |
be2fb01f | 57 | $membership = civicrm_api3('Membership', 'get', [ |
46097c9c | 58 | 'contribution_recur_id' => $contributionRecur['id'], |
be2fb01f | 59 | ]); |
46097c9c MW |
60 | if (!empty($membership['count'])) { |
61 | $membershipDetails = reset($membership['values']); | |
62 | $contributionRecur['membership_id'] = $membershipDetails['id']; | |
63 | $contributionRecur['membership_name'] = $membershipDetails['membership_name']; | |
6a488035 | 64 | } |
46097c9c | 65 | |
24eba103 MW |
66 | $groupTree = CRM_Core_BAO_CustomGroup::getTree('ContributionRecur', NULL, $contributionRecur['id']); |
67 | CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $contributionRecur['id']); | |
68 | ||
46097c9c | 69 | $this->assign('recur', $contributionRecur); |
0e52367e MWMC |
70 | |
71 | $displayName = CRM_Contact_BAO_Contact::displayName($contributionRecur['contact_id']); | |
72 | $this->assign('displayName', $displayName); | |
73 | ||
74 | // Check if this is default domain contact CRM-10482 | |
75 | if (CRM_Contact_BAO_Contact::checkDomainContact($contributionRecur['contact_id'])) { | |
76 | $displayName .= ' (' . ts('default organization') . ')'; | |
77 | } | |
78 | ||
79 | // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container | |
80 | CRM_Utils_System::setTitle(ts('View Recurring Contribution from') . ' ' . $displayName); | |
6a488035 TO |
81 | } |
82 | ||
00be9182 | 83 | public function preProcess() { |
353ffa53 TO |
84 | $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'view'); |
85 | $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); | |
6a488035 TO |
86 | $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); |
87 | $this->assign('contactId', $this->_contactId); | |
88 | ||
89 | // check logged in url permission | |
90 | CRM_Contact_Page_View::checkUserPermission($this); | |
91 | ||
6a488035 TO |
92 | $this->assign('action', $this->_action); |
93 | ||
94 | if ($this->_permission == CRM_Core_Permission::EDIT && !CRM_Core_Permission::check('edit contributions')) { | |
95 | // demote to view since user does not have edit contrib rights | |
96 | $this->_permission = CRM_Core_Permission::VIEW; | |
97 | $this->assign('permission', 'view'); | |
98 | } | |
99 | } | |
100 | ||
101 | /** | |
dc195289 | 102 | * the main function that is called when the page loads, |
6a488035 TO |
103 | * it decides the which action has to be taken for the page. |
104 | * | |
76e7a76c | 105 | * @return null |
6a488035 | 106 | */ |
00be9182 | 107 | public function run() { |
6a488035 TO |
108 | $this->preProcess(); |
109 | ||
110 | if ($this->_action & CRM_Core_Action::VIEW) { | |
111 | $this->view(); | |
112 | } | |
113 | ||
114 | return parent::run(); | |
115 | } | |
96025800 | 116 | |
6a488035 | 117 | } |