INFRA-132 - Civi - PHPStorm cleanup
[civicrm-core.git] / CRM / Grant / Form / GrantView.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
6a488035 5 +--------------------------------------------------------------------+
06b69b18 6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
26*/
27
28/**
29 *
30 * @package CRM
06b69b18 31 * @copyright CiviCRM LLC (c) 2004-2014
6a488035
TO
32 * $Id$
33 *
34 */
35
36/**
37 * This class generates form components for processing a Grant
38 *
39 */
40class CRM_Grant_Form_GrantView extends CRM_Core_Form {
41
42 /**
100fef9d 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);
49 $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
50 $context = CRM_Utils_Request::retrieve('context', 'String', $this);
51 $this->assign('context', $context);
52
53 $values = array();
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']]);
60 $grantTokens = array(
61 'amount_total', 'amount_requested', 'amount_granted',
62 'rationale', 'grant_report_received', 'application_received_date',
63 'decision_date', 'money_transfer_date', 'grant_due_date',
64 );
65
66 foreach ($grantTokens as $token) {
67 $this->assign($token, CRM_Utils_Array::value($token, $values));
68 }
69
70 if (isset($this->_id)) {
71 $noteDAO = new CRM_Core_BAO_Note();
72 $noteDAO->entity_table = 'civicrm_grant';
73 $noteDAO->entity_id = $this->_id;
74 if ($noteDAO->find(TRUE)) {
75 $this->_noteId = $noteDAO->id;
76 }
77 }
78
79 if (isset($this->_noteId)) {
80 $this->assign('note', CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Note', $this->_noteId, 'note'));
81 }
82
6a488035
TO
83 // add Grant to Recent Items
84 $url = CRM_Utils_System::url('civicrm/contact/view/grant',
85 "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"
86 );
87
88 $title = CRM_Contact_BAO_Contact::displayName($values['contact_id']) . ' - ' . ts('Grant') . ': ' . CRM_Utils_Money::format($values['amount_total']) . ' (' . $grantType[$values['grant_type_id']] . ')';
89
90 $recentOther = array();
91 if (CRM_Core_Permission::checkActionPermission('CiviGrant', CRM_Core_Action::UPDATE)) {
92 $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/grant',
93 "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"
94 );
95 }
96 if (CRM_Core_Permission::checkActionPermission('CiviGrant', CRM_Core_Action::DELETE)) {
97 $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/grant',
98 "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"
99 );
100 }
101 CRM_Utils_Recent::add($title,
102 $url,
103 $values['id'],
104 'Grant',
105 $values['contact_id'],
106 NULL,
107 $recentOther
108 );
109
110 $attachment = CRM_Core_BAO_File::attachmentInfo('civicrm_grant', $this->_id);
111 $this->assign('attachment', $attachment);
112
113 $grantType = CRM_Core_DAO::getFieldValue("CRM_Grant_DAO_Grant", $this->_id, "grant_type_id");
114 $groupTree = &CRM_Core_BAO_CustomGroup::getTree("Grant", $this, $this->_id, 0, $grantType);
115 CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
116
117 $this->assign('id', $this->_id);
e2046b33
CW
118
119 $this->setPageTitle(ts('Grant'));
6a488035
TO
120 }
121
122 /**
c490a46a 123 * Build the form object
6a488035 124 *
355ba699 125 * @return void
6a488035
TO
126 */
127 public function buildQuickForm() {
128 $this->addButtons(array(
129 array(
130 'type' => 'cancel',
131 'name' => ts('Done'),
132 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
133 'isDefault' => TRUE,
134 ),
135 )
136 );
137 }
138}