Merge pull request #17175 from eileenmcnaughton/batch
[civicrm-core.git] / CRM / Contribute / Page / ContributionRecur.php
CommitLineData
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 */
21class CRM_Contribute_Page_ContributionRecur extends CRM_Core_Page {
22
479857b3
MW
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 }
6a488035
TO
35
36 /**
fe482240 37 * View details of a recurring contribution.
95ea96be 38 */
d5cc0fc2 39 public function view() {
479857b3 40 if (empty($this->getEntityId())) {
46097c9c
MW
41 CRM_Core_Error::statusBounce('Recurring contribution not found');
42 }
6a488035 43
46097c9c 44 try {
be2fb01f 45 $contributionRecur = civicrm_api3('ContributionRecur', 'getsingle', [
479857b3 46 'id' => $this->getEntityId(),
be2fb01f 47 ]);
46097c9c
MW
48 }
49 catch (Exception $e) {
479857b3 50 CRM_Core_Error::statusBounce('Recurring contribution not found (ID: ' . $this->getEntityId());
46097c9c
MW
51 }
52
85b68a11
CR
53 $contributionRecur['payment_processor'] = CRM_Financial_BAO_PaymentProcessor::getPaymentProcessorName(
54 CRM_Utils_Array::value('payment_processor_id', $contributionRecur)
55 );
be2fb01f 56 $idFields = ['contribution_status_id', 'campaign_id', 'financial_type_id'];
46097c9c
MW
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]);
fadaea59 60 }
46097c9c 61 }
fadaea59 62
46097c9c 63 // Add linked membership
be2fb01f 64 $membership = civicrm_api3('Membership', 'get', [
46097c9c 65 'contribution_recur_id' => $contributionRecur['id'],
be2fb01f 66 ]);
46097c9c
MW
67 if (!empty($membership['count'])) {
68 $membershipDetails = reset($membership['values']);
69 $contributionRecur['membership_id'] = $membershipDetails['id'];
70 $contributionRecur['membership_name'] = $membershipDetails['membership_name'];
6a488035 71 }
46097c9c 72
24eba103
MW
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
46097c9c 76 $this->assign('recur', $contributionRecur);
0e52367e
MWMC
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);
6a488035
TO
88 }
89
00be9182 90 public function preProcess() {
479857b3 91 $this->preProcessQuickEntityPage();
6a488035
TO
92 }
93
94 /**
dc195289 95 * the main function that is called when the page loads,
6a488035
TO
96 * it decides the which action has to be taken for the page.
97 *
76e7a76c 98 * @return null
6a488035 99 */
00be9182 100 public function run() {
6a488035
TO
101 $this->preProcess();
102
479857b3 103 if ($this->isViewContext()) {
6a488035
TO
104 $this->view();
105 }
106
107 return parent::run();
108 }
96025800 109
6a488035 110}