drupal 9 deprecations
[civicrm-core.git] / CRM / Case / 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 *
21 * Used by the search forms
22 */
23 class CRM_Case_Task extends CRM_Core_Task {
24
25 /**
26 * Case tasks
27 */
28 const RESTORE_CASES = 501;
29
30 /**
31 * @var string
32 */
33 public static $objectType = 'case';
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 cases'),
47 'class' => 'CRM_Case_Form_Task_Delete',
48 'result' => FALSE,
49 ],
50 self::TASK_PRINT => [
51 'title' => ts('Print selected rows'),
52 'class' => 'CRM_Case_Form_Task_Print',
53 'result' => FALSE,
54 ],
55 self::TASK_EXPORT => [
56 'title' => ts('Export cases'),
57 'class' => [
58 'CRM_Export_Form_Select_Case',
59 'CRM_Export_Form_Map',
60 ],
61 'result' => FALSE,
62 ],
63 self::RESTORE_CASES => [
64 'title' => ts('Restore cases'),
65 'class' => 'CRM_Case_Form_Task_Restore',
66 'result' => FALSE,
67 ],
68 self::PDF_LETTER => [
69 'title' => ts('Print/merge document'),
70 'class' => 'CRM_Case_Form_Task_PDF',
71 'result' => FALSE,
72 ],
73 self::BATCH_UPDATE => [
74 'title' => ts('Update multiple cases'),
75 'class' => [
76 'CRM_Case_Form_Task_PickProfile',
77 'CRM_Case_Form_Task_Batch',
78 ],
79 'result' => FALSE,
80 ],
81 ];
82
83 //CRM-4418, check for delete
84 if (!CRM_Core_Permission::check('delete in CiviCase')) {
85 unset(self::$_tasks[self::TASK_DELETE]);
86 }
87
88 parent::tasks();
89 }
90
91 return self::$_tasks;
92 }
93
94 /**
95 * Show tasks selectively based on the permission level.
96 * of the user
97 *
98 * @param int $permission
99 * @param array $params
100 *
101 * @return array
102 * set of tasks that are valid for the user
103 */
104 public static function permissionedTaskTitles($permission, $params = []) {
105 if (($permission == CRM_Core_Permission::EDIT)
106 || CRM_Core_Permission::check('access all cases and activities')
107 || CRM_Core_Permission::check('access my cases and activities')
108 ) {
109 $tasks = self::taskTitles();
110 }
111 else {
112 $tasks = [
113 self::TASK_EXPORT => self::$_tasks[self::TASK_EXPORT]['title'],
114 ];
115 //CRM-4418,
116 if (CRM_Core_Permission::check('delete in CiviCase')) {
117 $tasks[self::TASK_DELETE] = self::$_tasks[self::TASK_DELETE]['title'];
118 }
119 }
120
121 $tasks = parent::corePermissionedTaskTitles($tasks, $permission, $params);
122 return $tasks;
123 }
124
125 /**
126 * These tasks are the core set of tasks.
127 *
128 * @param int $value
129 *
130 * @return array
131 * the set of tasks for a group of contacts
132 */
133 public static function getTask($value) {
134 self::tasks();
135 if (!$value || empty(self::$_tasks[$value])) {
136 // make the print task by default
137 $value = self::TASK_PRINT;
138 }
139
140 return [
141 self::$_tasks[$value]['class'],
142 self::$_tasks[$value]['result'],
143 ];
144 }
145
146 }