Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
fa938177 | 6 | | Copyright CiviCRM LLC (c) 2004-2016 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
fa938177 | 31 | * @copyright CiviCRM LLC (c) 2004-2016 |
6a488035 TO |
32 | */ |
33 | ||
34 | /** | |
35 | * This class generates form components for Pledge | |
6a488035 TO |
36 | */ |
37 | class CRM_Pledge_Form_PledgeView extends CRM_Core_Form { | |
38 | ||
39 | /** | |
fe482240 | 40 | * Set variables up before form is built. |
6a488035 TO |
41 | */ |
42 | public function preProcess() { | |
43 | ||
44 | $values = $ids = array(); | |
45 | $params = array('id' => $this->get('id')); | |
46 | CRM_Pledge_BAO_Pledge::getValues($params, | |
47 | $values, | |
48 | $ids | |
49 | ); | |
50 | ||
51 | $values['frequencyUnit'] = ts('%1(s)', array(1 => $values['frequency_unit'])); | |
52 | ||
53 | if (isset($values["honor_contact_id"]) && $values["honor_contact_id"]) { | |
54 | $sql = "SELECT display_name FROM civicrm_contact WHERE id = " . $values["honor_contact_id"]; | |
55 | $dao = new CRM_Core_DAO(); | |
56 | $dao->query($sql); | |
57 | if ($dao->fetch()) { | |
58 | $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid=$values[honor_contact_id]"); | |
59 | $values["honor_display"] = "<A href = $url>" . $dao->display_name . "</A>"; | |
60 | } | |
cbf48754 | 61 | $honor = CRM_Core_PseudoConstant::get('CRM_Pledge_DAO_Pledge', 'honor_type_id'); |
6a488035 TO |
62 | $values['honor_type'] = $honor[$values['honor_type_id']]; |
63 | } | |
64 | ||
cc28438b | 65 | // handle custom data. |
6a488035 | 66 | $groupTree = CRM_Core_BAO_CustomGroup::getTree('Pledge', $this, $params['id']); |
e34e6979 | 67 | CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $params['id']); |
6a488035 | 68 | |
a7488080 | 69 | if (!empty($values['contribution_page_id'])) { |
6a488035 TO |
70 | $values['contribution_page'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $values['contribution_page_id'], 'title'); |
71 | } | |
72 | ||
481a74f4 | 73 | $values['financial_type'] = CRM_Utils_Array::value($values['financial_type_id'], CRM_Contribute_PseudoConstant::financialType()); |
6a488035 TO |
74 | |
75 | if ($values['status_id']) { | |
ab6ba136 | 76 | $values['pledge_status'] = CRM_Core_PseudoConstant::getKey('CRM_Pledge_BAO_Pledge', 'status_id', $values['status_id']); |
6a488035 TO |
77 | } |
78 | ||
79 | $url = CRM_Utils_System::url('civicrm/contact/view/pledge', | |
80 | "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home" | |
81 | ); | |
82 | ||
83 | $recentOther = array(); | |
84 | if (CRM_Core_Permission::checkActionPermission('CiviPledge', CRM_Core_Action::UPDATE)) { | |
85 | $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/pledge', | |
86 | "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home" | |
87 | ); | |
88 | } | |
89 | if (CRM_Core_Permission::checkActionPermission('CiviPledge', CRM_Core_Action::DELETE)) { | |
90 | $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/pledge', | |
91 | "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home" | |
92 | ); | |
93 | } | |
94 | ||
95 | $displayName = CRM_Contact_BAO_Contact::displayName($values['contact_id']); | |
96 | $this->assign('displayName', $displayName); | |
97 | ||
366fe2a3 | 98 | $title = $displayName . |
481a74f4 | 99 | ' - (' . ts('Pledged') . ' ' . CRM_Utils_Money::format($values['pledge_amount']) . |
6a488035 TO |
100 | ' - ' . $values['financial_type'] . ')'; |
101 | ||
102 | // add Pledge to Recent Items | |
103 | CRM_Utils_Recent::add($title, | |
104 | $url, | |
105 | $values['id'], | |
106 | 'Pledge', | |
107 | $values['contact_id'], | |
108 | NULL, | |
109 | $recentOther | |
110 | ); | |
111 | ||
112 | // Check if this is default domain contact CRM-10482 | |
113 | if (CRM_Contact_BAO_Contact::checkDomainContact($values['contact_id'])) { | |
114 | $displayName .= ' (' . ts('default organization') . ')'; | |
115 | } | |
116 | // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container | |
86bfa4f6 | 117 | CRM_Utils_System::setTitle(ts('View Pledge by') . ' ' . $displayName); |
6a488035 | 118 | |
cc28438b | 119 | // do check for campaigns |
6a488035 TO |
120 | if ($campaignId = CRM_Utils_Array::value('campaign_id', $values)) { |
121 | $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId); | |
122 | $values['campaign'] = $campaigns[$campaignId]; | |
123 | } | |
124 | ||
125 | $this->assign($values); | |
126 | } | |
127 | ||
128 | /** | |
fe482240 | 129 | * Build the form object. |
6a488035 TO |
130 | */ |
131 | public function buildQuickForm() { | |
132 | $this->addButtons(array( | |
133 | array( | |
134 | 'type' => 'next', | |
135 | 'name' => ts('Done'), | |
136 | 'spacing' => ' ', | |
137 | 'isDefault' => TRUE, | |
138 | ), | |
139 | ) | |
140 | ); | |
141 | } | |
96025800 | 142 | |
6a488035 | 143 | } |