Extract getMungedFieldName
[civicrm-core.git] / CRM / Contact / Task.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2018
32 */
33
34 /**
35 * Class to represent the actions that can be performed on a group of contacts used by the search forms.
36 */
37 class CRM_Contact_Task extends CRM_Core_Task {
38
39 const
40 // Contact tasks
41 HOUSEHOLD_CONTACTS = 101,
42 ORGANIZATION_CONTACTS = 102,
43 RECORD_CONTACTS = 103,
44 MAP_CONTACTS = 104,
45 ADD_EVENT = 105,
46 MERGE_CONTACTS = 106,
47 EMAIL_UNHOLD = 107,
48 RESTORE = 108,
49 COMMUNICATION_PREFS = 109,
50 INDIVIDUAL_CONTACTS = 110,
51 ADD_TO_CASE = 111;
52
53 static $objectType = 'contact';
54
55 public static function tasks() {
56 if (!self::$_tasks) {
57 self::$_tasks = array(
58 self::GROUP_ADD => array(
59 'title' => ts('Group - add contacts'),
60 'class' => 'CRM_Contact_Form_Task_AddToGroup',
61 'url' => 'civicrm/task/add-to-group',
62 ),
63 self::GROUP_REMOVE => array(
64 'title' => ts('Group - remove contacts'),
65 'class' => 'CRM_Contact_Form_Task_RemoveFromGroup',
66 'url' => 'civicrm/task/remove-from-group',
67 ),
68 self::TAG_ADD => array(
69 'title' => ts('Tag - add to contacts'),
70 'class' => 'CRM_Contact_Form_Task_AddToTag',
71 'url' => 'civicrm/task/add-to-tag',
72 ),
73 self::TAG_REMOVE => array(
74 'title' => ts('Tag - remove from contacts'),
75 'class' => 'CRM_Contact_Form_Task_RemoveFromTag',
76 'url' => 'civicrm/task/remove-from-tag',
77 ),
78 self::TASK_EXPORT => array(
79 'title' => ts('Export contacts'),
80 'class' => array(
81 'CRM_Export_Form_Select',
82 'CRM_Export_Form_Map',
83 ),
84 'result' => FALSE,
85 ),
86 self::TASK_EMAIL => array(
87 'title' => ts('Email - send now (to %1 or less)', array(
88 1 => Civi::settings()
89 ->get('simple_mail_limit'),
90 )),
91 'class' => 'CRM_Contact_Form_Task_Email',
92 'result' => TRUE,
93 'url' => 'civicrm/task/send-email',
94 ),
95 self::TASK_DELETE => array(
96 'title' => ts('Delete contacts'),
97 'class' => 'CRM_Contact_Form_Task_Delete',
98 'result' => FALSE,
99 'url' => 'civicrm/task/delete-contact',
100 ),
101 self::RECORD_CONTACTS => array(
102 'title' => ts('Add activity'),
103 'class' => 'CRM_Activity_Form_Activity',
104 ),
105 self::SAVE_SEARCH => array(
106 'title' => ts('Group - create smart group'),
107 'class' => 'CRM_Contact_Form_Task_SaveSearch',
108 'result' => TRUE,
109 ),
110 self::SAVE_SEARCH_UPDATE => array(
111 'title' => ts('Group - update smart group'),
112 'class' => 'CRM_Contact_Form_Task_SaveSearch_Update',
113 'result' => TRUE,
114 ),
115 self::TASK_PRINT => array(
116 'title' => ts('Print selected rows'),
117 'class' => 'CRM_Contact_Form_Task_Print',
118 'result' => FALSE,
119 ),
120 self::LABEL_CONTACTS => array(
121 'title' => ts('Mailing labels - print'),
122 'class' => 'CRM_Contact_Form_Task_Label',
123 'result' => TRUE,
124 'url' => 'civicrm/task/make-mailing-label',
125 ),
126 self::BATCH_UPDATE => array(
127 'title' => ts('Update multiple contacts'),
128 'class' => array(
129 'CRM_Contact_Form_Task_PickProfile',
130 'CRM_Contact_Form_Task_Batch',
131 ),
132 'result' => TRUE,
133 'url' => 'civicrm/task/pick-profile',
134 ),
135 self::PDF_LETTER => array(
136 'title' => ts('Print/merge document'),
137 'class' => 'CRM_Contact_Form_Task_PDF',
138 'result' => TRUE,
139 'url' => 'civicrm/task/print-document',
140 ),
141 self::EMAIL_UNHOLD => array(
142 'title' => ts('Email - unhold addresses'),
143 'class' => 'CRM_Contact_Form_Task_Unhold',
144 'url' => 'civicrm/task/unhold-email',
145 ),
146 self::COMMUNICATION_PREFS => array(
147 'title' => ts('Communication preferences - alter'),
148 'class' => 'CRM_Contact_Form_Task_AlterPreferences',
149 'url' => 'civicrm/task/alter-contact-preference',
150 ),
151 self::RESTORE => array(
152 'title' => ts('Restore contacts from trash'),
153 'class' => 'CRM_Contact_Form_Task_Delete',
154 'result' => FALSE,
155 ),
156 self::DELETE_PERMANENTLY => array(
157 'title' => ts('Delete permanently'),
158 'class' => 'CRM_Contact_Form_Task_Delete',
159 'result' => FALSE,
160 ),
161 );
162
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',
169 'result' => TRUE,
170 );
171 }
172
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',
177 array(1 => $label)
178 ),
179 'class' => 'CRM_Contact_Form_Task_AddToIndividual',
180 );
181 }
182
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',
187 array(1 => $label)
188 ),
189 'class' => 'CRM_Contact_Form_Task_AddToHousehold',
190 );
191 }
192
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',
197 array(1 => $label)
198 ),
199 'class' => 'CRM_Contact_Form_Task_AddToOrganization',
200 );
201 }
202
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',
207 'result' => TRUE,
208 );
209 }
210
211 //CRM-4418, check for delete
212 if (!CRM_Core_Permission::check('delete contacts')) {
213 unset(self::$_tasks[self::TASK_DELETE]);
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 ) {
227 self::$_tasks[self::MAP_CONTACTS] = array(
228 'title' => ts('Map contacts'),
229 'class' => 'CRM_Contact_Form_Task_Map',
230 'result' => FALSE,
231 );
232 }
233
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',
238 );
239 }
240
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(
245 'title' => ts('Email - schedule/send via CiviMail'),
246 'class' => 'CRM_Mailing_Form_Task_AdhocMailing',
247 'result' => FALSE,
248 );
249 }
250
251 if (CRM_Core_Permission::access('CiviCase')) {
252 self::$_tasks[self::ADD_TO_CASE] = array(
253 'title' => 'Add to case as role',
254 'class' => 'CRM_Case_Form_AddToCaseAsRole',
255 'result' => FALSE,
256 );
257 }
258
259 parent::tasks();
260 }
261
262 return self::$_tasks;
263 }
264
265 /**
266 * Show tasks selectively based on the permission level
267 * of the user
268 *
269 * @param int $permission
270 * @param array $params
271 * bool deletedContacts: Are these tasks for operating on deleted contacts?.
272 *
273 * @return array
274 * set of tasks that are valid for the user
275 */
276 public static function permissionedTaskTitles($permission, $params = array()) {
277 if (!isset($params['deletedContacts'])) {
278 $params['deletedContacts'] = FALSE;
279 }
280 self::tasks();
281 $tasks = array();
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'];
287 }
288 }
289 }
290 elseif ($permission == CRM_Core_Permission::EDIT) {
291 $tasks = self::taskTitles();
292 }
293 else {
294 $tasks = array(
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'],
298 );
299
300 foreach ([
301 self::MAP_CONTACTS,
302 self::CREATE_MAILING,
303 self::TASK_SMS
304 ] as $task) {
305 if (isset(self::$_tasks[$task]) &&
306 !empty(self::$_tasks[$task]['title'])
307 ) {
308 $tasks[$task] = self::$_tasks[$task]['title'];
309 }
310 }
311 }
312
313 $tasks = parent::corePermissionedTaskTitles($tasks, $permission, $params);
314 return $tasks;
315 }
316
317 /**
318 * @param $value
319 *
320 * @return array
321 */
322 public static function getTask($value) {
323 self::tasks();
324
325 if (!CRM_Utils_Array::value($value, self::$_tasks)) {
326 // make it the print task by default
327 $value = self::TASK_PRINT;
328 }
329 return parent::getTask($value);
330 }
331
332 }