Merge pull request #13457 from mattwire/contact_note
[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 const
42 // Case tasks
43 RESTORE_CASES = 501;
44
45 static $objectType = 'case';
46
47 /**
48 * These tasks are the core set of tasks that the user can perform
49 * on a contact / group of contacts
50 *
51 * @return array
52 * the set of tasks for a group of contacts
53 */
54 public static function tasks() {
55 if (!self::$_tasks) {
56 self::$_tasks = array(
57 self::TASK_DELETE => array(
58 'title' => ts('Delete cases'),
59 'class' => 'CRM_Case_Form_Task_Delete',
60 'result' => FALSE,
61 ),
62 self::TASK_PRINT => array(
63 'title' => ts('Print selected rows'),
64 'class' => 'CRM_Case_Form_Task_Print',
65 'result' => FALSE,
66 ),
67 self::TASK_EXPORT => array(
68 'title' => ts('Export cases'),
69 'class' => array(
70 'CRM_Export_Form_Select_Case',
71 'CRM_Export_Form_Map',
72 ),
73 'result' => FALSE,
74 ),
75 self::RESTORE_CASES => array(
76 'title' => ts('Restore cases'),
77 'class' => 'CRM_Case_Form_Task_Restore',
78 'result' => FALSE,
79 ),
80 self::PDF_LETTER => array(
81 'title' => ts('Print/merge document'),
82 'class' => 'CRM_Case_Form_Task_PDF',
83 'result' => FALSE,
84 ),
85 self::BATCH_UPDATE => array(
86 'title' => ts('Update multiple cases'),
87 'class' => array(
88 'CRM_Case_Form_Task_PickProfile',
89 'CRM_Case_Form_Task_Batch',
90 ),
91 'result' => FALSE,
92 ),
93 );
94
95 //CRM-4418, check for delete
96 if (!CRM_Core_Permission::check('delete in CiviCase')) {
97 unset(self::$_tasks[self::TASK_DELETE]);
98 }
99
100 parent::tasks();
101 }
102
103 return self::$_tasks;
104 }
105
106 /**
107 * Show tasks selectively based on the permission level.
108 * of the user
109 *
110 * @param int $permission
111 * @param array $params
112 *
113 * @return array
114 * set of tasks that are valid for the user
115 */
116 public static function permissionedTaskTitles($permission, $params = array()) {
117 if (($permission == CRM_Core_Permission::EDIT)
118 || CRM_Core_Permission::check('access all cases and activities')
119 || CRM_Core_Permission::check('access my cases and activities')
120 ) {
121 $tasks = self::taskTitles();
122 }
123 else {
124 $tasks = array(
125 self::TASK_EXPORT => self::$_tasks[self::TASK_EXPORT]['title'],
126 );
127 //CRM-4418,
128 if (CRM_Core_Permission::check('delete in CiviCase')) {
129 $tasks[self::TASK_DELETE] = self::$_tasks[self::TASK_DELETE]['title'];
130 }
131 }
132
133 $tasks = parent::corePermissionedTaskTitles($tasks, $permission, $params);
134 return $tasks;
135 }
136
137 /**
138 * These tasks are the core set of tasks.
139 *
140 * @param int $value
141 *
142 * @return array
143 * the set of tasks for a group of contacts
144 */
145 public static function getTask($value) {
146 self::tasks();
147 if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) {
148 // make the print task by default
149 $value = self::TASK_PRINT;
150 }
151
152 return array(
153 self::$_tasks[$value]['class'],
154 self::$_tasks[$value]['result'],
155 );
156 }
157
158 }