dev/financial#77 ++ Make contribution_id mandatory for PaymentProcessor.pay, pass...
[civicrm-core.git] / CRM / Case / Task.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2019
32 */
33
34 /**
35 * Class to represent the actions that can be performed on a group of contacts.
36 *
37 * Used by the search forms
38 */
39 class CRM_Case_Task extends CRM_Core_Task {
40
41 /**
42 * Case tasks
43 */
44 const RESTORE_CASES = 501;
45
46 /**
47 * @var string
48 */
49 public static $objectType = 'case';
50
51 /**
52 * These tasks are the core set of tasks that the user can perform
53 * on a contact / group of contacts
54 *
55 * @return array
56 * the set of tasks for a group of contacts
57 */
58 public static function tasks() {
59 if (!self::$_tasks) {
60 self::$_tasks = [
61 self::TASK_DELETE => [
62 'title' => ts('Delete cases'),
63 'class' => 'CRM_Case_Form_Task_Delete',
64 'result' => FALSE,
65 ],
66 self::TASK_PRINT => [
67 'title' => ts('Print selected rows'),
68 'class' => 'CRM_Case_Form_Task_Print',
69 'result' => FALSE,
70 ],
71 self::TASK_EXPORT => [
72 'title' => ts('Export cases'),
73 'class' => [
74 'CRM_Export_Form_Select_Case',
75 'CRM_Export_Form_Map',
76 ],
77 'result' => FALSE,
78 ],
79 self::RESTORE_CASES => [
80 'title' => ts('Restore cases'),
81 'class' => 'CRM_Case_Form_Task_Restore',
82 'result' => FALSE,
83 ],
84 self::PDF_LETTER => [
85 'title' => ts('Print/merge document'),
86 'class' => 'CRM_Case_Form_Task_PDF',
87 'result' => FALSE,
88 ],
89 self::BATCH_UPDATE => [
90 'title' => ts('Update multiple cases'),
91 'class' => [
92 'CRM_Case_Form_Task_PickProfile',
93 'CRM_Case_Form_Task_Batch',
94 ],
95 'result' => FALSE,
96 ],
97 ];
98
99 //CRM-4418, check for delete
100 if (!CRM_Core_Permission::check('delete in CiviCase')) {
101 unset(self::$_tasks[self::TASK_DELETE]);
102 }
103
104 parent::tasks();
105 }
106
107 return self::$_tasks;
108 }
109
110 /**
111 * Show tasks selectively based on the permission level.
112 * of the user
113 *
114 * @param int $permission
115 * @param array $params
116 *
117 * @return array
118 * set of tasks that are valid for the user
119 */
120 public static function permissionedTaskTitles($permission, $params = []) {
121 if (($permission == CRM_Core_Permission::EDIT)
122 || CRM_Core_Permission::check('access all cases and activities')
123 || CRM_Core_Permission::check('access my cases and activities')
124 ) {
125 $tasks = self::taskTitles();
126 }
127 else {
128 $tasks = [
129 self::TASK_EXPORT => self::$_tasks[self::TASK_EXPORT]['title'],
130 ];
131 //CRM-4418,
132 if (CRM_Core_Permission::check('delete in CiviCase')) {
133 $tasks[self::TASK_DELETE] = self::$_tasks[self::TASK_DELETE]['title'];
134 }
135 }
136
137 $tasks = parent::corePermissionedTaskTitles($tasks, $permission, $params);
138 return $tasks;
139 }
140
141 /**
142 * These tasks are the core set of tasks.
143 *
144 * @param int $value
145 *
146 * @return array
147 * the set of tasks for a group of contacts
148 */
149 public static function getTask($value) {
150 self::tasks();
151 if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) {
152 // make the print task by default
153 $value = self::TASK_PRINT;
154 }
155
156 return [
157 self::$_tasks[$value]['class'],
158 self::$_tasks[$value]['result'],
159 ];
160 }
161
162 }