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