Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * This class provides the functionality to update a group of | |
38 | * grants. This class provides functionality for the actual | |
39 | * update. | |
40 | */ | |
41 | class CRM_Grant_Form_Task_Update extends CRM_Grant_Form_Task { | |
42 | ||
43 | /** | |
fe482240 | 44 | * Build all the data structures needed to build the form. |
6a488035 TO |
45 | * |
46 | * @return void | |
6a488035 | 47 | */ |
00be9182 | 48 | public function preProcess() { |
6a488035 TO |
49 | parent::preProcess(); |
50 | ||
51 | //check permission for update. | |
52 | if (!CRM_Core_Permission::checkActionPermission('CiviGrant', CRM_Core_Action::UPDATE)) { | |
0499b0ad | 53 | CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); |
6a488035 TO |
54 | } |
55 | } | |
56 | ||
57 | /** | |
fe482240 | 58 | * Build the form object. |
6a488035 | 59 | * |
6a488035 TO |
60 | * |
61 | * @return void | |
62 | */ | |
00be9182 | 63 | public function buildQuickForm() { |
fb1fd730 | 64 | $grantStatus = CRM_Core_PseudoConstant::get('CRM_Grant_DAO_Grant', 'status_id'); |
6a488035 TO |
65 | $this->addElement('select', 'status_id', ts('Grant Status'), array('' => '') + $grantStatus); |
66 | ||
67 | $this->addElement('text', 'amount_granted', ts('Amount Granted')); | |
68 | $this->addRule('amount_granted', ts('Please enter a valid amount.'), 'money'); | |
69 | ||
70 | $this->addDate('decision_date', ts('Grant Decision'), FALSE, array('formatType' => 'custom')); | |
71 | ||
72 | $this->assign('elements', array('status_id', 'amount_granted', 'decision_date')); | |
73 | $this->assign('totalSelectedGrants', count($this->_grantIds)); | |
74 | ||
75 | $this->addDefaultButtons(ts('Update Grants'), 'done'); | |
76 | } | |
77 | ||
78 | /** | |
fe482240 | 79 | * Process the form after the input has been submitted and validated. |
6a488035 | 80 | * |
6a488035 | 81 | * |
355ba699 | 82 | * @return void |
6a488035 TO |
83 | */ |
84 | public function postProcess() { | |
85 | $updatedGrants = 0; | |
86 | ||
87 | // get the submitted form values. | |
88 | $params = $this->controller->exportValues($this->_name); | |
89 | $qfKey = $params['qfKey']; | |
90 | foreach ($params as $key => $value) { | |
91 | if ($value == '' || $key == 'qfKey') { | |
92 | unset($params[$key]); | |
93 | } | |
94 | } | |
95 | ||
96 | if (!empty($params)) { | |
97 | foreach ($params as $key => $value) { | |
98 | $values[$key] = $value; | |
99 | } | |
100 | foreach ($this->_grantIds as $grantId) { | |
565df8cf | 101 | $ids['grant_id'] = $grantId; |
6a488035 TO |
102 | |
103 | CRM_Grant_BAO_Grant::add($values, $ids); | |
104 | $updatedGrants++; | |
105 | } | |
106 | } | |
107 | ||
0bc90828 KM |
108 | $status = ts('Updated Grant(s): %1 (Total Selected: %2)', array(1 => $updatedGrants, 2 => count($this->_grantIds))); |
109 | CRM_Core_Session::setStatus($status, '', 'info'); | |
6a488035 TO |
110 | CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/grant/search', 'force=1&qfKey=' . $qfKey)); |
111 | } | |
96025800 | 112 | |
6a488035 | 113 | } |