| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | Copyright CiviCRM LLC. All rights reserved. | |
| 5 | | | |
| 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 | |
| 9 | +--------------------------------------------------------------------+ |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * |
| 14 | * @package CRM |
| 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
| 16 | */ |
| 17 | |
| 18 | /** |
| 19 | * Main page for viewing Recurring Contributions. |
| 20 | */ |
| 21 | class CRM_Contribute_Page_ContributionRecur extends CRM_Core_Page { |
| 22 | |
| 23 | public static $_links = NULL; |
| 24 | public $_permission = NULL; |
| 25 | public $_contactId = NULL; |
| 26 | public $_id = NULL; |
| 27 | public $_action = NULL; |
| 28 | |
| 29 | /** |
| 30 | * View details of a recurring contribution. |
| 31 | */ |
| 32 | public function view() { |
| 33 | if (empty($this->_id)) { |
| 34 | CRM_Core_Error::statusBounce('Recurring contribution not found'); |
| 35 | } |
| 36 | |
| 37 | try { |
| 38 | $contributionRecur = civicrm_api3('ContributionRecur', 'getsingle', [ |
| 39 | 'id' => $this->_id, |
| 40 | ]); |
| 41 | } |
| 42 | catch (Exception $e) { |
| 43 | CRM_Core_Error::statusBounce('Recurring contribution not found (ID: ' . $this->_id); |
| 44 | } |
| 45 | |
| 46 | $contributionRecur['payment_processor'] = CRM_Financial_BAO_PaymentProcessor::getPaymentProcessorName( |
| 47 | CRM_Utils_Array::value('payment_processor_id', $contributionRecur) |
| 48 | ); |
| 49 | $idFields = ['contribution_status_id', 'campaign_id', 'financial_type_id']; |
| 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]); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | // Add linked membership |
| 57 | $membership = civicrm_api3('Membership', 'get', [ |
| 58 | 'contribution_recur_id' => $contributionRecur['id'], |
| 59 | ]); |
| 60 | if (!empty($membership['count'])) { |
| 61 | $membershipDetails = reset($membership['values']); |
| 62 | $contributionRecur['membership_id'] = $membershipDetails['id']; |
| 63 | $contributionRecur['membership_name'] = $membershipDetails['membership_name']; |
| 64 | } |
| 65 | |
| 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 | |
| 69 | $this->assign('recur', $contributionRecur); |
| 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); |
| 81 | } |
| 82 | |
| 83 | public function preProcess() { |
| 84 | $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'view'); |
| 85 | $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); |
| 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 | |
| 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 | /** |
| 102 | * the main function that is called when the page loads, |
| 103 | * it decides the which action has to be taken for the page. |
| 104 | * |
| 105 | * @return null |
| 106 | */ |
| 107 | public function run() { |
| 108 | $this->preProcess(); |
| 109 | |
| 110 | if ($this->_action & CRM_Core_Action::VIEW) { |
| 111 | $this->view(); |
| 112 | } |
| 113 | |
| 114 | return parent::run(); |
| 115 | } |
| 116 | |
| 117 | } |