Merge pull request #20909 from eileenmcnaughton/index
[civicrm-core.git] / CRM / Grant / Form / GrantView.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
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 /**
25 * Set variables up before form is built.
26 *
27 * @return void
28 */
29 public function preProcess() {
30 $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
31 $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
32 $context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this);
33 $this->assign('context', $context);
34
35 $values = [];
36 $params['id'] = $this->_id;
37 CRM_Grant_BAO_Grant::retrieve($params, $values);
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');
40 $this->assign('grantType', $grantType[$values['grant_type_id']]);
41 $this->assign('grantStatus', $grantStatus[$values['status_id']]);
42 $grantTokens = [
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',
52 ];
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
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
78 $recentOther = [];
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");
102 $groupTree = CRM_Core_BAO_CustomGroup::getTree("Grant", NULL, $this->_id, 0, $grantType, NULL,
103 TRUE, NULL, FALSE, CRM_Core_Permission::VIEW);
104 CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $this->_id);
105
106 $this->assign('id', $this->_id);
107
108 $this->setPageTitle(ts('Grant'));
109 }
110
111 /**
112 * Build the form object.
113 *
114 * @return void
115 */
116 public function buildQuickForm() {
117 $this->addButtons([
118 [
119 'type' => 'cancel',
120 'name' => ts('Done'),
121 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
122 'isDefault' => TRUE,
123 ],
124 ]);
125 }
126
127 }