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