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