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