Merge pull request #21876 from mariav0/patch-14
[civicrm-core.git] / CRM / Pledge / Form / PledgeView.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 * This class generates form components for Pledge
20 */
21 class CRM_Pledge_Form_PledgeView extends CRM_Core_Form {
22
23 /**
24 * Set variables up before form is built.
25 */
26 public function preProcess() {
27
28 $values = $ids = [];
29 $params = ['id' => $this->get('id')];
30 CRM_Pledge_BAO_Pledge::getValues($params,
31 $values,
32 $ids
33 );
34
35 $values['frequencyUnit'] = ts('%1(s)', [1 => $values['frequency_unit']]);
36
37 if (isset($values["honor_contact_id"]) && $values["honor_contact_id"]) {
38 $sql = "SELECT display_name FROM civicrm_contact WHERE id = " . $values["honor_contact_id"];
39 $dao = new CRM_Core_DAO();
40 $dao->query($sql);
41 if ($dao->fetch()) {
42 $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid=$values[honor_contact_id]");
43 $values["honor_display"] = "<A href = $url>" . $dao->display_name . "</A>";
44 }
45 $honor = CRM_Core_PseudoConstant::get('CRM_Pledge_DAO_Pledge', 'honor_type_id');
46 $values['honor_type'] = $honor[$values['honor_type_id']];
47 }
48
49 // handle custom data.
50 $groupTree = CRM_Core_BAO_CustomGroup::getTree('Pledge', NULL, $params['id'], NULL, [], NULL,
51 TRUE, NULL, FALSE, CRM_Core_Permission::VIEW);
52 CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $params['id']);
53
54 if (!empty($values['contribution_page_id'])) {
55 $values['contribution_page'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $values['contribution_page_id'], 'title');
56 }
57
58 $values['financial_type'] = CRM_Utils_Array::value($values['financial_type_id'], CRM_Contribute_PseudoConstant::financialType());
59
60 if ($values['status_id']) {
61 $values['pledge_status'] = CRM_Core_PseudoConstant::getKey('CRM_Pledge_BAO_Pledge', 'status_id', $values['status_id']);
62 }
63
64 $url = CRM_Utils_System::url('civicrm/contact/view/pledge',
65 "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"
66 );
67
68 $recentOther = [];
69 if (CRM_Core_Permission::checkActionPermission('CiviPledge', CRM_Core_Action::UPDATE)) {
70 $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/pledge',
71 "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"
72 );
73 }
74 if (CRM_Core_Permission::checkActionPermission('CiviPledge', CRM_Core_Action::DELETE)) {
75 $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/pledge',
76 "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"
77 );
78 }
79
80 $displayName = CRM_Contact_BAO_Contact::displayName($values['contact_id']);
81 $this->assign('displayName', $displayName);
82
83 $title = $displayName .
84 ' - (' . ts('Pledged') . ' ' . CRM_Utils_Money::format($values['pledge_amount']) .
85 ' - ' . $values['financial_type'] . ')';
86
87 // add Pledge to Recent Items
88 CRM_Utils_Recent::add($title,
89 $url,
90 $values['id'],
91 'Pledge',
92 $values['contact_id'],
93 NULL,
94 $recentOther
95 );
96
97 // Check if this is default domain contact CRM-10482
98 if (CRM_Contact_BAO_Contact::checkDomainContact($values['contact_id'])) {
99 $displayName .= ' (' . ts('default organization') . ')';
100 }
101 // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container
102 $this->setTitle(ts('View Pledge by') . ' ' . $displayName);
103
104 // do check for campaigns
105 if ($campaignId = CRM_Utils_Array::value('campaign_id', $values)) {
106 $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId);
107 $values['campaign'] = $campaigns[$campaignId];
108 }
109
110 $this->assign($values);
111 }
112
113 /**
114 * Build the form object.
115 */
116 public function buildQuickForm() {
117 $this->addButtons([
118 [
119 'type' => 'next',
120 'name' => ts('Done'),
121 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
122 'isDefault' => TRUE,
123 ],
124 ]);
125 }
126
127 }