Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
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 | |
6b83d5bd | 31 | * @copyright CiviCRM LLC (c) 2004-2019 |
6a488035 TO |
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 | /** | |
fe482240 | 43 | * Set variables up before form is built. |
6a488035 TO |
44 | * |
45 | * @return void | |
6a488035 TO |
46 | */ |
47 | public function preProcess() { | |
48 | $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this); | |
353ffa53 | 49 | $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); |
edc80cda | 50 | $context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this); |
6a488035 TO |
51 | $this->assign('context', $context); |
52 | ||
be2fb01f | 53 | $values = []; |
6a488035 TO |
54 | $params['id'] = $this->_id; |
55 | CRM_Grant_BAO_Grant::retrieve($params, $values); | |
fb1fd730 CW |
56 | $grantType = CRM_Core_PseudoConstant::get('CRM_Grant_DAO_Grant', 'grant_type_id'); |
57 | $grantStatus = CRM_Core_PseudoConstant::get('CRM_Grant_DAO_Grant', 'status_id'); | |
6a488035 TO |
58 | $this->assign('grantType', $grantType[$values['grant_type_id']]); |
59 | $this->assign('grantStatus', $grantStatus[$values['status_id']]); | |
be2fb01f | 60 | $grantTokens = [ |
353ffa53 TO |
61 | 'amount_total', |
62 | 'amount_requested', | |
63 | 'amount_granted', | |
64 | 'rationale', | |
65 | 'grant_report_received', | |
66 | 'application_received_date', | |
67 | 'decision_date', | |
68 | 'money_transfer_date', | |
69 | 'grant_due_date', | |
be2fb01f | 70 | ]; |
6a488035 TO |
71 | |
72 | foreach ($grantTokens as $token) { | |
73 | $this->assign($token, CRM_Utils_Array::value($token, $values)); | |
74 | } | |
75 | ||
76 | if (isset($this->_id)) { | |
77 | $noteDAO = new CRM_Core_BAO_Note(); | |
78 | $noteDAO->entity_table = 'civicrm_grant'; | |
79 | $noteDAO->entity_id = $this->_id; | |
80 | if ($noteDAO->find(TRUE)) { | |
81 | $this->_noteId = $noteDAO->id; | |
82 | } | |
83 | } | |
84 | ||
85 | if (isset($this->_noteId)) { | |
86 | $this->assign('note', CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Note', $this->_noteId, 'note')); | |
87 | } | |
88 | ||
6a488035 TO |
89 | // add Grant to Recent Items |
90 | $url = CRM_Utils_System::url('civicrm/contact/view/grant', | |
91 | "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home" | |
92 | ); | |
93 | ||
94 | $title = CRM_Contact_BAO_Contact::displayName($values['contact_id']) . ' - ' . ts('Grant') . ': ' . CRM_Utils_Money::format($values['amount_total']) . ' (' . $grantType[$values['grant_type_id']] . ')'; | |
95 | ||
be2fb01f | 96 | $recentOther = []; |
6a488035 TO |
97 | if (CRM_Core_Permission::checkActionPermission('CiviGrant', CRM_Core_Action::UPDATE)) { |
98 | $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/grant', | |
99 | "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home" | |
100 | ); | |
101 | } | |
102 | if (CRM_Core_Permission::checkActionPermission('CiviGrant', CRM_Core_Action::DELETE)) { | |
103 | $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/grant', | |
104 | "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home" | |
105 | ); | |
106 | } | |
107 | CRM_Utils_Recent::add($title, | |
108 | $url, | |
109 | $values['id'], | |
110 | 'Grant', | |
111 | $values['contact_id'], | |
112 | NULL, | |
113 | $recentOther | |
114 | ); | |
115 | ||
116 | $attachment = CRM_Core_BAO_File::attachmentInfo('civicrm_grant', $this->_id); | |
117 | $this->assign('attachment', $attachment); | |
118 | ||
119 | $grantType = CRM_Core_DAO::getFieldValue("CRM_Grant_DAO_Grant", $this->_id, "grant_type_id"); | |
0b330e6d | 120 | $groupTree = CRM_Core_BAO_CustomGroup::getTree("Grant", NULL, $this->_id, 0, $grantType); |
ba475058 | 121 | CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $this->_id); |
6a488035 TO |
122 | |
123 | $this->assign('id', $this->_id); | |
e2046b33 CW |
124 | |
125 | $this->setPageTitle(ts('Grant')); | |
6a488035 TO |
126 | } |
127 | ||
128 | /** | |
fe482240 | 129 | * Build the form object. |
6a488035 | 130 | * |
355ba699 | 131 | * @return void |
6a488035 TO |
132 | */ |
133 | public function buildQuickForm() { | |
be2fb01f | 134 | $this->addButtons([ |
7e8c8317 SL |
135 | [ |
136 | 'type' => 'cancel', | |
137 | 'name' => ts('Done'), | |
138 | 'spacing' => ' ', | |
139 | 'isDefault' => TRUE, | |
140 | ], | |
141 | ]); | |
6a488035 | 142 | } |
96025800 | 143 | |
6a488035 | 144 | } |