Merge pull request #18645 from seamuslee001/frontend_group
[civicrm-core.git] / CRM / Case / Task.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
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 |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 */
17
18/**
67d19299 19 * Class to represent the actions that can be performed on a group of contacts.
6a488035 20 *
67d19299 21 * Used by the search forms
6a488035 22 */
047838bc 23class CRM_Case_Task extends CRM_Core_Task {
6a488035 24
f157740d
SL
25 /**
26 * Case tasks
27 */
28 const RESTORE_CASES = 501;
6a488035 29
f157740d
SL
30 /**
31 * @var string
32 */
33 public static $objectType = 'case';
6a488035
TO
34
35 /**
36 * These tasks are the core set of tasks that the user can perform
37 * on a contact / group of contacts
38 *
a6c01b45
CW
39 * @return array
40 * the set of tasks for a group of contacts
6a488035 41 */
047838bc 42 public static function tasks() {
6a488035 43 if (!self::$_tasks) {
be2fb01f
CW
44 self::$_tasks = [
45 self::TASK_DELETE => [
7f82e636 46 'title' => ts('Delete cases'),
6a488035
TO
47 'class' => 'CRM_Case_Form_Task_Delete',
48 'result' => FALSE,
be2fb01f
CW
49 ],
50 self::TASK_PRINT => [
7f82e636 51 'title' => ts('Print selected rows'),
6a488035
TO
52 'class' => 'CRM_Case_Form_Task_Print',
53 'result' => FALSE,
be2fb01f
CW
54 ],
55 self::TASK_EXPORT => [
7f82e636 56 'title' => ts('Export cases'),
be2fb01f 57 'class' => [
d5fd18f6 58 'CRM_Export_Form_Select_Case',
6a488035 59 'CRM_Export_Form_Map',
be2fb01f 60 ],
6a488035 61 'result' => FALSE,
be2fb01f
CW
62 ],
63 self::RESTORE_CASES => [
7f82e636 64 'title' => ts('Restore cases'),
6a488035
TO
65 'class' => 'CRM_Case_Form_Task_Restore',
66 'result' => FALSE,
be2fb01f
CW
67 ],
68 self::PDF_LETTER => [
d85976d8 69 'title' => ts('Print/merge document'),
13e6f3e9 70 'class' => 'CRM_Case_Form_Task_PDF',
8ffa3b7c 71 'result' => FALSE,
be2fb01f
CW
72 ],
73 self::BATCH_UPDATE => [
888da08c 74 'title' => ts('Update multiple cases'),
be2fb01f 75 'class' => [
888da08c
MW
76 'CRM_Case_Form_Task_PickProfile',
77 'CRM_Case_Form_Task_Batch',
be2fb01f 78 ],
888da08c 79 'result' => FALSE,
be2fb01f
CW
80 ],
81 ];
4d73a5a7 82
6a488035
TO
83 //CRM-4418, check for delete
84 if (!CRM_Core_Permission::check('delete in CiviCase')) {
047838bc 85 unset(self::$_tasks[self::TASK_DELETE]);
6a488035 86 }
4d73a5a7 87
047838bc 88 parent::tasks();
6a488035
TO
89 }
90
6a488035
TO
91 return self::$_tasks;
92 }
93
6a488035 94 /**
fe482240 95 * Show tasks selectively based on the permission level.
6a488035
TO
96 * of the user
97 *
98 * @param int $permission
047838bc 99 * @param array $params
6a488035 100 *
a6c01b45
CW
101 * @return array
102 * set of tasks that are valid for the user
6a488035 103 */
be2fb01f 104 public static function permissionedTaskTitles($permission, $params = []) {
6a488035
TO
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 {
be2fb01f 112 $tasks = [
047838bc 113 self::TASK_EXPORT => self::$_tasks[self::TASK_EXPORT]['title'],
be2fb01f 114 ];
6a488035
TO
115 //CRM-4418,
116 if (CRM_Core_Permission::check('delete in CiviCase')) {
047838bc 117 $tasks[self::TASK_DELETE] = self::$_tasks[self::TASK_DELETE]['title'];
6a488035
TO
118 }
119 }
047838bc
MW
120
121 $tasks = parent::corePermissionedTaskTitles($tasks, $permission, $params);
6a488035
TO
122 return $tasks;
123 }
124
125 /**
fe482240 126 * These tasks are the core set of tasks.
6a488035
TO
127 *
128 * @param int $value
129 *
a6c01b45
CW
130 * @return array
131 * the set of tasks for a group of contacts
6a488035 132 */
00be9182 133 public static function getTask($value) {
6a488035 134 self::tasks();
b99f3e96 135 if (!$value || empty(self::$_tasks[$value])) {
6a488035 136 // make the print task by default
047838bc 137 $value = self::TASK_PRINT;
6a488035
TO
138 }
139
be2fb01f 140 return [
6a488035
TO
141 self::$_tasks[$value]['class'],
142 self::$_tasks[$value]['result'],
be2fb01f 143 ];
6a488035 144 }
96025800 145
6a488035 146}