Merge pull request #925 from GiantRobot/CRM-12737
[civicrm-core.git] / CRM / Grant / Form / GrantView.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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
31 * @copyright CiviCRM LLC (c) 2004-2013
32 * $Id$
33 *
34 */
35
36 /**
37 * This class generates form components for processing a Grant
38 *
39 */
40 class CRM_Grant_Form_GrantView 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 $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
50 $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
51 $context = CRM_Utils_Request::retrieve('context', 'String', $this);
52 $this->assign('context', $context);
53
54 $values = array();
55 $params['id'] = $this->_id;
56 CRM_Grant_BAO_Grant::retrieve($params, $values);
57 $grantType = CRM_Core_PseudoConstant::get('CRM_Grant_DAO_Grant', 'grant_type_id');
58 $grantStatus = CRM_Core_PseudoConstant::get('CRM_Grant_DAO_Grant', 'status_id');
59 $this->assign('grantType', $grantType[$values['grant_type_id']]);
60 $this->assign('grantStatus', $grantStatus[$values['status_id']]);
61 $grantTokens = array(
62 'amount_total', 'amount_requested', 'amount_granted',
63 'rationale', 'grant_report_received', 'application_received_date',
64 'decision_date', 'money_transfer_date', 'grant_due_date',
65 );
66
67 foreach ($grantTokens as $token) {
68 $this->assign($token, CRM_Utils_Array::value($token, $values));
69 }
70
71 if (isset($this->_id)) {
72 $noteDAO = new CRM_Core_BAO_Note();
73 $noteDAO->entity_table = 'civicrm_grant';
74 $noteDAO->entity_id = $this->_id;
75 if ($noteDAO->find(TRUE)) {
76 $this->_noteId = $noteDAO->id;
77 }
78 }
79
80 if (isset($this->_noteId)) {
81 $this->assign('note', CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Note', $this->_noteId, 'note'));
82 }
83
84
85 // add Grant to Recent Items
86 $url = CRM_Utils_System::url('civicrm/contact/view/grant',
87 "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"
88 );
89
90 $title = CRM_Contact_BAO_Contact::displayName($values['contact_id']) . ' - ' . ts('Grant') . ': ' . CRM_Utils_Money::format($values['amount_total']) . ' (' . $grantType[$values['grant_type_id']] . ')';
91
92 $recentOther = array();
93 if (CRM_Core_Permission::checkActionPermission('CiviGrant', CRM_Core_Action::UPDATE)) {
94 $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/grant',
95 "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"
96 );
97 }
98 if (CRM_Core_Permission::checkActionPermission('CiviGrant', CRM_Core_Action::DELETE)) {
99 $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/grant',
100 "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"
101 );
102 }
103 CRM_Utils_Recent::add($title,
104 $url,
105 $values['id'],
106 'Grant',
107 $values['contact_id'],
108 NULL,
109 $recentOther
110 );
111
112 $attachment = CRM_Core_BAO_File::attachmentInfo('civicrm_grant', $this->_id);
113 $this->assign('attachment', $attachment);
114
115 $grantType = CRM_Core_DAO::getFieldValue("CRM_Grant_DAO_Grant", $this->_id, "grant_type_id");
116 $groupTree = &CRM_Core_BAO_CustomGroup::getTree("Grant", $this, $this->_id, 0, $grantType);
117 CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
118
119 $this->assign('id', $this->_id);
120 }
121
122 /**
123 * Function to build the form
124 *
125 * @return None
126 * @access public
127 */
128 public function buildQuickForm() {
129 $this->addButtons(array(
130 array(
131 'type' => 'cancel',
132 'name' => ts('Done'),
133 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
134 'isDefault' => TRUE,
135 ),
136 )
137 );
138 }
139 }
140