3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * Class to represent the actions that can be performed on a group of contacts used by the search forms.
21 class CRM_Contact_Task
extends CRM_Core_Task
{
27 HOUSEHOLD_CONTACTS
= 101,
28 ORGANIZATION_CONTACTS
= 102,
29 RECORD_CONTACTS
= 103,
35 COMMUNICATION_PREFS
= 109,
36 INDIVIDUAL_CONTACTS
= 110,
42 public static $objectType = 'contact';
44 public static function 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 'icon' => 'fa-user-plus',
53 self
::GROUP_REMOVE
=> array(
54 'title' => ts('Group - remove contacts'),
55 'class' => 'CRM_Contact_Form_Task_RemoveFromGroup',
56 'url' => 'civicrm/task/remove-from-group',
57 'icon' => 'fa-user-plus',
59 self
::TAG_ADD
=> array(
60 'title' => ts('Tag - add to contacts'),
61 'class' => 'CRM_Contact_Form_Task_AddToTag',
62 'url' => 'civicrm/task/add-to-tag',
65 self
::TAG_REMOVE
=> array(
66 'title' => ts('Tag - remove from contacts'),
67 'class' => 'CRM_Contact_Form_Task_RemoveFromTag',
68 'url' => 'civicrm/task/remove-from-tag',
71 self
::TASK_EXPORT
=> array(
72 'title' => ts('Export contacts'),
74 'CRM_Export_Form_Select',
75 'CRM_Export_Form_Map',
79 self
::TASK_EMAIL
=> array(
80 'title' => ts('Email - send now (to %1 or less)', array(
82 ->get('simple_mail_limit'),
84 'class' => 'CRM_Contact_Form_Task_Email',
86 'url' => 'civicrm/task/send-email',
87 'icon' => 'fa-paper-plane-o',
89 self
::TASK_DELETE
=> array(
90 'title' => ts('Delete contacts'),
91 'class' => 'CRM_Contact_Form_Task_Delete',
93 'url' => 'civicrm/task/delete-contact',
96 self
::RECORD_CONTACTS
=> array(
97 'title' => ts('Add activity'),
98 'class' => 'CRM_Activity_Form_Activity',
100 self
::SAVE_SEARCH
=> array(
101 'title' => ts('Group - create smart group'),
102 'class' => 'CRM_Contact_Form_Task_SaveSearch',
105 self
::SAVE_SEARCH_UPDATE
=> array(
106 'title' => ts('Group - update smart group'),
107 'class' => 'CRM_Contact_Form_Task_SaveSearch_Update',
110 self
::TASK_PRINT
=> array(
111 'title' => ts('Print selected rows'),
112 'class' => 'CRM_Contact_Form_Task_Print',
115 self
::LABEL_CONTACTS
=> array(
116 'title' => ts('Mailing labels - print'),
117 'class' => 'CRM_Contact_Form_Task_Label',
119 'url' => 'civicrm/task/make-mailing-label',
120 'icon' => 'fa-print',
122 self
::BATCH_UPDATE
=> array(
123 'title' => ts('Update multiple contacts'),
125 'CRM_Contact_Form_Task_PickProfile',
126 'CRM_Contact_Form_Task_Batch',
129 'url' => 'civicrm/task/pick-profile',
130 'icon' => 'fa-pencil',
132 self
::PDF_LETTER
=> array(
133 'title' => ts('Print/merge document'),
134 'class' => 'CRM_Contact_Form_Task_PDF',
136 'url' => 'civicrm/task/print-document',
137 'icon' => 'fa-file-pdf-o',
139 self
::EMAIL_UNHOLD
=> array(
140 'title' => ts('Email - unhold addresses'),
141 'class' => 'CRM_Contact_Form_Task_Unhold',
142 'url' => 'civicrm/task/unhold-email',
143 'icon' => 'fa-unlock',
145 self
::COMMUNICATION_PREFS
=> array(
146 'title' => ts('Communication preferences - alter'),
147 'class' => 'CRM_Contact_Form_Task_AlterPreferences',
148 'url' => 'civicrm/task/alter-contact-preference',
149 'icon' => 'fa-check-square-o',
151 self
::RESTORE
=> array(
152 'title' => ts('Restore contacts from trash'),
153 'class' => 'CRM_Contact_Form_Task_Delete',
156 self
::DELETE_PERMANENTLY
=> array(
157 'title' => ts('Delete permanently'),
158 'class' => 'CRM_Contact_Form_Task_Delete',
163 //CRM-16329, if SMS provider is configured show sms action.
164 $providersCount = CRM_SMS_BAO_Provider
::activeProviderCount();
165 if ($providersCount && CRM_Core_Permission
::check('send SMS')) {
166 self
::$_tasks[self
::TASK_SMS
] = array(
167 'title' => ts('SMS - schedule/send'),
168 'class' => 'CRM_Contact_Form_Task_SMS',
173 if (CRM_Contact_BAO_ContactType
::isActive('Individual')) {
174 $label = CRM_Contact_BAO_ContactType
::getLabel('Individual');
175 self
::$_tasks[self
::INDIVIDUAL_CONTACTS
] = array(
176 'title' => ts('Add relationship - to %1',
179 'class' => 'CRM_Contact_Form_Task_AddToIndividual',
183 if (CRM_Contact_BAO_ContactType
::isActive('Household')) {
184 $label = CRM_Contact_BAO_ContactType
::getLabel('Household');
185 self
::$_tasks[self
::HOUSEHOLD_CONTACTS
] = array(
186 'title' => ts('Add relationship - to %1',
189 'class' => 'CRM_Contact_Form_Task_AddToHousehold',
193 if (CRM_Contact_BAO_ContactType
::isActive('Organization')) {
194 $label = CRM_Contact_BAO_ContactType
::getLabel('Organization');
195 self
::$_tasks[self
::ORGANIZATION_CONTACTS
] = array(
196 'title' => ts('Add relationship - to %1',
199 'class' => 'CRM_Contact_Form_Task_AddToOrganization',
203 if (CRM_Core_Permission
::check('merge duplicate contacts')) {
204 self
::$_tasks[self
::MERGE_CONTACTS
] = array(
205 'title' => ts('Merge contacts'),
206 'class' => 'CRM_Contact_Form_Task_Merge',
211 //CRM-4418, check for delete
212 if (!CRM_Core_Permission
::check('delete contacts')) {
213 unset(self
::$_tasks[self
::TASK_DELETE
]);
216 //show map action only if map provider and geoprovider are set (Google doesn't need geoprovider)
217 // should fix this to be more flexible as providers are added ??
218 $config = CRM_Core_Config
::singleton();
220 if ($config->mapProvider
&&
221 ($config->mapProvider
== 'Google' ||
222 ($config->mapProvider
== 'OpenStreetMaps' ||
223 $config->geoProvider
== 'Google'
227 self
::$_tasks[self
::MAP_CONTACTS
] = array(
228 'title' => ts('Map contacts'),
229 'class' => 'CRM_Contact_Form_Task_Map',
234 if (CRM_Core_Permission
::access('CiviEvent')) {
235 self
::$_tasks[self
::ADD_EVENT
] = array(
236 'title' => ts('Register participants for event'),
237 'class' => 'CRM_Event_Form_Participant',
241 if (CRM_Core_Permission
::access('CiviMail')
242 ||
(CRM_Mailing_Info
::workflowEnabled() && CRM_Core_Permission
::check('create mailings'))
244 self
::$_tasks[self
::CREATE_MAILING
] = array(
245 'title' => ts('Email - schedule/send via CiviMail'),
246 'class' => 'CRM_Mailing_Form_Task_AdhocMailing',
251 if (CRM_Core_Permission
::access('CiviCase')) {
252 self
::$_tasks[self
::ADD_TO_CASE
] = array(
253 'title' => ts('Add to case as role'),
254 'class' => 'CRM_Case_Form_AddToCaseAsRole',
262 return self
::$_tasks;
266 * Show tasks selectively based on the permission level
269 * @param int $permission
270 * @param array $params
271 * bool deletedContacts: Are these tasks for operating on deleted contacts?.
274 * set of tasks that are valid for the user
276 public static function permissionedTaskTitles($permission, $params = []) {
277 if (!isset($params['deletedContacts'])) {
278 $params['deletedContacts'] = FALSE;
282 if ($params['deletedContacts']) {
283 if (CRM_Core_Permission
::check('access deleted contacts')) {
284 $tasks[self
::RESTORE
] = self
::$_tasks[self
::RESTORE
]['title'];
285 if (CRM_Core_Permission
::check('delete contacts')) {
286 $tasks[self
::DELETE_PERMANENTLY
] = self
::$_tasks[self
::DELETE_PERMANENTLY
]['title'];
290 elseif ($permission == CRM_Core_Permission
::EDIT
) {
291 $tasks = self
::taskTitles();
295 self
::TASK_EXPORT
=> self
::$_tasks[self
::TASK_EXPORT
]['title'],
296 self
::TASK_EMAIL
=> self
::$_tasks[self
::TASK_EMAIL
]['title'],
297 self
::LABEL_CONTACTS
=> self
::$_tasks[self
::LABEL_CONTACTS
]['title'],
302 self
::CREATE_MAILING
,
305 if (isset(self
::$_tasks[$task]) &&
306 !empty(self
::$_tasks[$task]['title'])
308 $tasks[$task] = self
::$_tasks[$task]['title'];
313 $tasks = parent
::corePermissionedTaskTitles($tasks, $permission, $params);
322 public static function getTask($value) {
325 if (empty(self
::$_tasks[$value])) {
326 // make it the print task by default
327 $value = self
::TASK_PRINT
;
329 return parent
::getTask($value);