Commit | Line | Data |
---|---|---|
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 | /** | |
6a488035 | 13 | * @package CRM |
ca5cec67 | 14 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
15 | */ |
16 | ||
17 | /** | |
3819f101 | 18 | * Class to represent the actions that can be performed on a group of contacts used by the search forms. |
6a488035 | 19 | */ |
be509c11 | 20 | class CRM_Activity_Task extends CRM_Core_Task { |
6a488035 | 21 | |
62d3ee27 | 22 | public static $objectType = 'activity'; |
6a488035 TO |
23 | |
24 | /** | |
7808aae6 SB |
25 | * These tasks are the core set of tasks that the user can perform |
26 | * on a contact / group of contacts. | |
6a488035 | 27 | * |
a6c01b45 CW |
28 | * @return array |
29 | * the set of tasks for a group of contacts | |
6a488035 | 30 | */ |
be509c11 | 31 | public static function tasks() { |
6a488035 | 32 | if (!(self::$_tasks)) { |
be2fb01f CW |
33 | self::$_tasks = [ |
34 | self::TASK_DELETE => [ | |
7f82e636 | 35 | 'title' => ts('Delete activities'), |
6a488035 TO |
36 | 'class' => 'CRM_Activity_Form_Task_Delete', |
37 | 'result' => FALSE, | |
be2fb01f CW |
38 | ], |
39 | self::TASK_PRINT => [ | |
7f82e636 | 40 | 'title' => ts('Print selected rows'), |
6a488035 TO |
41 | 'class' => 'CRM_Activity_Form_Task_Print', |
42 | 'result' => FALSE, | |
be2fb01f CW |
43 | ], |
44 | self::TASK_EXPORT => [ | |
7f82e636 | 45 | 'title' => ts('Export activities'), |
be2fb01f | 46 | 'class' => [ |
6a488035 TO |
47 | 'CRM_Export_Form_Select', |
48 | 'CRM_Export_Form_Map', | |
be2fb01f | 49 | ], |
6a488035 | 50 | 'result' => FALSE, |
be2fb01f CW |
51 | ], |
52 | self::BATCH_UPDATE => [ | |
b581842f | 53 | 'title' => ts('Update multiple activities'), |
be2fb01f | 54 | 'class' => [ |
6a488035 TO |
55 | 'CRM_Activity_Form_Task_PickProfile', |
56 | 'CRM_Activity_Form_Task_Batch', | |
be2fb01f | 57 | ], |
6a488035 | 58 | 'result' => FALSE, |
be2fb01f CW |
59 | ], |
60 | self::TASK_EMAIL => [ | |
61 | 'title' => ts('Email - send now (to %1 or less)', [ | |
21d01648 MW |
62 | 1 => Civi::settings() |
63 | ->get('simple_mail_limit'), | |
be2fb01f CW |
64 | ]), |
65 | 'class' => [ | |
6a488035 TO |
66 | 'CRM_Activity_Form_Task_PickOption', |
67 | 'CRM_Activity_Form_Task_Email', | |
be2fb01f | 68 | ], |
6a488035 | 69 | 'result' => FALSE, |
be2fb01f CW |
70 | ], |
71 | self::TASK_SMS => [ | |
7f82e636 | 72 | 'title' => ts('SMS - send reply'), |
6a488035 TO |
73 | 'class' => 'CRM_Activity_Form_Task_SMS', |
74 | 'result' => FALSE, | |
be2fb01f CW |
75 | ], |
76 | self::TAG_ADD => [ | |
7f82e636 | 77 | 'title' => ts('Tag - add to activities'), |
f70ca446 PN |
78 | 'class' => 'CRM_Activity_Form_Task_AddToTag', |
79 | 'result' => FALSE, | |
be2fb01f CW |
80 | ], |
81 | self::TAG_REMOVE => [ | |
7f82e636 | 82 | 'title' => ts('Tag - remove from activities'), |
f70ca446 PN |
83 | 'class' => 'CRM_Activity_Form_Task_RemoveFromTag', |
84 | 'result' => FALSE, | |
be2fb01f CW |
85 | ], |
86 | ]; | |
6a488035 TO |
87 | |
88 | $config = CRM_Core_Config::singleton(); | |
89 | if (in_array('CiviCase', $config->enableComponents)) { | |
481a74f4 | 90 | if (CRM_Core_Permission::check('access all cases and activities') || |
353ffa53 TO |
91 | CRM_Core_Permission::check('access my cases and activities') |
92 | ) { | |
be2fb01f | 93 | self::$_tasks[self::TASK_SMS] = [ |
7f82e636 | 94 | 'title' => ts('File on case'), |
bbfeec41 BS |
95 | 'class' => 'CRM_Activity_Form_Task_FileOnCase', |
96 | 'result' => FALSE, | |
be2fb01f | 97 | ]; |
bbfeec41 | 98 | } |
6a488035 TO |
99 | } |
100 | ||
7808aae6 | 101 | // CRM-4418, check for delete |
6a488035 | 102 | if (!CRM_Core_Permission::check('delete activities')) { |
be509c11 | 103 | unset(self::$_tasks[self::TASK_DELETE]); |
6a488035 | 104 | } |
4d73a5a7 | 105 | |
be509c11 | 106 | parent::tasks(); |
6a488035 | 107 | } |
4d73a5a7 | 108 | |
6a488035 TO |
109 | return self::$_tasks; |
110 | } | |
111 | ||
6a488035 | 112 | /** |
7808aae6 | 113 | * Show tasks selectively based on the permission level of the user. |
6a488035 TO |
114 | * |
115 | * @param int $permission | |
be509c11 | 116 | * @param array $params |
6a488035 | 117 | * |
a6c01b45 CW |
118 | * @return array |
119 | * set of tasks that are valid for the user | |
6a488035 | 120 | */ |
be2fb01f | 121 | public static function permissionedTaskTitles($permission, $params = []) { |
6a488035 TO |
122 | if ($permission == CRM_Core_Permission::EDIT) { |
123 | $tasks = self::taskTitles(); | |
124 | } | |
125 | else { | |
be2fb01f | 126 | $tasks = [ |
be509c11 | 127 | self::TASK_EXPORT => self::$_tasks[self::TASK_EXPORT]['title'], |
be2fb01f | 128 | ]; |
6a488035 TO |
129 | |
130 | //CRM-4418, | |
131 | if (CRM_Core_Permission::check('delete activities')) { | |
be509c11 | 132 | $tasks[self::TASK_DELETE] = self::$_tasks[self::TASK_DELETE]['title']; |
6a488035 TO |
133 | } |
134 | } | |
be509c11 MW |
135 | |
136 | $tasks = parent::corePermissionedTaskTitles($tasks, $permission, $params); | |
6a488035 TO |
137 | return $tasks; |
138 | } | |
139 | ||
140 | /** | |
7808aae6 | 141 | * These tasks are the core set of tasks that the user can perform on activity. |
6a488035 TO |
142 | * |
143 | * @param int $value | |
144 | * | |
a6c01b45 CW |
145 | * @return array |
146 | * the set of tasks for a group of activity | |
6a488035 | 147 | */ |
00be9182 | 148 | public static function getTask($value) { |
6a488035 TO |
149 | self::tasks(); |
150 | if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) { | |
151 | // make the print task by default | |
be509c11 | 152 | $value = self::TASK_PRINT; |
6a488035 | 153 | } |
be509c11 | 154 | |
be2fb01f | 155 | return [ |
6a488035 TO |
156 | self::$_tasks[$value]['class'], |
157 | self::$_tasks[$value]['result'], | |
be2fb01f | 158 | ]; |
6a488035 | 159 | } |
96025800 | 160 | |
6a488035 | 161 | } |