Merge pull request #22487 from mattwire/repeattransactiontemplatecontribution
[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())) {
507bc932 41 CRM_Core_Error::statusBounce(ts('Recurring contribution not found'));
46097c9c 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) {
cd3286d3 50 CRM_Core_Error::statusBounce(ts('Recurring contribution not found (ID: %1)', [1 => $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
317103ab
CW
73 $groupTree = CRM_Core_BAO_CustomGroup::getTree('ContributionRecur', NULL, $contributionRecur['id'], NULL, [],
74 NULL, TRUE, NULL, FALSE, CRM_Core_Permission::VIEW);
24eba103
MW
75 CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $contributionRecur['id']);
76
af1bffc2
MW
77 if (isset($contributionRecur['trxn_id']) && ($contributionRecur['processor_id'] === $contributionRecur['trxn_id'])) {
78 unset($contributionRecur['trxn_id']);
79 }
46097c9c 80 $this->assign('recur', $contributionRecur);
0e52367e 81
2d8add95
JJ
82 $templateContribution = CRM_Contribute_BAO_ContributionRecur::getTemplateContribution($this->getEntityId());
83
84 $lineItems = [];
85 $displayLineItems = FALSE;
86 if (!empty($templateContribution['id'])) {
87 $lineItems = [CRM_Price_BAO_LineItem::getLineItemsByContributionID(($templateContribution['id']))];
88 $displayLineItems = TRUE;
89 }
90 $this->assign('lineItem', $lineItems);
91 $this->assign('displayLineItems', $displayLineItems);
92
0e52367e
MWMC
93 $displayName = CRM_Contact_BAO_Contact::displayName($contributionRecur['contact_id']);
94 $this->assign('displayName', $displayName);
95
96 // Check if this is default domain contact CRM-10482
97 if (CRM_Contact_BAO_Contact::checkDomainContact($contributionRecur['contact_id'])) {
98 $displayName .= ' (' . ts('default organization') . ')';
99 }
100
101 // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container
102 CRM_Utils_System::setTitle(ts('View Recurring Contribution from') . ' ' . $displayName);
6a488035
TO
103 }
104
00be9182 105 public function preProcess() {
479857b3 106 $this->preProcessQuickEntityPage();
6a488035
TO
107 }
108
109 /**
dc195289 110 * the main function that is called when the page loads,
6a488035
TO
111 * it decides the which action has to be taken for the page.
112 *
76e7a76c 113 * @return null
6a488035 114 */
00be9182 115 public function run() {
6a488035 116 $this->preProcess();
5d82f2a7 117 $this->assign('hasAccessCiviContributePermission', CRM_Core_Permission::check('access CiviContribute'));
479857b3 118 if ($this->isViewContext()) {
6a488035
TO
119 $this->view();
120 }
121
122 return parent::run();
123 }
96025800 124
6a488035 125}