Merge pull request #17476 from civicrm/5.26
[civicrm-core.git] / CRM / Contribute / Page / ContributionRecur.php
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 use CRM_Core_Page_EntityPageTrait;
24
25 /**
26 * @return string
27 */
28 public function getDefaultEntity() {
29 return 'ContributionRecur';
30 }
31
32 protected function getDefaultAction() {
33 return 'view';
34 }
35
36 /**
37 * View details of a recurring contribution.
38 */
39 public function view() {
40 if (empty($this->getEntityId())) {
41 CRM_Core_Error::statusBounce('Recurring contribution not found');
42 }
43
44 try {
45 $contributionRecur = civicrm_api3('ContributionRecur', 'getsingle', [
46 'id' => $this->getEntityId(),
47 ]);
48 }
49 catch (Exception $e) {
50 CRM_Core_Error::statusBounce('Recurring contribution not found (ID: ' . $this->getEntityId());
51 }
52
53 $contributionRecur['payment_processor'] = CRM_Financial_BAO_PaymentProcessor::getPaymentProcessorName(
54 CRM_Utils_Array::value('payment_processor_id', $contributionRecur)
55 );
56 $idFields = ['contribution_status_id', 'campaign_id', 'financial_type_id'];
57 foreach ($idFields as $idField) {
58 if (!empty($contributionRecur[$idField])) {
59 $contributionRecur[substr($idField, 0, -3)] = CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_ContributionRecur', $idField, $contributionRecur[$idField]);
60 }
61 }
62
63 // Add linked membership
64 $membership = civicrm_api3('Membership', 'get', [
65 'contribution_recur_id' => $contributionRecur['id'],
66 ]);
67 if (!empty($membership['count'])) {
68 $membershipDetails = reset($membership['values']);
69 $contributionRecur['membership_id'] = $membershipDetails['id'];
70 $contributionRecur['membership_name'] = $membershipDetails['membership_name'];
71 }
72
73 $groupTree = CRM_Core_BAO_CustomGroup::getTree('ContributionRecur', NULL, $contributionRecur['id']);
74 CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $contributionRecur['id']);
75
76 $this->assign('recur', $contributionRecur);
77
78 $displayName = CRM_Contact_BAO_Contact::displayName($contributionRecur['contact_id']);
79 $this->assign('displayName', $displayName);
80
81 // Check if this is default domain contact CRM-10482
82 if (CRM_Contact_BAO_Contact::checkDomainContact($contributionRecur['contact_id'])) {
83 $displayName .= ' (' . ts('default organization') . ')';
84 }
85
86 // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container
87 CRM_Utils_System::setTitle(ts('View Recurring Contribution from') . ' ' . $displayName);
88 }
89
90 public function preProcess() {
91 $this->preProcessQuickEntityPage();
92 }
93
94 /**
95 * the main function that is called when the page loads,
96 * it decides the which action has to be taken for the page.
97 *
98 * @return null
99 */
100 public function run() {
101 $this->preProcess();
102
103 if ($this->isViewContext()) {
104 $this->view();
105 }
106
107 return parent::run();
108 }
109
110 }