Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
18 | /** | |
19 | * This class generates form components for processing a Grant | |
20 | * | |
21 | */ | |
22 | class CRM_Grant_Form_GrantView extends CRM_Core_Form { | |
23 | ||
24 | /** | |
fe482240 | 25 | * Set variables up before form is built. |
6a488035 TO |
26 | * |
27 | * @return void | |
6a488035 TO |
28 | */ |
29 | public function preProcess() { | |
30 | $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this); | |
353ffa53 | 31 | $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); |
edc80cda | 32 | $context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this); |
6a488035 TO |
33 | $this->assign('context', $context); |
34 | ||
be2fb01f | 35 | $values = []; |
6a488035 TO |
36 | $params['id'] = $this->_id; |
37 | CRM_Grant_BAO_Grant::retrieve($params, $values); | |
fb1fd730 CW |
38 | $grantType = CRM_Core_PseudoConstant::get('CRM_Grant_DAO_Grant', 'grant_type_id'); |
39 | $grantStatus = CRM_Core_PseudoConstant::get('CRM_Grant_DAO_Grant', 'status_id'); | |
6a488035 TO |
40 | $this->assign('grantType', $grantType[$values['grant_type_id']]); |
41 | $this->assign('grantStatus', $grantStatus[$values['status_id']]); | |
be2fb01f | 42 | $grantTokens = [ |
353ffa53 TO |
43 | 'amount_total', |
44 | 'amount_requested', | |
45 | 'amount_granted', | |
46 | 'rationale', | |
47 | 'grant_report_received', | |
48 | 'application_received_date', | |
49 | 'decision_date', | |
50 | 'money_transfer_date', | |
51 | 'grant_due_date', | |
be2fb01f | 52 | ]; |
6a488035 TO |
53 | |
54 | foreach ($grantTokens as $token) { | |
55 | $this->assign($token, CRM_Utils_Array::value($token, $values)); | |
56 | } | |
57 | ||
58 | if (isset($this->_id)) { | |
59 | $noteDAO = new CRM_Core_BAO_Note(); | |
60 | $noteDAO->entity_table = 'civicrm_grant'; | |
61 | $noteDAO->entity_id = $this->_id; | |
62 | if ($noteDAO->find(TRUE)) { | |
63 | $this->_noteId = $noteDAO->id; | |
64 | } | |
65 | } | |
66 | ||
67 | if (isset($this->_noteId)) { | |
68 | $this->assign('note', CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Note', $this->_noteId, 'note')); | |
69 | } | |
70 | ||
6a488035 TO |
71 | // add Grant to Recent Items |
72 | $url = CRM_Utils_System::url('civicrm/contact/view/grant', | |
73 | "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home" | |
74 | ); | |
75 | ||
76 | $title = CRM_Contact_BAO_Contact::displayName($values['contact_id']) . ' - ' . ts('Grant') . ': ' . CRM_Utils_Money::format($values['amount_total']) . ' (' . $grantType[$values['grant_type_id']] . ')'; | |
77 | ||
be2fb01f | 78 | $recentOther = []; |
6a488035 TO |
79 | if (CRM_Core_Permission::checkActionPermission('CiviGrant', CRM_Core_Action::UPDATE)) { |
80 | $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/grant', | |
81 | "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home" | |
82 | ); | |
83 | } | |
84 | if (CRM_Core_Permission::checkActionPermission('CiviGrant', CRM_Core_Action::DELETE)) { | |
85 | $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/grant', | |
86 | "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home" | |
87 | ); | |
88 | } | |
89 | CRM_Utils_Recent::add($title, | |
90 | $url, | |
91 | $values['id'], | |
92 | 'Grant', | |
93 | $values['contact_id'], | |
94 | NULL, | |
95 | $recentOther | |
96 | ); | |
97 | ||
98 | $attachment = CRM_Core_BAO_File::attachmentInfo('civicrm_grant', $this->_id); | |
99 | $this->assign('attachment', $attachment); | |
100 | ||
101 | $grantType = CRM_Core_DAO::getFieldValue("CRM_Grant_DAO_Grant", $this->_id, "grant_type_id"); | |
0b330e6d | 102 | $groupTree = CRM_Core_BAO_CustomGroup::getTree("Grant", NULL, $this->_id, 0, $grantType); |
ba475058 | 103 | CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $this->_id); |
6a488035 TO |
104 | |
105 | $this->assign('id', $this->_id); | |
e2046b33 CW |
106 | |
107 | $this->setPageTitle(ts('Grant')); | |
6a488035 TO |
108 | } |
109 | ||
110 | /** | |
fe482240 | 111 | * Build the form object. |
6a488035 | 112 | * |
355ba699 | 113 | * @return void |
6a488035 TO |
114 | */ |
115 | public function buildQuickForm() { | |
be2fb01f | 116 | $this->addButtons([ |
7e8c8317 SL |
117 | [ |
118 | 'type' => 'cancel', | |
119 | 'name' => ts('Done'), | |
120 | 'spacing' => ' ', | |
121 | 'isDefault' => TRUE, | |
122 | ], | |
123 | ]); | |
6a488035 | 124 | } |
96025800 | 125 | |
6a488035 | 126 | } |