Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
f299f7db | 6 | | Copyright CiviCRM LLC (c) 2004-2020 | |
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 | |
ca5cec67 | 31 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * class to represent the actions that can be performed on a group of contacts | |
38 | * used by the search forms | |
39 | * | |
40 | */ | |
7b9bce60 | 41 | class CRM_Grant_Task extends CRM_Core_Task { |
6a488035 | 42 | |
7e8c8317 SL |
43 | /** |
44 | * Grant Tasks | |
45 | */ | |
46 | const UPDATE_GRANTS = 701; | |
6a488035 | 47 | |
7e8c8317 SL |
48 | /** |
49 | * @var string | |
50 | */ | |
51 | public static $objectType = 'grant'; | |
6a488035 TO |
52 | |
53 | /** | |
54 | * These tasks are the core set of tasks that the user can perform | |
55 | * on a contact / group of contacts | |
56 | * | |
a6c01b45 CW |
57 | * @return array |
58 | * the set of tasks for a group of contacts | |
6a488035 | 59 | */ |
7b9bce60 | 60 | public static function tasks() { |
6a488035 | 61 | if (!(self::$_tasks)) { |
be2fb01f CW |
62 | self::$_tasks = [ |
63 | self::TASK_DELETE => [ | |
7f82e636 | 64 | 'title' => ts('Delete grants'), |
6a488035 TO |
65 | 'class' => 'CRM_Grant_Form_Task_Delete', |
66 | 'result' => FALSE, | |
be2fb01f CW |
67 | ], |
68 | self::TASK_PRINT => [ | |
7f82e636 | 69 | 'title' => ts('Print selected rows'), |
6a488035 TO |
70 | 'class' => 'CRM_Grant_Form_Task_Print', |
71 | 'result' => FALSE, | |
be2fb01f CW |
72 | ], |
73 | self::TASK_EXPORT => [ | |
7f82e636 | 74 | 'title' => ts('Export grants'), |
be2fb01f | 75 | 'class' => [ |
6a488035 TO |
76 | 'CRM_Export_Form_Select', |
77 | 'CRM_Export_Form_Map', | |
be2fb01f | 78 | ], |
6a488035 | 79 | 'result' => FALSE, |
be2fb01f CW |
80 | ], |
81 | self::UPDATE_GRANTS => [ | |
7f82e636 | 82 | 'title' => ts('Update grants'), |
6a488035 TO |
83 | 'class' => 'CRM_Grant_Form_Task_Update', |
84 | 'result' => FALSE, | |
be2fb01f CW |
85 | ], |
86 | ]; | |
4d73a5a7 | 87 | |
88 | if (!CRM_Core_Permission::check('delete in CiviGrant')) { | |
7b9bce60 | 89 | unset(self::$_tasks[self::TASK_DELETE]); |
4d73a5a7 | 90 | } |
91 | ||
7b9bce60 | 92 | parent::tasks(); |
6a488035 | 93 | } |
4d73a5a7 | 94 | |
6a488035 TO |
95 | return self::$_tasks; |
96 | } | |
97 | ||
6a488035 | 98 | /** |
100fef9d | 99 | * Show tasks selectively based on the permission level |
6a488035 TO |
100 | * of the user |
101 | * | |
102 | * @param int $permission | |
7b9bce60 | 103 | * @param array $params |
6a488035 | 104 | * |
a6c01b45 CW |
105 | * @return array |
106 | * set of tasks that are valid for the user | |
6a488035 | 107 | */ |
be2fb01f | 108 | public static function permissionedTaskTitles($permission, $params = []) { |
6a488035 TO |
109 | if (($permission == CRM_Core_Permission::EDIT) |
110 | || CRM_Core_Permission::check('edit grants') | |
111 | ) { | |
112 | $tasks = self::taskTitles(); | |
113 | } | |
114 | else { | |
be2fb01f | 115 | $tasks = [ |
7b9bce60 | 116 | self::TASK_EXPORT => self::$_tasks[self::TASK_EXPORT]['title'], |
be2fb01f | 117 | ]; |
6a488035 TO |
118 | //CRM-4418, |
119 | if (CRM_Core_Permission::check('delete in CiviGrant')) { | |
7b9bce60 | 120 | $tasks[self::TASK_DELETE] = self::$_tasks[self::TASK_DELETE]['title']; |
6a488035 TO |
121 | } |
122 | } | |
7b9bce60 MW |
123 | |
124 | $tasks = parent::corePermissionedTaskTitles($tasks, $permission, $params); | |
6a488035 TO |
125 | return $tasks; |
126 | } | |
127 | ||
128 | /** | |
129 | * These tasks are the core set of tasks that the user can perform | |
130 | * | |
131 | * @param int $value | |
132 | * | |
a6c01b45 CW |
133 | * @return array |
134 | * the set of tasks for a group of contacts | |
6a488035 | 135 | */ |
00be9182 | 136 | public static function getTask($value) { |
6a488035 | 137 | self::tasks(); |
7b9bce60 MW |
138 | |
139 | if (!CRM_Utils_Array::value($value, self::$_tasks)) { | |
140 | // make it the print task by default | |
141 | $value = self::TASK_PRINT; | |
6a488035 | 142 | } |
7b9bce60 | 143 | return parent::getTask($value); |
6a488035 | 144 | } |
96025800 | 145 | |
6a488035 | 146 | } |