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