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