Merge pull request #21490 from eileenmcnaughton/case_email
[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
3c78698e
EM
497 *
498 * @deprecated
cb9b8644
SL
499 */
500 public static function domainTokens() {
3c78698e
EM
501 $tokenProcessor = new TokenProcessor(Civi::dispatcher(), []);
502 return $tokenProcessor->listTokens();
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 */
eac0a5bf 524 public static function membershipTokens(): array {
be2fb01f 525 return [
c3831ebd 526 '{membership.id}' => ts('Membership ID'),
eac0a5bf
EM
527 '{membership.status_id:label}' => ts('Membership Status'),
528 '{membership.membership_type_id:label}' => ts('Membership Type'),
c3831ebd
EM
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 /**
1ee56218 561 * Different type of Contribution Tokens.
6a488035 562 *
3c78698e
EM
563 * @deprecated
564 *
76e7a76c 565 * @return array
6a488035 566 */
7ddd4af7 567 public static function contributionTokens(): array {
1ee56218 568 $tokenProcessor = new TokenProcessor(Civi::dispatcher(), ['schema' => ['contributionId']]);
3c78698e
EM
569 $allTokens = $tokenProcessor->listTokens();
570 foreach (array_keys($allTokens) as $token) {
571 if (strpos($token, '{domain.') === 0) {
572 unset($allTokens[$token]);
573 }
574 }
575 return $allTokens;
6a488035
TO
576 }
577
578 /**
f9e31d7f 579 * Different type of Contact Tokens.
6a488035 580 *
3c78698e
EM
581 * @deprecated
582 *
76e7a76c 583 * @return array
6a488035 584 */
fb9c59fe
EM
585 public static function contactTokens(): array {
586 $tokenProcessor = new TokenProcessor(Civi::dispatcher(), ['schema' => ['contactId']]);
3c78698e
EM
587 $allTokens = $tokenProcessor->listTokens();
588 foreach (array_keys($allTokens) as $token) {
589 if (strpos($token, '{domain.') === 0) {
590 unset($allTokens[$token]);
591 }
592 }
593 return $allTokens;
6a488035
TO
594 }
595
ea921622 596 /**
f9e31d7f 597 * Different type of Participant Tokens.
ea921622 598 *
76e7a76c 599 * @return array
ea921622 600 */
35571079
EM
601 public static function participantTokens(): array {
602 $tokens = [
603 '{participant.participant_status_id}' => 'Status ID',
604 '{participant.participant_role_id}' => 'Participant Role (ID)',
605 '{participant.participant_register_date}' => 'Register date',
606 '{participant.participant_source}' => 'Participant Source',
607 '{participant.participant_fee_level}' => 'Fee level',
608 '{participant.participant_fee_amount}' => 'Fee Amount',
609 '{participant.participant_registered_by_id}' => 'Registered By Participant ID',
610 '{participant.transferred_to_contact_id}' => 'Transferred to Contact ID',
611 '{participant.participant_role}' => 'Participant Role (label)',
612 '{participant.event_title}' => 'Event Title',
613 '{participant.event_start_date}' => 'Event Start Date',
614 '{participant.event_end_date}' => 'Event End Date',
615 '{participant.fee_label}' => 'Fee Label',
616 '{participant.default_role_id}' => 'Default Role',
617 '{participant.template_title}' => 'Event Template Title',
618 '{participant.currency}' => 'Currency',
619 '{participant.participant_note}' => 'Participant Note',
620 ];
621 $customFields = CRM_Core_BAO_CustomField::getFields('Participant');
ea921622 622
35571079
EM
623 foreach ($customFields as $customField) {
624 $tokens['{participant.custom_' . $customField['id'] . '}'] = $customField['label'] . " :: " . $customField['groupTitle'];
ea921622 625 }
35571079 626
ea921622
KJ
627 return $tokens;
628 }
629
07945b3c 630 /**
0fe4153d 631 * @param int $caseTypeId
07945b3c
CW
632 * @return array
633 */
0fe4153d 634 public static function caseTokens($caseTypeId = NULL) {
07945b3c
CW
635 static $tokens = NULL;
636 if (!$tokens) {
2f5c0408
EM
637 $tokens = [
638 '{case.id}' => 'Case ID',
639 '{case.case_type_id:label}' => 'Case Type',
640 '{case.subject}' => 'Case Subject',
641 '{case.start_date}' => 'Case Start Date',
642 '{case.end_date}' => 'Case End Date',
643 '{case.details}' => 'Details',
644 '{case.status_id:label}' => 'Case Status',
78ffc4d7 645 '{case.is_deleted:label}' => 'Case is in the Trash',
2f5c0408
EM
646 '{case.created_date}' => 'Created Date',
647 '{case.modified_date}' => 'Modified Date',
648 ];
07945b3c 649
0fe4153d 650 $customFields = CRM_Core_BAO_CustomField::getFields('Case', FALSE, FALSE, $caseTypeId);
07945b3c
CW
651 foreach ($customFields as $id => $field) {
652 $tokens["{case.custom_$id}"] = "{$field['label']} :: {$field['groupTitle']}";
653 }
654 }
655 return $tokens;
656 }
657
6a488035 658 /**
f9e31d7f 659 * CiviCRM supported date input formats.
76e7a76c
CW
660 *
661 * @return array
6a488035 662 */
00be9182 663 public static function getDatePluginInputFormats() {
86ef49af 664 return [
07faa05f
DA
665 'mm/dd/yy' => ts('mm/dd/yy (12/31/2009)'),
666 'dd/mm/yy' => ts('dd/mm/yy (31/12/2009)'),
667 'yy-mm-dd' => ts('yy-mm-dd (2009-12-31)'),
668 'dd-mm-yy' => ts('dd-mm-yy (31-12-2009)'),
669 'dd.mm.yy' => ts('dd.mm.yy (31.12.2009)'),
670 'M d, yy' => ts('M d, yy (Dec 31, 2009)'),
671 'd M yy' => ts('d M yy (31 Dec 2009)'),
672 'MM d, yy' => ts('MM d, yy (December 31, 2009)'),
673 'd MM yy' => ts('d MM yy (31 December 2009)'),
674 'DD, d MM yy' => ts('DD, d MM yy (Thursday, 31 December 2009)'),
675 'mm/dd' => ts('mm/dd (12/31)'),
676 'dd-mm' => ts('dd-mm (31-12)'),
677 'yy-mm' => ts('yy-mm (2009-12)'),
678 'M yy' => ts('M yy (Dec 2009)'),
679 'yy' => ts('yy (2009)'),
be2fb01f 680 ];
6a488035
TO
681 }
682
6a488035 683 /**
f9e31d7f 684 * Time formats.
76e7a76c
CW
685 *
686 * @return array
6a488035 687 */
00be9182 688 public static function getTimeFormats() {
be2fb01f 689 return [
6795600d 690 '1' => ts('12 Hours'),
6a488035 691 '2' => ts('24 Hours'),
be2fb01f 692 ];
6a488035
TO
693 }
694
695 /**
f9e31d7f 696 * Get numeric options.
79d7553f 697 *
76e7a76c
CW
698 * @param int $start
699 * @param int $end
6a488035 700 *
76e7a76c 701 * @return array
6a488035
TO
702 */
703 public static function getNumericOptions($start = 0, $end = 10) {
be2fb01f 704 $numericOptions = [];
6a488035 705 for ($i = $start; $i <= $end; $i++) {
2aa397bc 706 $numericOptions[$i] = $i;
6a488035
TO
707 }
708 return $numericOptions;
709 }
f38395f7
KJ
710
711 /**
f9e31d7f 712 * Barcode types.
76e7a76c
CW
713 *
714 * @return array
f38395f7 715 */
00be9182 716 public static function getBarcodeTypes() {
be2fb01f 717 return [
c3831ebd
EM
718 'barcode' => ts('Linear (1D)'),
719 'qrcode' => ts('QR code'),
be2fb01f 720 ];
f38395f7 721 }
77d0b1f8 722
723 /**
f9e31d7f 724 * Dedupe rule types.
76e7a76c
CW
725 *
726 * @return array
77d0b1f8 727 */
00be9182 728 public static function getDedupeRuleTypes() {
be2fb01f 729 return [
c3831ebd
EM
730 'Unsupervised' => ts('Unsupervised'),
731 'Supervised' => ts('Supervised'),
732 'General' => ts('General'),
be2fb01f 733 ];
77d0b1f8 734 }
f80ce889 735
736 /**
f9e31d7f 737 * Campaign group types.
76e7a76c
CW
738 *
739 * @return array
f80ce889 740 */
00be9182 741 public static function getCampaignGroupTypes() {
be2fb01f 742 return [
c3831ebd
EM
743 'Include' => ts('Include'),
744 'Exclude' => ts('Exclude'),
be2fb01f 745 ];
f80ce889 746 }
747
748 /**
f9e31d7f 749 * Subscription history method.
76e7a76c
CW
750 *
751 * @return array
f80ce889 752 */
00be9182 753 public static function getSubscriptionHistoryMethods() {
be2fb01f 754 return [
c3831ebd
EM
755 'Admin' => ts('Admin'),
756 'Email' => ts('Email'),
757 'Web' => ts('Web'),
758 'API' => ts('API'),
be2fb01f 759 ];
f80ce889 760 }
761
762 /**
f9e31d7f 763 * Premium units.
76e7a76c
CW
764 *
765 * @return array
f80ce889 766 */
00be9182 767 public static function getPremiumUnits() {
be2fb01f 768 return [
c3831ebd
EM
769 'day' => ts('Day'),
770 'week' => ts('Week'),
771 'month' => ts('Month'),
772 'year' => ts('Year'),
be2fb01f 773 ];
f80ce889 774 }
56251ea7 775
776 /**
f9e31d7f 777 * Extension types.
76e7a76c
CW
778 *
779 * @return array
56251ea7 780 */
00be9182 781 public static function getExtensionTypes() {
be2fb01f 782 return [
c3831ebd
EM
783 'payment' => ts('Payment'),
784 'search' => ts('Search'),
785 'report' => ts('Report'),
786 'module' => ts('Module'),
787 'sms' => ts('SMS'),
be2fb01f 788 ];
56251ea7 789 }
790
791 /**
f9e31d7f 792 * Job frequency.
76e7a76c
CW
793 *
794 * @return array
56251ea7 795 */
00be9182 796 public static function getJobFrequency() {
be2fb01f 797 return [
bda41fcb
DRJ
798 // CRM-17669
799 'Yearly' => ts('Yearly'),
800 'Quarter' => ts('Quarterly'),
801 'Monthly' => ts('Monthly'),
802 'Weekly' => ts('Weekly'),
803
c3831ebd
EM
804 'Daily' => ts('Daily'),
805 'Hourly' => ts('Hourly'),
806 'Always' => ts('Every time cron job is run'),
be2fb01f 807 ];
56251ea7 808 }
e204d358 809
810 /**
f9e31d7f 811 * Search builder operators.
76e7a76c
CW
812 *
813 * @return array
e204d358 814 */
76c8a771 815 public static function getSearchBuilderOperators() {
80beace7 816 return [
c3831ebd
EM
817 '=' => '=',
818 '!=' => '≠',
819 '>' => '>',
820 '<' => '<',
821 '>=' => '≥',
822 '<=' => '≤',
823 'IN' => ts('In'),
afa0b07c 824 'NOT IN' => ts('Not In'),
c3831ebd 825 'LIKE' => ts('Like'),
afa0b07c 826 'NOT LIKE' => ts('Not Like'),
c3831ebd
EM
827 'RLIKE' => ts('Regex'),
828 'IS EMPTY' => ts('Is Empty'),
829 'IS NOT EMPTY' => ts('Not Empty'),
830 'IS NULL' => ts('Is Null'),
831 'IS NOT NULL' => ts('Not Null'),
80beace7 832 ];
e204d358 833 }
834
835 /**
f9e31d7f 836 * Profile group types.
e204d358 837 *
76e7a76c 838 * @return array
e204d358 839 */
00be9182 840 public static function getProfileGroupType() {
be2fb01f 841 $profileGroupType = [
c3831ebd
EM
842 'Activity' => ts('Activities'),
843 'Contribution' => ts('Contributions'),
844 'Membership' => ts('Memberships'),
845 'Participant' => ts('Participants'),
be2fb01f 846 ];
c3831ebd 847 $contactTypes = self::contactType();
be2fb01f 848 $contactTypes = !empty($contactTypes) ? ['Contact' => 'Contacts'] + $contactTypes : [];
481a74f4 849 $profileGroupType = array_merge($contactTypes, $profileGroupType);
c3831ebd 850
e204d358 851 return $profileGroupType;
852 }
853
e204d358 854 /**
f9e31d7f 855 * Word replacement match type.
76e7a76c
CW
856 *
857 * @return array
e204d358 858 */
00be9182 859 public static function getWordReplacementMatchType() {
be2fb01f 860 return [
353ffa53
TO
861 'exactMatch' => ts('Exact Match'),
862 'wildcardMatch' => ts('Wildcard Match'),
be2fb01f 863 ];
e204d358 864 }
865
71a707c3 866 /**
f9e31d7f 867 * Mailing group types.
76e7a76c
CW
868 *
869 * @return array
71a707c3 870 */
00be9182 871 public static function getMailingGroupTypes() {
be2fb01f 872 return [
c3831ebd
EM
873 'Include' => ts('Include'),
874 'Exclude' => ts('Exclude'),
875 'Base' => ts('Base'),
be2fb01f 876 ];
71a707c3 877 }
878
879 /**
f9e31d7f 880 * Mailing Job Status.
76e7a76c
CW
881 *
882 * @return array
71a707c3 883 */
00be9182 884 public static function getMailingJobStatus() {
be2fb01f 885 return [
c3831ebd
EM
886 'Scheduled' => ts('Scheduled'),
887 'Running' => ts('Running'),
888 'Complete' => ts('Complete'),
889 'Paused' => ts('Paused'),
890 'Canceled' => ts('Canceled'),
be2fb01f 891 ];
71a707c3 892 }
893
76e7a76c
CW
894 /**
895 * @return array
896 */
00be9182 897 public static function billingMode() {
be2fb01f 898 return [
280f1b05
CW
899 CRM_Core_Payment::BILLING_MODE_FORM => 'form',
900 CRM_Core_Payment::BILLING_MODE_BUTTON => 'button',
901 CRM_Core_Payment::BILLING_MODE_NOTIFY => 'notify',
be2fb01f 902 ];
280f1b05
CW
903 }
904
367b5943 905 /**
906 * @return array
907 */
908 public static function contributeMode() {
be2fb01f 909 return [
367b5943 910 CRM_Core_Payment::BILLING_MODE_FORM => 'direct',
911 CRM_Core_Payment::BILLING_MODE_BUTTON => 'directIPN',
912 CRM_Core_Payment::BILLING_MODE_NOTIFY => 'notify',
be2fb01f 913 ];
367b5943 914 }
915
9775f926 916 /**
f9e31d7f 917 * Frequency unit for schedule reminders.
76e7a76c 918 *
8fe4b69f
CW
919 * @param int $count
920 * For pluralization
76e7a76c 921 * @return array
9775f926 922 */
8fe4b69f
CW
923 public static function getRecurringFrequencyUnits($count = 1) {
924 // @todo this used to refer to the 'recur_frequency_unit' option_values which
925 // is for recurring payments and probably not good to re-use for recurring entities.
926 // If something other than a hard-coded list is desired, add a new option_group.
be2fb01f
CW
927 return [
928 'hour' => ts('hour', ['plural' => 'hours', 'count' => $count]),
929 'day' => ts('day', ['plural' => 'days', 'count' => $count]),
930 'week' => ts('week', ['plural' => 'weeks', 'count' => $count]),
931 'month' => ts('month', ['plural' => 'months', 'count' => $count]),
932 'year' => ts('year', ['plural' => 'years', 'count' => $count]),
933 ];
9775f926 934 }
96025800 935
7537a84b
J
936 /**
937 * Relative Date Terms.
938 *
939 * @return array
940 */
941 public static function getRelativeDateTerms() {
be2fb01f 942 return [
7537a84b
J
943 'previous' => ts('Previous'),
944 'previous_2' => ts('Previous 2'),
945 'previous_before' => ts('Prior to Previous'),
946 'before_previous' => ts('All Prior to Previous'),
947 'earlier' => ts('To End of Previous'),
948 'greater_previous' => ts('From End of Previous'),
949 'greater' => ts('From Start Of Current'),
950 'current' => ts('Current'),
951 'ending_3' => ts('Last 3'),
952 'ending_2' => ts('Last 2'),
953 'ending' => ts('Last'),
954 'this' => ts('This'),
955 'starting' => ts('Upcoming'),
956 'less' => ts('To End of'),
957 'next' => ts('Next'),
be2fb01f 958 ];
7537a84b
J
959 }
960
961 /**
962 * Relative Date Units.
963 *
964 * @return array
965 */
966 public static function getRelativeDateUnits() {
be2fb01f 967 return [
7537a84b
J
968 'year' => ts('Years'),
969 'fiscal_year' => ts('Fiscal Years'),
970 'quarter' => ts('Quarters'),
971 'month' => ts('Months'),
972 'week' => ts('Weeks'),
973 'day' => ts('Days'),
be2fb01f 974 ];
7537a84b
J
975 }
976
0aeb5a1e
CW
977 /**
978 * Exportable document formats.
979 *
980 * @return array
981 */
982 public static function documentFormat() {
be2fb01f 983 return [
0aeb5a1e
CW
984 'pdf' => ts('Portable Document Format (.pdf)'),
985 'docx' => ts('MS Word (.docx)'),
986 'odt' => ts('Open Office (.odt)'),
987 'html' => ts('Webpage (.html)'),
be2fb01f 988 ];
0aeb5a1e
CW
989 }
990
90a73810 991 /**
992 * Application type of document.
993 *
994 * @return array
995 */
996 public static function documentApplicationType() {
be2fb01f 997 return [
90a73810 998 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
999 'odt' => 'application/vnd.oasis.opendocument.text',
be2fb01f 1000 ];
90a73810 1001 }
1002
1cd7479e 1003 /**
1004 * Activity Text options.
1005 *
1006 * @return array
1007 */
1008 public static function activityTextOptions() {
be2fb01f 1009 return [
1cd7479e 1010 2 => ts('Details Only'),
1011 3 => ts('Subject Only'),
1012 6 => ts('Both'),
be2fb01f 1013 ];
1cd7479e 1014 }
1015
f871c3a9
AS
1016 /**
1017 * Relationship permissions
1018 *
1019 * @return array
1020 */
1021 public static function getPermissionedRelationshipOptions() {
be2fb01f 1022 return [
f871c3a9
AS
1023 CRM_Contact_BAO_Relationship::NONE => ts('None'),
1024 CRM_Contact_BAO_Relationship::VIEW => ts('View only'),
1025 CRM_Contact_BAO_Relationship::EDIT => ts('View and update'),
be2fb01f 1026 ];
f871c3a9
AS
1027 }
1028
f5e8cb7b 1029 /**
1030 * Get option values for dashboard entries (used for 'how many events to display on dashboard').
1031 *
1032 * @return array
1033 * Dashboard entries options - in practice [-1 => 'Show All', 10 => 10, 20 => 20, ... 100 => 100].
1034 */
1035 public static function getDashboardEntriesCount() {
1036 $optionValues = [];
1037 $optionValues[-1] = ts('show all');
1038 for ($i = 10; $i <= 100; $i += 10) {
1039 $optionValues[$i] = $i;
1040 }
1041 return $optionValues;
1042 }
1043
4235341b
CW
1044 /**
1045 * Dropdown options for quicksearch in the menu
1046 *
1047 * @return array
76c8a771 1048 * @throws \CiviCRM_API3_Exception
4235341b
CW
1049 */
1050 public static function quicksearchOptions() {
be2fb01f 1051 $includeEmail = civicrm_api3('setting', 'getvalue', ['name' => 'includeEmailInName', 'group' => 'Search Preferences']);
4235341b
CW
1052 $options = [
1053 'sort_name' => $includeEmail ? ts('Name/Email') : ts('Name'),
1054 'contact_id' => ts('Contact ID'),
1055 'external_identifier' => ts('External ID'),
1056 'first_name' => ts('First Name'),
1057 'last_name' => ts('Last Name'),
1058 'email' => ts('Email'),
1059 'phone_numeric' => ts('Phone'),
1060 'street_address' => ts('Street Address'),
1061 'city' => ts('City'),
1062 'postal_code' => ts('Postal Code'),
1063 'job_title' => ts('Job Title'),
1064 ];
1065 $custom = civicrm_api3('CustomField', 'get', [
1f8ac3d2
CW
1066 'return' => ['name', 'label', 'custom_group_id.title'],
1067 'custom_group_id.extends' => ['IN' => ['Contact', 'Individual', 'Organization', 'Household']],
1068 'data_type' => ['NOT IN' => ['ContactReference', 'Date', 'File']],
4235341b
CW
1069 'custom_group_id.is_active' => 1,
1070 'is_active' => 1,
1071 'is_searchable' => 1,
d44e024b 1072 'options' => ['sort' => ['custom_group_id.weight', 'weight'], 'limit' => 0],
4235341b
CW
1073 ]);
1074 foreach ($custom['values'] as $field) {
1075 $options['custom_' . $field['name']] = $field['custom_group_id.title'] . ': ' . $field['label'];
1076 }
1077 return $options;
1078 }
1079
281db812 1080 /**
1081 * Get components (translated for display.
1082 *
1083 * @return array
1084 *
1085 * @throws \Exception
1086 */
1087 public static function getComponentSelectValues() {
1088 $ret = [];
1089 $components = CRM_Core_Component::getComponents();
1090 foreach ($components as $name => $object) {
1091 $ret[$name] = $object->info['translatedName'];
1092 }
1093
1094 return $ret;
1095 }
1096
e0674c37
CW
1097 /**
1098 * @return string[]
1099 */
2bcfa9ee
CW
1100 public static function fieldSerialization() {
1101 return [
1102 CRM_Core_DAO::SERIALIZE_SEPARATOR_BOOKEND => 'separator_bookend',
1103 CRM_Core_DAO::SERIALIZE_SEPARATOR_TRIMMED => 'separator_trimmed',
1104 CRM_Core_DAO::SERIALIZE_JSON => 'json',
1105 CRM_Core_DAO::SERIALIZE_PHP => 'php',
1106 CRM_Core_DAO::SERIALIZE_COMMA => 'comma',
1107 ];
1108 }
1109
e0674c37
CW
1110 /**
1111 * @return array
1112 */
1113 public static function navigationMenuSeparator() {
1114 return [
1115 ts('None'),
1116 ts('After menu element'),
1117 ts('Before menu element'),
1118 ];
1119 }
1120
bf01b886
CW
1121 /**
1122 * @return array
1123 */
1124 public static function relationshipOrientation() {
1125 return [
1126 'a_b' => ts('A to B'),
1127 'b_a' => ts('B to A'),
1128 ];
1129 }
1130
6a488035 1131}