(NFC) Update CRM/Contact to match new coder style
[civicrm-core.git] / CRM / Contact / Task.php
CommitLineData
6a488035 1<?php
6a488035
TO
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/**
95cdcc0f 35 * Class to represent the actions that can be performed on a group of contacts used by the search forms.
6a488035 36 */
f2774867 37class CRM_Contact_Task extends CRM_Core_Task {
6a488035 38
69078420
SL
39 /**
40 * Contact tasks
41 */
f2774867 42 const
f2774867
MW
43 HOUSEHOLD_CONTACTS = 101,
44 ORGANIZATION_CONTACTS = 102,
45 RECORD_CONTACTS = 103,
46 MAP_CONTACTS = 104,
47 ADD_EVENT = 105,
48 MERGE_CONTACTS = 106,
49 EMAIL_UNHOLD = 107,
50 RESTORE = 108,
51 COMMUNICATION_PREFS = 109,
52 INDIVIDUAL_CONTACTS = 110,
53 ADD_TO_CASE = 111;
54
69078420
SL
55 /**
56 * @var string
57 */
58 public static $objectType = 'contact';
6a488035 59
78b22ce9 60 public static function tasks() {
6a488035
TO
61 if (!self::$_tasks) {
62 self::$_tasks = array(
f2774867 63 self::GROUP_ADD => array(
7f82e636 64 'title' => ts('Group - add contacts'),
6a488035 65 'class' => 'CRM_Contact_Form_Task_AddToGroup',
061ff68c 66 'url' => 'civicrm/task/add-to-group',
6a488035 67 ),
f2774867 68 self::GROUP_REMOVE => array(
7f82e636 69 'title' => ts('Group - remove contacts'),
6a488035 70 'class' => 'CRM_Contact_Form_Task_RemoveFromGroup',
061ff68c 71 'url' => 'civicrm/task/remove-from-group',
6a488035 72 ),
f2774867 73 self::TAG_ADD => array(
79e4c2ad 74 'title' => ts('Tag - add to contacts'),
6a488035 75 'class' => 'CRM_Contact_Form_Task_AddToTag',
061ff68c 76 'url' => 'civicrm/task/add-to-tag',
6a488035 77 ),
f2774867 78 self::TAG_REMOVE => array(
7f82e636 79 'title' => ts('Tag - remove from contacts'),
6a488035 80 'class' => 'CRM_Contact_Form_Task_RemoveFromTag',
061ff68c 81 'url' => 'civicrm/task/remove-from-tag',
6a488035 82 ),
f2774867 83 self::TASK_EXPORT => array(
7f82e636 84 'title' => ts('Export contacts'),
6a488035
TO
85 'class' => array(
86 'CRM_Export_Form_Select',
87 'CRM_Export_Form_Map',
88 ),
89 'result' => FALSE,
90 ),
f2774867
MW
91 self::TASK_EMAIL => array(
92 'title' => ts('Email - send now (to %1 or less)', array(
93 1 => Civi::settings()
94 ->get('simple_mail_limit'),
95 )),
6a488035
TO
96 'class' => 'CRM_Contact_Form_Task_Email',
97 'result' => TRUE,
061ff68c 98 'url' => 'civicrm/task/send-email',
6a488035 99 ),
f2774867 100 self::TASK_DELETE => array(
7f82e636 101 'title' => ts('Delete contacts'),
6a488035
TO
102 'class' => 'CRM_Contact_Form_Task_Delete',
103 'result' => FALSE,
061ff68c 104 'url' => 'civicrm/task/delete-contact',
6a488035 105 ),
2a6af255 106 self::RECORD_CONTACTS => array(
7f82e636 107 'title' => ts('Add activity'),
6a488035
TO
108 'class' => 'CRM_Activity_Form_Activity',
109 ),
2a6af255 110 self::SAVE_SEARCH => array(
7f12f044 111 'title' => ts('Group - create smart group'),
6a488035
TO
112 'class' => 'CRM_Contact_Form_Task_SaveSearch',
113 'result' => TRUE,
114 ),
2a6af255 115 self::SAVE_SEARCH_UPDATE => array(
7f12f044 116 'title' => ts('Group - update smart group'),
6a488035
TO
117 'class' => 'CRM_Contact_Form_Task_SaveSearch_Update',
118 'result' => TRUE,
119 ),
f2774867 120 self::TASK_PRINT => array(
7f82e636 121 'title' => ts('Print selected rows'),
6a488035
TO
122 'class' => 'CRM_Contact_Form_Task_Print',
123 'result' => FALSE,
124 ),
2a6af255 125 self::LABEL_CONTACTS => array(
7f82e636 126 'title' => ts('Mailing labels - print'),
6a488035
TO
127 'class' => 'CRM_Contact_Form_Task_Label',
128 'result' => TRUE,
061ff68c 129 'url' => 'civicrm/task/make-mailing-label',
6a488035 130 ),
2a6af255 131 self::BATCH_UPDATE => array(
b581842f 132 'title' => ts('Update multiple contacts'),
6a488035
TO
133 'class' => array(
134 'CRM_Contact_Form_Task_PickProfile',
135 'CRM_Contact_Form_Task_Batch',
136 ),
137 'result' => TRUE,
061ff68c 138 'url' => 'civicrm/task/pick-profile',
6a488035 139 ),
f2774867 140 self::PDF_LETTER => array(
cd095eae 141 'title' => ts('Print/merge document'),
6a488035
TO
142 'class' => 'CRM_Contact_Form_Task_PDF',
143 'result' => TRUE,
061ff68c 144 'url' => 'civicrm/task/print-document',
6a488035 145 ),
2a6af255 146 self::EMAIL_UNHOLD => array(
79e4c2ad 147 'title' => ts('Email - unhold addresses'),
6a488035 148 'class' => 'CRM_Contact_Form_Task_Unhold',
061ff68c 149 'url' => 'civicrm/task/unhold-email',
6a488035 150 ),
2a6af255 151 self::COMMUNICATION_PREFS => array(
7f82e636 152 'title' => ts('Communication preferences - alter'),
6a488035 153 'class' => 'CRM_Contact_Form_Task_AlterPreferences',
061ff68c 154 'url' => 'civicrm/task/alter-contact-preference',
6a488035
TO
155 ),
156 self::RESTORE => array(
7f82e636 157 'title' => ts('Restore contacts from trash'),
6a488035
TO
158 'class' => 'CRM_Contact_Form_Task_Delete',
159 'result' => FALSE,
160 ),
161 self::DELETE_PERMANENTLY => array(
7f82e636 162 'title' => ts('Delete permanently'),
6a488035
TO
163 'class' => 'CRM_Contact_Form_Task_Delete',
164 'result' => FALSE,
165 ),
166 );
167
26b0e4d2
SB
168 //CRM-16329, if SMS provider is configured show sms action.
169 $providersCount = CRM_SMS_BAO_Provider::activeProviderCount();
63483feb 170 if ($providersCount && CRM_Core_Permission::check('send SMS')) {
f2774867 171 self::$_tasks[self::TASK_SMS] = array(
7f82e636 172 'title' => ts('SMS - schedule/send'),
26b0e4d2
SB
173 'class' => 'CRM_Contact_Form_Task_SMS',
174 'result' => TRUE,
175 );
176 }
177
6b5f37d3 178 if (CRM_Contact_BAO_ContactType::isActive('Individual')) {
179 $label = CRM_Contact_BAO_ContactType::getLabel('individual');
180 self::$_tasks[self::INDIVIDUAL_CONTACTS] = array(
181 'title' => ts('Add relationship - to %1',
182 array(1 => $label)
183 ),
184 'class' => 'CRM_Contact_Form_Task_AddToIndividual',
185 );
186 }
187
6a488035 188 if (CRM_Contact_BAO_ContactType::isActive('Household')) {
79e4c2ad 189 $label = CRM_Contact_BAO_ContactType::getLabel('household');
2a6af255 190 self::$_tasks[self::HOUSEHOLD_CONTACTS] = array(
79e4c2ad 191 'title' => ts('Add relationship - to %1',
6a488035
TO
192 array(1 => $label)
193 ),
194 'class' => 'CRM_Contact_Form_Task_AddToHousehold',
195 );
196 }
197
198 if (CRM_Contact_BAO_ContactType::isActive('Organization')) {
79e4c2ad 199 $label = CRM_Contact_BAO_ContactType::getLabel('organization');
2a6af255 200 self::$_tasks[self::ORGANIZATION_CONTACTS] = array(
79e4c2ad 201 'title' => ts('Add relationship - to %1',
6a488035
TO
202 array(1 => $label)
203 ),
204 'class' => 'CRM_Contact_Form_Task_AddToOrganization',
205 );
206 }
207
208 if (CRM_Core_Permission::check('merge duplicate contacts')) {
2a6af255 209 self::$_tasks[self::MERGE_CONTACTS] = array(
7f82e636 210 'title' => ts('Merge contacts'),
6a488035
TO
211 'class' => 'CRM_Contact_Form_Task_Merge',
212 'result' => TRUE,
213 );
214 }
215
216 //CRM-4418, check for delete
217 if (!CRM_Core_Permission::check('delete contacts')) {
f2774867 218 unset(self::$_tasks[self::TASK_DELETE]);
6a488035
TO
219 }
220
221 //show map action only if map provider and geoprovider are set (Google doesn't need geoprovider)
222 // should fix this to be more flexible as providers are added ??
223 $config = CRM_Core_Config::singleton();
224
225 if ($config->mapProvider &&
226 ($config->mapProvider == 'Google' ||
227 ($config->mapProvider == 'OpenStreetMaps' ||
228 $config->geoProvider == 'Google'
229 )
230 )
231 ) {
2a6af255 232 self::$_tasks[self::MAP_CONTACTS] = array(
7f82e636 233 'title' => ts('Map contacts'),
6a488035
TO
234 'class' => 'CRM_Contact_Form_Task_Map',
235 'result' => FALSE,
236 );
237 }
238
239 if (CRM_Core_Permission::access('CiviEvent')) {
2a6af255 240 self::$_tasks[self::ADD_EVENT] = array(
7f82e636 241 'title' => ts('Register participants for event'),
6a488035
TO
242 'class' => 'CRM_Event_Form_Participant',
243 );
244 }
245
0083c73f
TO
246 if (CRM_Core_Permission::access('CiviMail')
247 || (CRM_Mailing_Info::workflowEnabled() && CRM_Core_Permission::check('create mailings'))
248 ) {
249 self::$_tasks[self::CREATE_MAILING] = array(
db2e53c6 250 'title' => ts('Email - schedule/send via CiviMail'),
0083c73f
TO
251 'class' => 'CRM_Mailing_Form_Task_AdhocMailing',
252 'result' => FALSE,
253 );
6a488035
TO
254 }
255
cf0adfdc 256 if (CRM_Core_Permission::access('CiviCase')) {
3e240fc3 257 self::$_tasks[self::ADD_TO_CASE] = array(
cf0adfdc
CR
258 'title' => 'Add to case as role',
259 'class' => 'CRM_Case_Form_AddToCaseAsRole',
260 'result' => FALSE,
3e240fc3 261 );
cf0adfdc 262 }
f1d7f287 263
f2774867 264 parent::tasks();
6a488035
TO
265 }
266
f2774867 267 return self::$_tasks;
6a488035
TO
268 }
269
270 /**
100fef9d 271 * Show tasks selectively based on the permission level
6a488035
TO
272 * of the user
273 *
274 * @param int $permission
f2774867
MW
275 * @param array $params
276 * bool deletedContacts: Are these tasks for operating on deleted contacts?.
6a488035 277 *
a6c01b45
CW
278 * @return array
279 * set of tasks that are valid for the user
6a488035 280 */
f2774867
MW
281 public static function permissionedTaskTitles($permission, $params = array()) {
282 if (!isset($params['deletedContacts'])) {
283 $params['deletedContacts'] = FALSE;
284 }
285 self::tasks();
6a488035 286 $tasks = array();
f2774867 287 if ($params['deletedContacts']) {
6a488035
TO
288 if (CRM_Core_Permission::check('access deleted contacts')) {
289 $tasks[self::RESTORE] = self::$_tasks[self::RESTORE]['title'];
290 if (CRM_Core_Permission::check('delete contacts')) {
291 $tasks[self::DELETE_PERMANENTLY] = self::$_tasks[self::DELETE_PERMANENTLY]['title'];
292 }
293 }
294 }
295 elseif ($permission == CRM_Core_Permission::EDIT) {
296 $tasks = self::taskTitles();
297 }
298 else {
299 $tasks = array(
f2774867
MW
300 self::TASK_EXPORT => self::$_tasks[self::TASK_EXPORT]['title'],
301 self::TASK_EMAIL => self::$_tasks[self::TASK_EMAIL]['title'],
2a6af255 302 self::LABEL_CONTACTS => self::$_tasks[self::LABEL_CONTACTS]['title'],
6a488035
TO
303 );
304
474f2a8f
MM
305 foreach ([
306 self::MAP_CONTACTS,
307 self::CREATE_MAILING,
69078420 308 self::TASK_SMS,
474f2a8f
MM
309 ] as $task) {
310 if (isset(self::$_tasks[$task]) &&
311 !empty(self::$_tasks[$task]['title'])
312 ) {
313 $tasks[$task] = self::$_tasks[$task]['title'];
314 }
6a488035
TO
315 }
316 }
6a488035 317
f2774867 318 $tasks = parent::corePermissionedTaskTitles($tasks, $permission, $params);
6a488035
TO
319 return $tasks;
320 }
321
86538308
EM
322 /**
323 * @param $value
324 *
325 * @return array
326 */
00be9182 327 public static function getTask($value) {
f2774867 328 self::tasks();
6a488035
TO
329
330 if (!CRM_Utils_Array::value($value, self::$_tasks)) {
331 // make it the print task by default
f2774867 332 $value = self::TASK_PRINT;
061ff68c 333 }
f2774867 334 return parent::getTask($value);
061ff68c 335 }
336
6a488035 337}