Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * This class generates form components for Pledge | |
38 | * | |
39 | */ | |
40 | class CRM_Pledge_Form_PledgeView extends CRM_Core_Form { | |
41 | ||
42 | /** | |
100fef9d | 43 | * Set variables up before form is built |
6a488035 TO |
44 | * |
45 | * @return void | |
6a488035 TO |
46 | */ |
47 | public function preProcess() { | |
48 | ||
49 | $values = $ids = array(); | |
50 | $params = array('id' => $this->get('id')); | |
51 | CRM_Pledge_BAO_Pledge::getValues($params, | |
52 | $values, | |
53 | $ids | |
54 | ); | |
55 | ||
56 | $values['frequencyUnit'] = ts('%1(s)', array(1 => $values['frequency_unit'])); | |
57 | ||
58 | if (isset($values["honor_contact_id"]) && $values["honor_contact_id"]) { | |
59 | $sql = "SELECT display_name FROM civicrm_contact WHERE id = " . $values["honor_contact_id"]; | |
60 | $dao = new CRM_Core_DAO(); | |
61 | $dao->query($sql); | |
62 | if ($dao->fetch()) { | |
63 | $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid=$values[honor_contact_id]"); | |
64 | $values["honor_display"] = "<A href = $url>" . $dao->display_name . "</A>"; | |
65 | } | |
cbf48754 | 66 | $honor = CRM_Core_PseudoConstant::get('CRM_Pledge_DAO_Pledge', 'honor_type_id'); |
6a488035 TO |
67 | $values['honor_type'] = $honor[$values['honor_type_id']]; |
68 | } | |
69 | ||
70 | //handle custom data. | |
71 | $groupTree = CRM_Core_BAO_CustomGroup::getTree('Pledge', $this, $params['id']); | |
72 | CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree); | |
73 | ||
a7488080 | 74 | if (!empty($values['contribution_page_id'])) { |
6a488035 TO |
75 | $values['contribution_page'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $values['contribution_page_id'], 'title'); |
76 | } | |
77 | ||
481a74f4 | 78 | $values['financial_type'] = CRM_Utils_Array::value($values['financial_type_id'], CRM_Contribute_PseudoConstant::financialType()); |
6a488035 TO |
79 | |
80 | if ($values['status_id']) { | |
81 | $values['pledge_status'] = CRM_Utils_Array::value($values['status_id'], CRM_Contribute_PseudoConstant::contributionStatus()); | |
82 | } | |
83 | ||
84 | $url = CRM_Utils_System::url('civicrm/contact/view/pledge', | |
85 | "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home" | |
86 | ); | |
87 | ||
88 | $recentOther = array(); | |
89 | if (CRM_Core_Permission::checkActionPermission('CiviPledge', CRM_Core_Action::UPDATE)) { | |
90 | $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/pledge', | |
91 | "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home" | |
92 | ); | |
93 | } | |
94 | if (CRM_Core_Permission::checkActionPermission('CiviPledge', CRM_Core_Action::DELETE)) { | |
95 | $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/pledge', | |
96 | "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home" | |
97 | ); | |
98 | } | |
99 | ||
100 | $displayName = CRM_Contact_BAO_Contact::displayName($values['contact_id']); | |
101 | $this->assign('displayName', $displayName); | |
102 | ||
366fe2a3 | 103 | $title = $displayName . |
481a74f4 | 104 | ' - (' . ts('Pledged') . ' ' . CRM_Utils_Money::format($values['pledge_amount']) . |
6a488035 TO |
105 | ' - ' . $values['financial_type'] . ')'; |
106 | ||
107 | // add Pledge to Recent Items | |
108 | CRM_Utils_Recent::add($title, | |
109 | $url, | |
110 | $values['id'], | |
111 | 'Pledge', | |
112 | $values['contact_id'], | |
113 | NULL, | |
114 | $recentOther | |
115 | ); | |
116 | ||
117 | // Check if this is default domain contact CRM-10482 | |
118 | if (CRM_Contact_BAO_Contact::checkDomainContact($values['contact_id'])) { | |
119 | $displayName .= ' (' . ts('default organization') . ')'; | |
120 | } | |
121 | // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container | |
86bfa4f6 | 122 | CRM_Utils_System::setTitle(ts('View Pledge by') . ' ' . $displayName); |
6a488035 TO |
123 | |
124 | //do check for campaigns | |
125 | if ($campaignId = CRM_Utils_Array::value('campaign_id', $values)) { | |
126 | $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId); | |
127 | $values['campaign'] = $campaigns[$campaignId]; | |
128 | } | |
129 | ||
130 | $this->assign($values); | |
131 | } | |
132 | ||
133 | /** | |
c490a46a | 134 | * Build the form object |
6a488035 | 135 | * |
355ba699 | 136 | * @return void |
6a488035 TO |
137 | */ |
138 | public function buildQuickForm() { | |
139 | $this->addButtons(array( | |
140 | array( | |
141 | 'type' => 'next', | |
142 | 'name' => ts('Done'), | |
143 | 'spacing' => ' ', | |
144 | 'isDefault' => TRUE, | |
145 | ), | |
146 | ) | |
147 | ); | |
148 | } | |
149 | } |