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