[REF] Minor code simplification
[civicrm-core.git] / CRM / Core / SelectValues.php
CommitLineData
6a488035
TO
1<?php
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 * One place to store frequently used values in Select Elements. Note that
14 * some of the below elements will be dynamic, so we'll probably have a
15 * smart caching scheme on a per domain basis
16 *
17 * @package CRM
ca5cec67 18 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
19 * $Id$
20 *
21 */
22class CRM_Core_SelectValues {
23
14f42e31
CW
24 /**
25 * Yes/No options
26 *
27 * @return array
28 */
29 public static function boolean() {
be2fb01f 30 return [
14f42e31
CW
31 1 => ts('Yes'),
32 0 => ts('No'),
be2fb01f 33 ];
14f42e31
CW
34 }
35
6a488035 36 /**
f9e31d7f 37 * Preferred mail format.
79d7553f 38 *
76e7a76c 39 * @return array
6a488035 40 */
00be9182 41 public static function pmf() {
be2fb01f 42 return [
6795600d
CW
43 'Both' => ts('Both'),
44 'HTML' => ts('HTML'),
45 'Text' => ts('Text'),
be2fb01f 46 ];
6a488035
TO
47 }
48
49 /**
f9e31d7f 50 * Privacy options.
76e7a76c
CW
51 *
52 * @return array
6a488035 53 */
00be9182 54 public static function privacy() {
be2fb01f 55 return [
6795600d
CW
56 'do_not_phone' => ts('Do not phone'),
57 'do_not_email' => ts('Do not email'),
58 'do_not_mail' => ts('Do not mail'),
59 'do_not_sms' => ts('Do not sms'),
60 'do_not_trade' => ts('Do not trade'),
61 'is_opt_out' => ts('No bulk emails (User Opt Out)'),
be2fb01f 62 ];
6a488035
TO
63 }
64
65 /**
f9e31d7f 66 * Various pre defined contact super types.
76e7a76c
CW
67 *
68 * @return array
6a488035 69 */
00be9182 70 public static function contactType() {
6a488035
TO
71 static $contactType = NULL;
72 if (!$contactType) {
694e78fd 73 $contactType = CRM_Contact_BAO_ContactType::basicTypePairs();
6a488035
TO
74 }
75 return $contactType;
76 }
77
78 /**
f9e31d7f 79 * Various pre defined unit list.
79d7553f 80 *
76e7a76c
CW
81 * @param string $unitType
82 * @return array
6a488035 83 */
00be9182 84 public static function unitList($unitType = NULL) {
be2fb01f 85 $unitList = [
c3831ebd
EM
86 'day' => ts('day'),
87 'month' => ts('month'),
88 'year' => ts('year'),
be2fb01f 89 ];
76c8a771 90 if ($unitType === 'duration') {
6795600d 91 $unitList['lifetime'] = ts('lifetime');
6a488035
TO
92 }
93 return $unitList;
94 }
95
93bfa565 96 /**
f9e31d7f 97 * Membership type unit.
76e7a76c
CW
98 *
99 * @return array
93bfa565 100 */
2aa397bc 101 public static function membershipTypeUnitList() {
6795600d 102 return self::unitList('duration');
93bfa565 103 }
104
6a488035 105 /**
f9e31d7f 106 * Various pre defined period types.
76e7a76c
CW
107 *
108 * @return array
6a488035 109 */
00be9182 110 public static function periodType() {
be2fb01f 111 return [
c3831ebd
EM
112 'rolling' => ts('Rolling'),
113 'fixed' => ts('Fixed'),
be2fb01f 114 ];
6a488035
TO
115 }
116
bac4cd35 117 /**
f9e31d7f 118 * Various pre defined email selection methods.
76e7a76c
CW
119 *
120 * @return array
bac4cd35 121 */
00be9182 122 public static function emailSelectMethods() {
be2fb01f 123 return [
76c8a771 124 'automatic' => ts('Automatic'),
125 'location-only' => ts('Only send to email addresses assigned to the specified location'),
126 'location-prefer' => ts('Prefer email addresses assigned to the specified location'),
127 'location-exclude' => ts('Exclude email addresses assigned to the specified location'),
be2fb01f 128 ];
bac4cd35 129 }
130
6a488035 131 /**
f9e31d7f 132 * Various pre defined member visibility options.
76e7a76c
CW
133 *
134 * @return array
6a488035 135 */
00be9182 136 public static function memberVisibility() {
be2fb01f 137 return [
ab5e0c41
CW
138 'Public' => ts('Public'),
139 'Admin' => ts('Admin'),
be2fb01f 140 ];
6a488035
TO
141 }
142
dbd82592
CW
143 /**
144 * Member auto-renew options
76e7a76c
CW
145 *
146 * @return array
dbd82592
CW
147 */
148 public static function memberAutoRenew() {
be2fb01f 149 return [
dbd82592
CW
150 ts('No auto-renew option'),
151 ts('Give option, but not required'),
21dfd5f5 152 ts('Auto-renew required'),
be2fb01f 153 ];
dbd82592
CW
154 }
155
6a488035 156 /**
f9e31d7f 157 * Various pre defined event dates.
76e7a76c
CW
158 *
159 * @return array
6a488035 160 */
00be9182 161 public static function eventDate() {
be2fb01f 162 return [
c3831ebd
EM
163 'start_date' => ts('start date'),
164 'end_date' => ts('end date'),
165 'join_date' => ts('member since'),
be2fb01f 166 ];
6a488035
TO
167 }
168
6a488035 169 /**
f9e31d7f 170 * Custom form field types.
76e7a76c
CW
171 *
172 * @return array
6a488035 173 */
00be9182 174 public static function customHtmlType() {
be2fb01f 175 return [
c3831ebd
EM
176 'Text' => ts('Single-line input field (text or numeric)'),
177 'TextArea' => ts('Multi-line text box (textarea)'),
178 'Select' => ts('Drop-down (select list)'),
179 'Radio' => ts('Radio buttons'),
180 'CheckBox' => ts('Checkbox(es)'),
181 'Select Date' => ts('Select Date'),
182 'File' => ts('File'),
183 'Select State/Province' => ts('Select State/Province'),
184 'Multi-Select State/Province' => ts('Multi-Select State/Province'),
185 'Select Country' => ts('Select Country'),
186 'Multi-Select Country' => ts('Multi-Select Country'),
187 'RichTextEditor' => ts('Rich Text Editor'),
188 'Autocomplete-Select' => ts('Autocomplete-Select'),
189 'Multi-Select' => ts('Multi-Select'),
c3831ebd 190 'Link' => ts('Link'),
79dc94e4 191 'ContactReference' => ts('Autocomplete-Select'),
be2fb01f 192 ];
6a488035
TO
193 }
194
195 /**
f9e31d7f 196 * Various pre defined extensions for dynamic properties and groups.
6a488035 197 *
76e7a76c
CW
198 * @return array
199 *
6a488035 200 */
00be9182 201 public static function customGroupExtends() {
be2fb01f 202 $customGroupExtends = [
c3831ebd
EM
203 'Activity' => ts('Activities'),
204 'Relationship' => ts('Relationships'),
205 'Contribution' => ts('Contributions'),
95974e8e 206 'ContributionRecur' => ts('Recurring Contributions'),
c3831ebd
EM
207 'Group' => ts('Groups'),
208 'Membership' => ts('Memberships'),
209 'Event' => ts('Events'),
210 'Participant' => ts('Participants'),
211 'ParticipantRole' => ts('Participants (Role)'),
212 'ParticipantEventName' => ts('Participants (Event Name)'),
213 'ParticipantEventType' => ts('Participants (Event Type)'),
214 'Pledge' => ts('Pledges'),
215 'Grant' => ts('Grants'),
216 'Address' => ts('Addresses'),
217 'Campaign' => ts('Campaigns'),
be2fb01f 218 ];
c3831ebd 219 $contactTypes = self::contactType();
be2fb01f 220 $contactTypes = !empty($contactTypes) ? ['Contact' => 'Contacts'] + $contactTypes : [];
6795600d 221 $extendObjs = CRM_Core_OptionGroup::values('cg_extend_objects');
c3831ebd 222 $customGroupExtends = array_merge($contactTypes, $customGroupExtends, $extendObjs);
6a488035
TO
223 return $customGroupExtends;
224 }
225
226 /**
f9e31d7f 227 * Styles for displaying the custom data group.
6a488035 228 *
76e7a76c 229 * @return array
6a488035 230 */
00be9182 231 public static function customGroupStyle() {
be2fb01f 232 return [
c3831ebd
EM
233 'Tab' => ts('Tab'),
234 'Inline' => ts('Inline'),
235 'Tab with table' => ts('Tab with table'),
be2fb01f 236 ];
6a488035
TO
237 }
238
239 /**
f9e31d7f 240 * For displaying the uf group types.
6a488035 241 *
76e7a76c 242 * @return array
6a488035 243 */
00be9182 244 public static function ufGroupTypes() {
be2fb01f 245 $ufGroupType = [
c3831ebd
EM
246 'Profile' => ts('Standalone Form or Directory'),
247 'Search Profile' => ts('Search Views'),
be2fb01f 248 ];
c3831ebd
EM
249
250 if (CRM_Core_Config::singleton()->userSystem->supports_form_extensions) {
be2fb01f 251 $ufGroupType += [
c3831ebd
EM
252 'User Registration' => ts('Drupal User Registration'),
253 'User Account' => ts('View/Edit Drupal User Account'),
be2fb01f 254 ];
6a488035
TO
255 }
256 return $ufGroupType;
257 }
258
259 /**
f9e31d7f 260 * The status of a contact within a group.
6a488035 261 *
76e7a76c 262 * @return array
6a488035 263 */
00be9182 264 public static function groupContactStatus() {
be2fb01f 265 return [
c3831ebd
EM
266 'Added' => ts('Added'),
267 'Removed' => ts('Removed'),
268 'Pending' => ts('Pending'),
be2fb01f 269 ];
6a488035
TO
270 }
271
272 /**
f9e31d7f 273 * List of Group Types.
76e7a76c
CW
274 *
275 * @return array
6a488035 276 */
00be9182 277 public static function groupType() {
be2fb01f 278 return [
c3831ebd
EM
279 'query' => ts('Dynamic'),
280 'static' => ts('Static'),
be2fb01f 281 ];
6a488035
TO
282 }
283
284 /**
f9e31d7f 285 * Compose the parameters for a date select object.
6a488035 286 *
041ecc95 287 * @param string|null $type
76e7a76c 288 * the type of date
041ecc95 289 * @param string|null $format
76e7a76c 290 * date format (QF format)
9bf2a591
EM
291 * @param null $minOffset
292 * @param null $maxOffset
518fa0ee 293 * @param string $context
041ecc95 294 *
a6c01b45
CW
295 * @return array
296 * the date array
76c8a771 297 * @throws CRM_Core_Exception
6a488035 298 */
1285ac45 299 public static function date($type = NULL, $format = NULL, $minOffset = NULL, $maxOffset = NULL, $context = 'display') {
300 // These options are deprecated. Definitely not used in datepicker. Possibly not even in jcalendar+addDateTime.
be2fb01f 301 $date = [
6a488035
TO
302 'addEmptyOption' => TRUE,
303 'emptyOptionText' => ts('- select -'),
304 'emptyOptionValue' => '',
be2fb01f 305 ];
6a488035
TO
306
307 if ($format) {
308 $date['format'] = $format;
309 }
310 else {
311 if ($type) {
312 $dao = new CRM_Core_DAO_PreferencesDate();
313 $dao->name = $type;
314 if (!$dao->find(TRUE)) {
76c8a771 315 throw new CRM_Core_Exception('Date preferences not configured.');
6a488035 316 }
1285ac45 317 if (!$maxOffset) {
318 $maxOffset = $dao->end;
319 }
320 if (!$minOffset) {
321 $minOffset = $dao->start;
322 }
6a488035 323
6a488035 324 $date['format'] = $dao->date_format;
1285ac45 325 $date['time'] = (bool) $dao->time_format;
6a488035
TO
326 }
327
a7488080 328 if (empty($date['format'])) {
76c8a771 329 if ($context === 'Input') {
1285ac45 330 $date['format'] = Civi::settings()->get('dateInputFormat');
1285ac45 331 }
332 else {
333 $date['format'] = 'M d';
334 }
6a488035
TO
335 }
336 }
2732685b 337
ed0ca248 338 $date['smarty_view_format'] = CRM_Utils_Date::getDateFieldViewFormat($date['format']);
1285ac45 339 if (!isset($date['time'])) {
340 $date['time'] = FALSE;
341 }
6a488035 342
6795600d 343 $year = date('Y');
1285ac45 344 $date['minYear'] = $year - (int) $minOffset;
345 $date['maxYear'] = $year + (int) $maxOffset;
6a488035
TO
346 return $date;
347 }
348
349 /**
f9e31d7f 350 * Values for UF form visibility options.
6a488035 351 *
76e7a76c 352 * @return array
6a488035 353 */
00be9182 354 public static function ufVisibility() {
be2fb01f 355 return [
c3831ebd 356 'User and User Admin Only' => ts('User and User Admin Only'),
fac01cb1
DG
357 'Public Pages' => ts('Expose Publicly'),
358 'Public Pages and Listings' => ts('Expose Publicly and for Listings'),
be2fb01f 359 ];
6a488035
TO
360 }
361
93bfa565 362 /**
f9e31d7f 363 * Values for group form visibility options.
93bfa565 364 *
76e7a76c 365 * @return array
93bfa565 366 */
00be9182 367 public static function groupVisibility() {
be2fb01f 368 return [
6795600d
CW
369 'User and User Admin Only' => ts('User and User Admin Only'),
370 'Public Pages' => ts('Public Pages'),
be2fb01f 371 ];
93bfa565 372 }
373
6a488035 374 /**
f9e31d7f 375 * Different type of Mailing Components.
6a488035 376 *
76e7a76c 377 * @return array
6a488035 378 */
00be9182 379 public static function mailingComponents() {
be2fb01f 380 return [
353ffa53 381 'Header' => ts('Header'),
c3831ebd
EM
382 'Footer' => ts('Footer'),
383 'Reply' => ts('Reply Auto-responder'),
384 'OptOut' => ts('Opt-out Message'),
385 'Subscribe' => ts('Subscription Confirmation Request'),
386 'Welcome' => ts('Welcome Message'),
387 'Unsubscribe' => ts('Unsubscribe Message'),
388 'Resubscribe' => ts('Resubscribe Message'),
be2fb01f 389 ];
6a488035
TO
390 }
391
392 /**
f9e31d7f 393 * Get hours.
6a488035 394 *
76e7a76c 395 * @return array
6a488035 396 */
00be9182 397 public function getHours() {
be2fb01f 398 $hours = [];
6a488035
TO
399 for ($i = 0; $i <= 6; $i++) {
400 $hours[$i] = $i;
401 }
402 return $hours;
403 }
404
405 /**
f9e31d7f 406 * Get minutes.
6a488035 407 *
76e7a76c 408 * @return array
6a488035 409 */
00be9182 410 public function getMinutes() {
be2fb01f 411 $minutes = [];
6a488035
TO
412 for ($i = 0; $i < 60; $i = $i + 15) {
413 $minutes[$i] = $i;
414 }
415 return $minutes;
416 }
417
418 /**
f9e31d7f 419 * Get the Map Provider.
6a488035 420 *
a6c01b45
CW
421 * @return array
422 * array of map providers
6a488035 423 */
00be9182 424 public static function mapProvider() {
6a488035
TO
425 static $map = NULL;
426 if (!$map) {
be2fb01f 427 $map = ['' => '- select -'] + CRM_Utils_System::getPluginList('templates/CRM/Contact/Form/Task/Map', ".tpl");
6a488035
TO
428 }
429 return $map;
430 }
431
432 /**
f9e31d7f 433 * Get the Geocoding Providers from available plugins.
6a488035 434 *
a6c01b45
CW
435 * @return array
436 * array of geocoder providers
6a488035 437 */
00be9182 438 public static function geoProvider() {
6a488035
TO
439 static $geo = NULL;
440 if (!$geo) {
be2fb01f 441 $geo = ['' => '- select -'] + CRM_Utils_System::getPluginList('CRM/Utils/Geocode');
6a488035
TO
442 }
443 return $geo;
444 }
445
ff6f993e 446 /**
447 * Get options for displaying tax.
448 *
449 * @return array
450 *
451 * @throws \CRM_Core_Exception
452 */
453 public function taxDisplayOptions() {
454 return [
455 'Do_not_show' => ts('Do not show breakdown, only show total - i.e %1', [
456 1 => CRM_Utils_Money::format(120),
457 ]),
458 'Inclusive' => ts('Show [tax term] inclusive price - i.e. %1', [
459 1 => ts('%1 (includes [tax term] of %2)', [1 => CRM_Utils_Money::format(120), 2 => CRM_Utils_Money::format(20)]),
460 ]),
461 'Exclusive' => ts('Show [tax term] exclusive price - i.e. %1', [
462 1 => ts('%1 + %2 [tax term]', [1 => CRM_Utils_Money::format(120), 2 => CRM_Utils_Money::format(20)]),
463 ]),
464 ];
465 }
466
6a488035 467 /**
f9e31d7f 468 * Get the Address Standardization Providers from available plugins.
6a488035 469 *
a6c01b45
CW
470 * @return array
471 * array of address standardization providers
6a488035 472 */
00be9182 473 public static function addressProvider() {
6a488035
TO
474 static $addr = NULL;
475 if (!$addr) {
be2fb01f 476 $addr = array_merge(['' => '- select -'], CRM_Utils_System::getPluginList('CRM/Utils/Address', '.php', ['BatchUpdate']));
6a488035
TO
477 }
478 return $addr;
479 }
480
481 /**
f9e31d7f 482 * Different type of Mailing Tokens.
6a488035 483 *
76e7a76c 484 * @return array
6a488035 485 */
00be9182 486 public static function mailingTokens() {
be2fb01f 487 return [
c3831ebd
EM
488 '{action.unsubscribe}' => ts('Unsubscribe via email'),
489 '{action.unsubscribeUrl}' => ts('Unsubscribe via web page'),
490 '{action.resubscribe}' => ts('Resubscribe via email'),
491 '{action.resubscribeUrl}' => ts('Resubscribe via web page'),
492 '{action.optOut}' => ts('Opt out via email'),
493 '{action.optOutUrl}' => ts('Opt out via web page'),
494 '{action.forward}' => ts('Forward this email (link)'),
495 '{action.reply}' => ts('Reply to this email (link)'),
496 '{action.subscribeUrl}' => ts('Subscribe via web page'),
497 '{domain.name}' => ts('Domain name'),
498 '{domain.address}' => ts('Domain (organization) address'),
499 '{domain.phone}' => ts('Domain (organization) phone'),
500 '{domain.email}' => ts('Domain (organization) email'),
b56b8b0e 501 '{mailing.key}' => ts('Mailing key'),
c3831ebd
EM
502 '{mailing.name}' => ts('Mailing name'),
503 '{mailing.group}' => ts('Mailing group'),
504 '{mailing.viewUrl}' => ts('Mailing permalink'),
be2fb01f 505 ];
6a488035
TO
506 }
507
508 /**
f9e31d7f 509 * Different type of Activity Tokens.
6a488035 510 *
76e7a76c 511 * @return array
6a488035 512 */
00be9182 513 public static function activityTokens() {
be2fb01f 514 return [
c3831ebd
EM
515 '{activity.activity_id}' => ts('Activity ID'),
516 '{activity.subject}' => ts('Activity Subject'),
517 '{activity.details}' => ts('Activity Details'),
518 '{activity.activity_date_time}' => ts('Activity Date Time'),
be2fb01f 519 ];
6a488035
TO
520 }
521
522 /**
f9e31d7f 523 * Different type of Membership Tokens.
6a488035 524 *
76e7a76c 525 * @return array
6a488035 526 */
00be9182 527 public static function membershipTokens() {
be2fb01f 528 return [
c3831ebd
EM
529 '{membership.id}' => ts('Membership ID'),
530 '{membership.status}' => ts('Membership Status'),
531 '{membership.type}' => ts('Membership Type'),
532 '{membership.start_date}' => ts('Membership Start Date'),
533 '{membership.join_date}' => ts('Membership Join Date'),
534 '{membership.end_date}' => ts('Membership End Date'),
535 '{membership.fee}' => ts('Membership Fee'),
be2fb01f 536 ];
6a488035
TO
537 }
538
539 /**
f9e31d7f 540 * Different type of Event Tokens.
6a488035 541 *
76e7a76c 542 * @return array
6a488035 543 */
00be9182 544 public static function eventTokens() {
be2fb01f 545 return [
c3831ebd
EM
546 '{event.event_id}' => ts('Event ID'),
547 '{event.title}' => ts('Event Title'),
548 '{event.start_date}' => ts('Event Start Date'),
549 '{event.end_date}' => ts('Event End Date'),
550 '{event.event_type}' => ts('Event Type'),
551 '{event.summary}' => ts('Event Summary'),
552 '{event.contact_email}' => ts('Event Contact Email'),
553 '{event.contact_phone}' => ts('Event Contact Phone'),
554 '{event.description}' => ts('Event Description'),
555 '{event.location}' => ts('Event Location'),
556 '{event.fee_amount}' => ts('Event Fees'),
557 '{event.info_url}' => ts('Event Info URL'),
558 '{event.registration_url}' => ts('Event Registration URL'),
21dfd5f5 559 '{event.balance}' => ts('Event Balance'),
be2fb01f 560 ];
6a488035
TO
561 }
562
563 /**
f9e31d7f 564 * Different type of Event Tokens.
6a488035 565 *
76e7a76c 566 * @return array
6a488035 567 */
00be9182 568 public static function contributionTokens() {
be2fb01f 569 return array_merge([
c3831ebd
EM
570 '{contribution.contribution_id}' => ts('Contribution ID'),
571 '{contribution.total_amount}' => ts('Total Amount'),
572 '{contribution.fee_amount}' => ts('Fee Amount'),
573 '{contribution.net_amount}' => ts('Net Amount'),
c94fc35e 574 '{contribution.non_deductible_amount}' => ts('Non-deductible Amount'),
7bc6b5bb 575 '{contribution.receive_date}' => ts('Contribution Date Received'),
536f0e02 576 '{contribution.payment_instrument}' => ts('Payment Method'),
c3831ebd
EM
577 '{contribution.trxn_id}' => ts('Transaction ID'),
578 '{contribution.invoice_id}' => ts('Invoice ID'),
579 '{contribution.currency}' => ts('Currency'),
580 '{contribution.cancel_date}' => ts('Contribution Cancel Date'),
581 '{contribution.cancel_reason}' => ts('Contribution Cancel Reason'),
582 '{contribution.receipt_date}' => ts('Receipt Date'),
583 '{contribution.thankyou_date}' => ts('Thank You Date'),
584 '{contribution.contribution_source}' => ts('Contribution Source'),
585 '{contribution.amount_level}' => ts('Amount Level'),
586 //'{contribution.contribution_recur_id}' => ts('Contribution Recurring ID'),
587 //'{contribution.honor_contact_id}' => ts('Honor Contact ID'),
588 '{contribution.contribution_status_id}' => ts('Contribution Status'),
589 //'{contribution.honor_type_id}' => ts('Honor Type ID'),
590 //'{contribution.address_id}' => ts('Address ID'),
591 '{contribution.check_number}' => ts('Check Number'),
592 '{contribution.campaign}' => ts('Contribution Campaign'),
be2fb01f 593 ], CRM_Utils_Token::getCustomFieldTokens('contribution', TRUE));
6a488035
TO
594 }
595
596 /**
f9e31d7f 597 * Different type of Contact Tokens.
6a488035 598 *
76e7a76c 599 * @return array
6a488035 600 */
00be9182 601 public static function contactTokens() {
6a488035
TO
602 static $tokens = NULL;
603 if (!$tokens) {
be2fb01f
CW
604 $additionalFields = [
605 'checksum' => ['title' => ts('Checksum')],
606 'contact_id' => ['title' => ts('Internal Contact ID')],
607 ];
6a488035
TO
608 $exportFields = array_merge(CRM_Contact_BAO_Contact::exportableFields(), $additionalFields);
609
610 $values = array_merge(array_keys($exportFields));
611 unset($values[0]);
612
613 //FIXME:skipping some tokens for time being.
be2fb01f 614 $skipTokens = [
353ffa53
TO
615 'is_bulkmail',
616 'group',
617 'tag',
618 'contact_sub_type',
619 'note',
620 'is_deceased',
621 'deceased_date',
622 'legal_identifier',
623 'contact_sub_type',
624 'user_unique_id',
be2fb01f 625 ];
ea921622 626
be2fb01f 627 $customFields = CRM_Core_BAO_CustomField::getFields(['Individual', 'Address']);
cc615373 628 $legacyTokenNames = array_flip(CRM_Utils_Token::legacyContactTokens());
6a488035 629
cc615373 630 foreach ($values as $val) {
6a488035
TO
631 if (in_array($val, $skipTokens)) {
632 continue;
633 }
634 //keys for $tokens should be constant. $token Values are changed for Custom Fields. CRM-3734
72e34731
CW
635 $customFieldId = CRM_Core_BAO_CustomField::getKeyID($val);
636 if ($customFieldId) {
637 // CRM-15191 - if key is not in $customFields then the field is disabled and should be ignored
638 if (!empty($customFields[$customFieldId])) {
639 $tokens["{contact.$val}"] = $customFields[$customFieldId]['label'] . " :: " . $customFields[$customFieldId]['groupTitle'];
640 }
6a488035
TO
641 }
642 else {
cc615373
CW
643 // Support legacy token names
644 $tokenName = CRM_Utils_Array::value($val, $legacyTokenNames, $val);
645 $tokens["{contact.$tokenName}"] = $exportFields[$val]['title'];
6a488035
TO
646 }
647 }
648
9950a1c9 649 // Get all the hook tokens too
be2fb01f 650 $hookTokens = [];
6a488035 651 CRM_Utils_Hook::tokens($hookTokens);
94bf1070 652 foreach ($hookTokens as $tokenValues) {
6a488035
TO
653 foreach ($tokenValues as $key => $value) {
654 if (is_numeric($key)) {
655 $key = $value;
656 }
657 if (!preg_match('/^\{[^\}]+\}$/', $key)) {
658 $key = '{' . $key . '}';
659 }
660 if (preg_match('/^\{([^\}]+)\}$/', $value, $matches)) {
661 $value = $matches[1];
662 }
663 $tokens[$key] = $value;
664 }
665 }
666 }
667
668 return $tokens;
669 }
670
ea921622 671 /**
f9e31d7f 672 * Different type of Participant Tokens.
ea921622 673 *
76e7a76c 674 * @return array
ea921622 675 */
00be9182 676 public static function participantTokens() {
ea921622
KJ
677 static $tokens = NULL;
678 if (!$tokens) {
679 $exportFields = CRM_Event_BAO_Participant::exportableFields();
680
681 $values = array_merge(array_keys($exportFields));
682 unset($values[0]);
683
684 // skipping some tokens for time being.
be2fb01f 685 $skipTokens = [
353ffa53
TO
686 'event_id',
687 'participant_is_pay_later',
688 'participant_is_test',
689 'participant_contact_id',
690 'participant_fee_currency',
691 'participant_campaign_id',
692 'participant_status',
693 'participant_discount_name',
be2fb01f 694 ];
ea921622
KJ
695
696 $customFields = CRM_Core_BAO_CustomField::getFields('Participant');
697
698 foreach ($values as $key => $val) {
699 if (in_array($val, $skipTokens)) {
700 continue;
701 }
702 //keys for $tokens should be constant. $token Values are changed for Custom Fields. CRM-3734
703 if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($val)) {
0d8afee2 704 $tokens["{participant.$val}"] = !empty($customFields[$customFieldId]) ? $customFields[$customFieldId]['label'] . " :: " . $customFields[$customFieldId]['groupTitle'] : '';
ea921622
KJ
705 }
706 else {
707 $tokens["{participant.$val}"] = $exportFields[$val]['title'];
708 }
709 }
710 }
711 return $tokens;
712 }
713
07945b3c 714 /**
0fe4153d 715 * @param int $caseTypeId
07945b3c
CW
716 * @return array
717 */
0fe4153d 718 public static function caseTokens($caseTypeId = NULL) {
07945b3c
CW
719 static $tokens = NULL;
720 if (!$tokens) {
721 foreach (CRM_Case_BAO_Case::fields() as $field) {
722 $tokens["{case.{$field['name']}}"] = $field['title'];
723 }
724
0fe4153d 725 $customFields = CRM_Core_BAO_CustomField::getFields('Case', FALSE, FALSE, $caseTypeId);
07945b3c
CW
726 foreach ($customFields as $id => $field) {
727 $tokens["{case.custom_$id}"] = "{$field['label']} :: {$field['groupTitle']}";
728 }
729 }
730 return $tokens;
731 }
732
6a488035 733 /**
f9e31d7f 734 * CiviCRM supported date input formats.
76e7a76c
CW
735 *
736 * @return array
6a488035 737 */
00be9182 738 public static function getDatePluginInputFormats() {
86ef49af 739 return [
07faa05f
DA
740 'mm/dd/yy' => ts('mm/dd/yy (12/31/2009)'),
741 'dd/mm/yy' => ts('dd/mm/yy (31/12/2009)'),
742 'yy-mm-dd' => ts('yy-mm-dd (2009-12-31)'),
743 'dd-mm-yy' => ts('dd-mm-yy (31-12-2009)'),
744 'dd.mm.yy' => ts('dd.mm.yy (31.12.2009)'),
745 'M d, yy' => ts('M d, yy (Dec 31, 2009)'),
746 'd M yy' => ts('d M yy (31 Dec 2009)'),
747 'MM d, yy' => ts('MM d, yy (December 31, 2009)'),
748 'd MM yy' => ts('d MM yy (31 December 2009)'),
749 'DD, d MM yy' => ts('DD, d MM yy (Thursday, 31 December 2009)'),
750 'mm/dd' => ts('mm/dd (12/31)'),
751 'dd-mm' => ts('dd-mm (31-12)'),
752 'yy-mm' => ts('yy-mm (2009-12)'),
753 'M yy' => ts('M yy (Dec 2009)'),
754 'yy' => ts('yy (2009)'),
be2fb01f 755 ];
6a488035
TO
756 }
757
6a488035 758 /**
f9e31d7f 759 * Time formats.
76e7a76c
CW
760 *
761 * @return array
6a488035 762 */
00be9182 763 public static function getTimeFormats() {
be2fb01f 764 return [
6795600d 765 '1' => ts('12 Hours'),
6a488035 766 '2' => ts('24 Hours'),
be2fb01f 767 ];
6a488035
TO
768 }
769
770 /**
f9e31d7f 771 * Get numeric options.
79d7553f 772 *
76e7a76c
CW
773 * @param int $start
774 * @param int $end
6a488035 775 *
76e7a76c 776 * @return array
6a488035
TO
777 */
778 public static function getNumericOptions($start = 0, $end = 10) {
be2fb01f 779 $numericOptions = [];
6a488035 780 for ($i = $start; $i <= $end; $i++) {
2aa397bc 781 $numericOptions[$i] = $i;
6a488035
TO
782 }
783 return $numericOptions;
784 }
f38395f7
KJ
785
786 /**
f9e31d7f 787 * Barcode types.
76e7a76c
CW
788 *
789 * @return array
f38395f7 790 */
00be9182 791 public static function getBarcodeTypes() {
be2fb01f 792 return [
c3831ebd
EM
793 'barcode' => ts('Linear (1D)'),
794 'qrcode' => ts('QR code'),
be2fb01f 795 ];
f38395f7 796 }
77d0b1f8 797
798 /**
f9e31d7f 799 * Dedupe rule types.
76e7a76c
CW
800 *
801 * @return array
77d0b1f8 802 */
00be9182 803 public static function getDedupeRuleTypes() {
be2fb01f 804 return [
c3831ebd
EM
805 'Unsupervised' => ts('Unsupervised'),
806 'Supervised' => ts('Supervised'),
807 'General' => ts('General'),
be2fb01f 808 ];
77d0b1f8 809 }
f80ce889 810
811 /**
f9e31d7f 812 * Campaign group types.
76e7a76c
CW
813 *
814 * @return array
f80ce889 815 */
00be9182 816 public static function getCampaignGroupTypes() {
be2fb01f 817 return [
c3831ebd
EM
818 'Include' => ts('Include'),
819 'Exclude' => ts('Exclude'),
be2fb01f 820 ];
f80ce889 821 }
822
823 /**
f9e31d7f 824 * Subscription history method.
76e7a76c
CW
825 *
826 * @return array
f80ce889 827 */
00be9182 828 public static function getSubscriptionHistoryMethods() {
be2fb01f 829 return [
c3831ebd
EM
830 'Admin' => ts('Admin'),
831 'Email' => ts('Email'),
832 'Web' => ts('Web'),
833 'API' => ts('API'),
be2fb01f 834 ];
f80ce889 835 }
836
837 /**
f9e31d7f 838 * Premium units.
76e7a76c
CW
839 *
840 * @return array
f80ce889 841 */
00be9182 842 public static function getPremiumUnits() {
be2fb01f 843 return [
c3831ebd
EM
844 'day' => ts('Day'),
845 'week' => ts('Week'),
846 'month' => ts('Month'),
847 'year' => ts('Year'),
be2fb01f 848 ];
f80ce889 849 }
56251ea7 850
851 /**
f9e31d7f 852 * Extension types.
76e7a76c
CW
853 *
854 * @return array
56251ea7 855 */
00be9182 856 public static function getExtensionTypes() {
be2fb01f 857 return [
c3831ebd
EM
858 'payment' => ts('Payment'),
859 'search' => ts('Search'),
860 'report' => ts('Report'),
861 'module' => ts('Module'),
862 'sms' => ts('SMS'),
be2fb01f 863 ];
56251ea7 864 }
865
866 /**
f9e31d7f 867 * Job frequency.
76e7a76c
CW
868 *
869 * @return array
56251ea7 870 */
00be9182 871 public static function getJobFrequency() {
be2fb01f 872 return [
bda41fcb
DRJ
873 // CRM-17669
874 'Yearly' => ts('Yearly'),
875 'Quarter' => ts('Quarterly'),
876 'Monthly' => ts('Monthly'),
877 'Weekly' => ts('Weekly'),
878
c3831ebd
EM
879 'Daily' => ts('Daily'),
880 'Hourly' => ts('Hourly'),
881 'Always' => ts('Every time cron job is run'),
be2fb01f 882 ];
56251ea7 883 }
e204d358 884
885 /**
f9e31d7f 886 * Search builder operators.
76e7a76c
CW
887 *
888 * @return array
e204d358 889 */
76c8a771 890 public static function getSearchBuilderOperators() {
80beace7 891 return [
c3831ebd
EM
892 '=' => '=',
893 '!=' => '≠',
894 '>' => '>',
895 '<' => '<',
896 '>=' => '≥',
897 '<=' => '≤',
898 'IN' => ts('In'),
afa0b07c 899 'NOT IN' => ts('Not In'),
c3831ebd 900 'LIKE' => ts('Like'),
afa0b07c 901 'NOT LIKE' => ts('Not Like'),
c3831ebd
EM
902 'RLIKE' => ts('Regex'),
903 'IS EMPTY' => ts('Is Empty'),
904 'IS NOT EMPTY' => ts('Not Empty'),
905 'IS NULL' => ts('Is Null'),
906 'IS NOT NULL' => ts('Not Null'),
80beace7 907 ];
e204d358 908 }
909
910 /**
f9e31d7f 911 * Profile group types.
e204d358 912 *
76e7a76c 913 * @return array
e204d358 914 */
00be9182 915 public static function getProfileGroupType() {
be2fb01f 916 $profileGroupType = [
c3831ebd
EM
917 'Activity' => ts('Activities'),
918 'Contribution' => ts('Contributions'),
919 'Membership' => ts('Memberships'),
920 'Participant' => ts('Participants'),
be2fb01f 921 ];
c3831ebd 922 $contactTypes = self::contactType();
be2fb01f 923 $contactTypes = !empty($contactTypes) ? ['Contact' => 'Contacts'] + $contactTypes : [];
481a74f4 924 $profileGroupType = array_merge($contactTypes, $profileGroupType);
c3831ebd 925
e204d358 926 return $profileGroupType;
927 }
928
e204d358 929 /**
f9e31d7f 930 * Word replacement match type.
76e7a76c
CW
931 *
932 * @return array
e204d358 933 */
00be9182 934 public static function getWordReplacementMatchType() {
be2fb01f 935 return [
353ffa53
TO
936 'exactMatch' => ts('Exact Match'),
937 'wildcardMatch' => ts('Wildcard Match'),
be2fb01f 938 ];
e204d358 939 }
940
71a707c3 941 /**
f9e31d7f 942 * Mailing group types.
76e7a76c
CW
943 *
944 * @return array
71a707c3 945 */
00be9182 946 public static function getMailingGroupTypes() {
be2fb01f 947 return [
c3831ebd
EM
948 'Include' => ts('Include'),
949 'Exclude' => ts('Exclude'),
950 'Base' => ts('Base'),
be2fb01f 951 ];
71a707c3 952 }
953
954 /**
f9e31d7f 955 * Mailing Job Status.
76e7a76c
CW
956 *
957 * @return array
71a707c3 958 */
00be9182 959 public static function getMailingJobStatus() {
be2fb01f 960 return [
c3831ebd
EM
961 'Scheduled' => ts('Scheduled'),
962 'Running' => ts('Running'),
963 'Complete' => ts('Complete'),
964 'Paused' => ts('Paused'),
965 'Canceled' => ts('Canceled'),
be2fb01f 966 ];
71a707c3 967 }
968
76e7a76c
CW
969 /**
970 * @return array
971 */
00be9182 972 public static function billingMode() {
be2fb01f 973 return [
280f1b05
CW
974 CRM_Core_Payment::BILLING_MODE_FORM => 'form',
975 CRM_Core_Payment::BILLING_MODE_BUTTON => 'button',
976 CRM_Core_Payment::BILLING_MODE_NOTIFY => 'notify',
be2fb01f 977 ];
280f1b05
CW
978 }
979
367b5943 980 /**
981 * @return array
982 */
983 public static function contributeMode() {
be2fb01f 984 return [
367b5943 985 CRM_Core_Payment::BILLING_MODE_FORM => 'direct',
986 CRM_Core_Payment::BILLING_MODE_BUTTON => 'directIPN',
987 CRM_Core_Payment::BILLING_MODE_NOTIFY => 'notify',
be2fb01f 988 ];
367b5943 989 }
990
9775f926 991 /**
f9e31d7f 992 * Frequency unit for schedule reminders.
76e7a76c 993 *
8fe4b69f
CW
994 * @param int $count
995 * For pluralization
76e7a76c 996 * @return array
9775f926 997 */
8fe4b69f
CW
998 public static function getRecurringFrequencyUnits($count = 1) {
999 // @todo this used to refer to the 'recur_frequency_unit' option_values which
1000 // is for recurring payments and probably not good to re-use for recurring entities.
1001 // If something other than a hard-coded list is desired, add a new option_group.
be2fb01f
CW
1002 return [
1003 'hour' => ts('hour', ['plural' => 'hours', 'count' => $count]),
1004 'day' => ts('day', ['plural' => 'days', 'count' => $count]),
1005 'week' => ts('week', ['plural' => 'weeks', 'count' => $count]),
1006 'month' => ts('month', ['plural' => 'months', 'count' => $count]),
1007 'year' => ts('year', ['plural' => 'years', 'count' => $count]),
1008 ];
9775f926 1009 }
96025800 1010
7537a84b
J
1011 /**
1012 * Relative Date Terms.
1013 *
1014 * @return array
1015 */
1016 public static function getRelativeDateTerms() {
be2fb01f 1017 return [
7537a84b
J
1018 'previous' => ts('Previous'),
1019 'previous_2' => ts('Previous 2'),
1020 'previous_before' => ts('Prior to Previous'),
1021 'before_previous' => ts('All Prior to Previous'),
1022 'earlier' => ts('To End of Previous'),
1023 'greater_previous' => ts('From End of Previous'),
1024 'greater' => ts('From Start Of Current'),
1025 'current' => ts('Current'),
1026 'ending_3' => ts('Last 3'),
1027 'ending_2' => ts('Last 2'),
1028 'ending' => ts('Last'),
1029 'this' => ts('This'),
1030 'starting' => ts('Upcoming'),
1031 'less' => ts('To End of'),
1032 'next' => ts('Next'),
be2fb01f 1033 ];
7537a84b
J
1034 }
1035
1036 /**
1037 * Relative Date Units.
1038 *
1039 * @return array
1040 */
1041 public static function getRelativeDateUnits() {
be2fb01f 1042 return [
7537a84b
J
1043 'year' => ts('Years'),
1044 'fiscal_year' => ts('Fiscal Years'),
1045 'quarter' => ts('Quarters'),
1046 'month' => ts('Months'),
1047 'week' => ts('Weeks'),
1048 'day' => ts('Days'),
be2fb01f 1049 ];
7537a84b
J
1050 }
1051
0aeb5a1e
CW
1052 /**
1053 * Exportable document formats.
1054 *
1055 * @return array
1056 */
1057 public static function documentFormat() {
be2fb01f 1058 return [
0aeb5a1e
CW
1059 'pdf' => ts('Portable Document Format (.pdf)'),
1060 'docx' => ts('MS Word (.docx)'),
1061 'odt' => ts('Open Office (.odt)'),
1062 'html' => ts('Webpage (.html)'),
be2fb01f 1063 ];
0aeb5a1e
CW
1064 }
1065
90a73810 1066 /**
1067 * Application type of document.
1068 *
1069 * @return array
1070 */
1071 public static function documentApplicationType() {
be2fb01f 1072 return [
90a73810 1073 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
1074 'odt' => 'application/vnd.oasis.opendocument.text',
be2fb01f 1075 ];
90a73810 1076 }
1077
1cd7479e 1078 /**
1079 * Activity Text options.
1080 *
1081 * @return array
1082 */
1083 public static function activityTextOptions() {
be2fb01f 1084 return [
1cd7479e 1085 2 => ts('Details Only'),
1086 3 => ts('Subject Only'),
1087 6 => ts('Both'),
be2fb01f 1088 ];
1cd7479e 1089 }
1090
f871c3a9
AS
1091 /**
1092 * Relationship permissions
1093 *
1094 * @return array
1095 */
1096 public static function getPermissionedRelationshipOptions() {
be2fb01f 1097 return [
f871c3a9
AS
1098 CRM_Contact_BAO_Relationship::NONE => ts('None'),
1099 CRM_Contact_BAO_Relationship::VIEW => ts('View only'),
1100 CRM_Contact_BAO_Relationship::EDIT => ts('View and update'),
be2fb01f 1101 ];
f871c3a9
AS
1102 }
1103
f5e8cb7b 1104 /**
1105 * Get option values for dashboard entries (used for 'how many events to display on dashboard').
1106 *
1107 * @return array
1108 * Dashboard entries options - in practice [-1 => 'Show All', 10 => 10, 20 => 20, ... 100 => 100].
1109 */
1110 public static function getDashboardEntriesCount() {
1111 $optionValues = [];
1112 $optionValues[-1] = ts('show all');
1113 for ($i = 10; $i <= 100; $i += 10) {
1114 $optionValues[$i] = $i;
1115 }
1116 return $optionValues;
1117 }
1118
4235341b
CW
1119 /**
1120 * Dropdown options for quicksearch in the menu
1121 *
1122 * @return array
76c8a771 1123 * @throws \CiviCRM_API3_Exception
4235341b
CW
1124 */
1125 public static function quicksearchOptions() {
be2fb01f 1126 $includeEmail = civicrm_api3('setting', 'getvalue', ['name' => 'includeEmailInName', 'group' => 'Search Preferences']);
4235341b
CW
1127 $options = [
1128 'sort_name' => $includeEmail ? ts('Name/Email') : ts('Name'),
1129 'contact_id' => ts('Contact ID'),
1130 'external_identifier' => ts('External ID'),
1131 'first_name' => ts('First Name'),
1132 'last_name' => ts('Last Name'),
1133 'email' => ts('Email'),
1134 'phone_numeric' => ts('Phone'),
1135 'street_address' => ts('Street Address'),
1136 'city' => ts('City'),
1137 'postal_code' => ts('Postal Code'),
1138 'job_title' => ts('Job Title'),
1139 ];
1140 $custom = civicrm_api3('CustomField', 'get', [
1f8ac3d2
CW
1141 'return' => ['name', 'label', 'custom_group_id.title'],
1142 'custom_group_id.extends' => ['IN' => ['Contact', 'Individual', 'Organization', 'Household']],
1143 'data_type' => ['NOT IN' => ['ContactReference', 'Date', 'File']],
4235341b
CW
1144 'custom_group_id.is_active' => 1,
1145 'is_active' => 1,
1146 'is_searchable' => 1,
d44e024b 1147 'options' => ['sort' => ['custom_group_id.weight', 'weight'], 'limit' => 0],
4235341b
CW
1148 ]);
1149 foreach ($custom['values'] as $field) {
1150 $options['custom_' . $field['name']] = $field['custom_group_id.title'] . ': ' . $field['label'];
1151 }
1152 return $options;
1153 }
1154
281db812 1155 /**
1156 * Get components (translated for display.
1157 *
1158 * @return array
1159 *
1160 * @throws \Exception
1161 */
1162 public static function getComponentSelectValues() {
1163 $ret = [];
1164 $components = CRM_Core_Component::getComponents();
1165 foreach ($components as $name => $object) {
1166 $ret[$name] = $object->info['translatedName'];
1167 }
1168
1169 return $ret;
1170 }
1171
6a488035 1172}