Merge pull request #15843 from totten/master-simplehead
[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 * $Id$
17 *
18 */
19
20 /**
21 * This class generates form components for processing a Grant
22 *
23 */
24 class CRM_Grant_Form_GrantView extends CRM_Core_Form {
25
26 /**
27 * Set variables up before form is built.
28 *
29 * @return void
30 */
31 public function preProcess() {
32 $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
33 $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
34 $context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this);
35 $this->assign('context', $context);
36
37 $values = [];
38 $params['id'] = $this->_id;
39 CRM_Grant_BAO_Grant::retrieve($params, $values);
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');
42 $this->assign('grantType', $grantType[$values['grant_type_id']]);
43 $this->assign('grantStatus', $grantStatus[$values['status_id']]);
44 $grantTokens = [
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',
54 ];
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
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
80 $recentOther = [];
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");
104 $groupTree = CRM_Core_BAO_CustomGroup::getTree("Grant", NULL, $this->_id, 0, $grantType);
105 CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $this->_id);
106
107 $this->assign('id', $this->_id);
108
109 $this->setPageTitle(ts('Grant'));
110 }
111
112 /**
113 * Build the form object.
114 *
115 * @return void
116 */
117 public function buildQuickForm() {
118 $this->addButtons([
119 [
120 'type' => 'cancel',
121 'name' => ts('Done'),
122 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
123 'isDefault' => TRUE,
124 ],
125 ]);
126 }
127
128 }