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',
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',
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',
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',
67 self
::TASK_EXPORT
=> array(
68 'title' => ts('Export contacts'),
70 'CRM_Export_Form_Select',
71 'CRM_Export_Form_Map',
75 self
::TASK_EMAIL
=> array(
76 'title' => ts('Email - send now (to %1 or less)', array(
78 ->get('simple_mail_limit'),
80 'class' => 'CRM_Contact_Form_Task_Email',
82 'url' => 'civicrm/task/send-email',
84 self
::TASK_DELETE
=> array(
85 'title' => ts('Delete contacts'),
86 'class' => 'CRM_Contact_Form_Task_Delete',
88 'url' => 'civicrm/task/delete-contact',
90 self
::RECORD_CONTACTS
=> array(
91 'title' => ts('Add activity'),
92 'class' => 'CRM_Activity_Form_Activity',
94 self
::SAVE_SEARCH
=> array(
95 'title' => ts('Group - create smart group'),
96 'class' => 'CRM_Contact_Form_Task_SaveSearch',
99 self
::SAVE_SEARCH_UPDATE
=> array(
100 'title' => ts('Group - update smart group'),
101 'class' => 'CRM_Contact_Form_Task_SaveSearch_Update',
104 self
::TASK_PRINT
=> array(
105 'title' => ts('Print selected rows'),
106 'class' => 'CRM_Contact_Form_Task_Print',
109 self
::LABEL_CONTACTS
=> array(
110 'title' => ts('Mailing labels - print'),
111 'class' => 'CRM_Contact_Form_Task_Label',
113 'url' => 'civicrm/task/make-mailing-label',
115 self
::BATCH_UPDATE
=> array(
116 'title' => ts('Update multiple contacts'),
118 'CRM_Contact_Form_Task_PickProfile',
119 'CRM_Contact_Form_Task_Batch',
122 'url' => 'civicrm/task/pick-profile',
124 self
::PDF_LETTER
=> array(
125 'title' => ts('Print/merge document'),
126 'class' => 'CRM_Contact_Form_Task_PDF',
128 'url' => 'civicrm/task/print-document',
130 self
::EMAIL_UNHOLD
=> array(
131 'title' => ts('Email - unhold addresses'),
132 'class' => 'CRM_Contact_Form_Task_Unhold',
133 'url' => 'civicrm/task/unhold-email',
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',
140 self
::RESTORE
=> array(
141 'title' => ts('Restore contacts from trash'),
142 'class' => 'CRM_Contact_Form_Task_Delete',
145 self
::DELETE_PERMANENTLY
=> array(
146 'title' => ts('Delete permanently'),
147 'class' => 'CRM_Contact_Form_Task_Delete',
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',
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',
168 'class' => 'CRM_Contact_Form_Task_AddToIndividual',
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',
178 'class' => 'CRM_Contact_Form_Task_AddToHousehold',
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',
188 'class' => 'CRM_Contact_Form_Task_AddToOrganization',
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',
200 //CRM-4418, check for delete
201 if (!CRM_Core_Permission
::check('delete contacts')) {
202 unset(self
::$_tasks[self
::TASK_DELETE
]);
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();
209 if ($config->mapProvider
&&
210 ($config->mapProvider
== 'Google' ||
211 ($config->mapProvider
== 'OpenStreetMaps' ||
212 $config->geoProvider
== 'Google'
216 self
::$_tasks[self
::MAP_CONTACTS
] = array(
217 'title' => ts('Map contacts'),
218 'class' => 'CRM_Contact_Form_Task_Map',
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',
230 if (CRM_Core_Permission
::access('CiviMail')
231 ||
(CRM_Mailing_Info
::workflowEnabled() && CRM_Core_Permission
::check('create mailings'))
233 self
::$_tasks[self
::CREATE_MAILING
] = array(
234 'title' => ts('Email - schedule/send via CiviMail'),
235 'class' => 'CRM_Mailing_Form_Task_AdhocMailing',
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',
251 return self
::$_tasks;
255 * Show tasks selectively based on the permission level
258 * @param int $permission
259 * @param array $params
260 * bool deletedContacts: Are these tasks for operating on deleted contacts?.
263 * set of tasks that are valid for the user
265 public static function permissionedTaskTitles($permission, $params = array()) {
266 if (!isset($params['deletedContacts'])) {
267 $params['deletedContacts'] = FALSE;
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'];
279 elseif ($permission == CRM_Core_Permission
::EDIT
) {
280 $tasks = self
::taskTitles();
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'],
291 self
::CREATE_MAILING
,
294 if (isset(self
::$_tasks[$task]) &&
295 !empty(self
::$_tasks[$task]['title'])
297 $tasks[$task] = self
::$_tasks[$task]['title'];
302 $tasks = parent
::corePermissionedTaskTitles($tasks, $permission, $params);
311 public static function getTask($value) {
314 if (!CRM_Utils_Array
::value($value, self
::$_tasks)) {
315 // make it the print task by default
316 $value = self
::TASK_PRINT
;
318 return parent
::getTask($value);