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 | */ |
33 | ||
34 | /** | |
67d19299 | 35 | * Class to represent the actions that can be performed on a group of contacts. |
6a488035 | 36 | * |
67d19299 | 37 | * Used by the search forms |
6a488035 | 38 | */ |
047838bc | 39 | class CRM_Case_Task extends CRM_Core_Task { |
6a488035 | 40 | |
f157740d SL |
41 | /** |
42 | * Case tasks | |
43 | */ | |
44 | const RESTORE_CASES = 501; | |
6a488035 | 45 | |
f157740d SL |
46 | /** |
47 | * @var string | |
48 | */ | |
49 | public static $objectType = 'case'; | |
6a488035 TO |
50 | |
51 | /** | |
52 | * These tasks are the core set of tasks that the user can perform | |
53 | * on a contact / group of contacts | |
54 | * | |
a6c01b45 CW |
55 | * @return array |
56 | * the set of tasks for a group of contacts | |
6a488035 | 57 | */ |
047838bc | 58 | public static function tasks() { |
6a488035 | 59 | if (!self::$_tasks) { |
be2fb01f CW |
60 | self::$_tasks = [ |
61 | self::TASK_DELETE => [ | |
7f82e636 | 62 | 'title' => ts('Delete cases'), |
6a488035 TO |
63 | 'class' => 'CRM_Case_Form_Task_Delete', |
64 | 'result' => FALSE, | |
be2fb01f CW |
65 | ], |
66 | self::TASK_PRINT => [ | |
7f82e636 | 67 | 'title' => ts('Print selected rows'), |
6a488035 TO |
68 | 'class' => 'CRM_Case_Form_Task_Print', |
69 | 'result' => FALSE, | |
be2fb01f CW |
70 | ], |
71 | self::TASK_EXPORT => [ | |
7f82e636 | 72 | 'title' => ts('Export cases'), |
be2fb01f | 73 | 'class' => [ |
d5fd18f6 | 74 | 'CRM_Export_Form_Select_Case', |
6a488035 | 75 | 'CRM_Export_Form_Map', |
be2fb01f | 76 | ], |
6a488035 | 77 | 'result' => FALSE, |
be2fb01f CW |
78 | ], |
79 | self::RESTORE_CASES => [ | |
7f82e636 | 80 | 'title' => ts('Restore cases'), |
6a488035 TO |
81 | 'class' => 'CRM_Case_Form_Task_Restore', |
82 | 'result' => FALSE, | |
be2fb01f CW |
83 | ], |
84 | self::PDF_LETTER => [ | |
d85976d8 | 85 | 'title' => ts('Print/merge document'), |
13e6f3e9 | 86 | 'class' => 'CRM_Case_Form_Task_PDF', |
8ffa3b7c | 87 | 'result' => FALSE, |
be2fb01f CW |
88 | ], |
89 | self::BATCH_UPDATE => [ | |
888da08c | 90 | 'title' => ts('Update multiple cases'), |
be2fb01f | 91 | 'class' => [ |
888da08c MW |
92 | 'CRM_Case_Form_Task_PickProfile', |
93 | 'CRM_Case_Form_Task_Batch', | |
be2fb01f | 94 | ], |
888da08c | 95 | 'result' => FALSE, |
be2fb01f CW |
96 | ], |
97 | ]; | |
4d73a5a7 | 98 | |
6a488035 TO |
99 | //CRM-4418, check for delete |
100 | if (!CRM_Core_Permission::check('delete in CiviCase')) { | |
047838bc | 101 | unset(self::$_tasks[self::TASK_DELETE]); |
6a488035 | 102 | } |
4d73a5a7 | 103 | |
047838bc | 104 | parent::tasks(); |
6a488035 TO |
105 | } |
106 | ||
6a488035 TO |
107 | return self::$_tasks; |
108 | } | |
109 | ||
6a488035 | 110 | /** |
fe482240 | 111 | * Show tasks selectively based on the permission level. |
6a488035 TO |
112 | * of the user |
113 | * | |
114 | * @param int $permission | |
047838bc | 115 | * @param array $params |
6a488035 | 116 | * |
a6c01b45 CW |
117 | * @return array |
118 | * set of tasks that are valid for the user | |
6a488035 | 119 | */ |
be2fb01f | 120 | public static function permissionedTaskTitles($permission, $params = []) { |
6a488035 TO |
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 { | |
be2fb01f | 128 | $tasks = [ |
047838bc | 129 | self::TASK_EXPORT => self::$_tasks[self::TASK_EXPORT]['title'], |
be2fb01f | 130 | ]; |
6a488035 TO |
131 | //CRM-4418, |
132 | if (CRM_Core_Permission::check('delete in CiviCase')) { | |
047838bc | 133 | $tasks[self::TASK_DELETE] = self::$_tasks[self::TASK_DELETE]['title']; |
6a488035 TO |
134 | } |
135 | } | |
047838bc MW |
136 | |
137 | $tasks = parent::corePermissionedTaskTitles($tasks, $permission, $params); | |
6a488035 TO |
138 | return $tasks; |
139 | } | |
140 | ||
141 | /** | |
fe482240 | 142 | * These tasks are the core set of tasks. |
6a488035 TO |
143 | * |
144 | * @param int $value | |
145 | * | |
a6c01b45 CW |
146 | * @return array |
147 | * the set of tasks for a group of contacts | |
6a488035 | 148 | */ |
00be9182 | 149 | public static function getTask($value) { |
6a488035 TO |
150 | self::tasks(); |
151 | if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) { | |
152 | // make the print task by default | |
047838bc | 153 | $value = self::TASK_PRINT; |
6a488035 TO |
154 | } |
155 | ||
be2fb01f | 156 | return [ |
6a488035 TO |
157 | self::$_tasks[$value]['class'], |
158 | self::$_tasks[$value]['result'], | |
be2fb01f | 159 | ]; |
6a488035 | 160 | } |
96025800 | 161 | |
6a488035 | 162 | } |