Merge pull request #21015 from civicrm/5.40
[civicrm-core.git] / CRM / Grant / Task.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 */
17
18 /**
19 * class to represent the actions that can be performed on a group of contacts
20 * used by the search forms
21 *
22 */
23 class CRM_Grant_Task extends CRM_Core_Task {
24
25 /**
26 * Grant Tasks
27 */
28 const UPDATE_GRANTS = 701;
29
30 /**
31 * @var string
32 */
33 public static $objectType = 'grant';
34
35 /**
36 * These tasks are the core set of tasks that the user can perform
37 * on a contact / group of contacts
38 *
39 * @return array
40 * the set of tasks for a group of contacts
41 */
42 public static function tasks() {
43 if (!(self::$_tasks)) {
44 self::$_tasks = [
45 self::TASK_DELETE => [
46 'title' => ts('Delete grants'),
47 'class' => 'CRM_Grant_Form_Task_Delete',
48 'result' => FALSE,
49 ],
50 self::TASK_PRINT => [
51 'title' => ts('Print selected rows'),
52 'class' => 'CRM_Grant_Form_Task_Print',
53 'result' => FALSE,
54 ],
55 self::TASK_EXPORT => [
56 'title' => ts('Export grants'),
57 'class' => [
58 'CRM_Grant_Export_Form_Select',
59 'CRM_Grant_Export_Form_Map',
60 ],
61 'result' => FALSE,
62 ],
63 self::UPDATE_GRANTS => [
64 'title' => ts('Update grants'),
65 'class' => 'CRM_Grant_Form_Task_Update',
66 'result' => FALSE,
67 ],
68 ];
69
70 if (!CRM_Core_Permission::check('delete in CiviGrant')) {
71 unset(self::$_tasks[self::TASK_DELETE]);
72 }
73
74 parent::tasks();
75 }
76
77 return self::$_tasks;
78 }
79
80 /**
81 * Show tasks selectively based on the permission level
82 * of the user
83 *
84 * @param int $permission
85 * @param array $params
86 *
87 * @return array
88 * set of tasks that are valid for the user
89 */
90 public static function permissionedTaskTitles($permission, $params = []) {
91 if (($permission == CRM_Core_Permission::EDIT)
92 || CRM_Core_Permission::check('edit grants')
93 ) {
94 $tasks = self::taskTitles();
95 }
96 else {
97 $tasks = [
98 self::TASK_EXPORT => self::$_tasks[self::TASK_EXPORT]['title'],
99 ];
100 //CRM-4418,
101 if (CRM_Core_Permission::check('delete in CiviGrant')) {
102 $tasks[self::TASK_DELETE] = self::$_tasks[self::TASK_DELETE]['title'];
103 }
104 }
105
106 $tasks = parent::corePermissionedTaskTitles($tasks, $permission, $params);
107 return $tasks;
108 }
109
110 /**
111 * These tasks are the core set of tasks that the user can perform
112 *
113 * @param int $value
114 *
115 * @return array
116 * the set of tasks for a group of contacts
117 */
118 public static function getTask($value) {
119 self::tasks();
120
121 if (empty(self::$_tasks[$value])) {
122 // make it the print task by default
123 $value = self::TASK_PRINT;
124 }
125 return parent::getTask($value);
126 }
127
128 }