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