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