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