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