Merge pull request #22532 from seamuslee001/dev_core_3034
[civicrm-core.git] / CRM / Core / SelectValues.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 |
9 +--------------------------------------------------------------------+
10 */
11
12 use Civi\Token\TokenProcessor;
13
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
20 * @copyright CiviCRM LLC https://civicrm.org/licensing
21 */
22 class CRM_Core_SelectValues {
23
24 /**
25 * Yes/No options
26 *
27 * @return array
28 */
29 public static function boolean() {
30 return [
31 1 => ts('Yes'),
32 0 => ts('No'),
33 ];
34 }
35
36 /**
37 * Preferred mail format.
38 *
39 * @return array
40 */
41 public static function pmf() {
42 return [
43 'Both' => ts('Both'),
44 'HTML' => ts('HTML'),
45 'Text' => ts('Text'),
46 ];
47 }
48
49 /**
50 * Privacy options.
51 *
52 * @return array
53 */
54 public static function privacy() {
55 return [
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)'),
62 ];
63 }
64
65 /**
66 * Various pre defined contact super types.
67 *
68 * @return array
69 */
70 public static function contactType() {
71 return CRM_Contact_BAO_ContactType::basicTypePairs();
72 }
73
74 /**
75 * Various pre defined unit list.
76 *
77 * @param string $unitType
78 * @return array
79 */
80 public static function unitList($unitType = NULL) {
81 $unitList = [
82 'day' => ts('day'),
83 'month' => ts('month'),
84 'year' => ts('year'),
85 ];
86 if ($unitType === 'duration') {
87 $unitList['lifetime'] = ts('lifetime');
88 }
89 return $unitList;
90 }
91
92 /**
93 * Membership type unit.
94 *
95 * @return array
96 */
97 public static function membershipTypeUnitList() {
98 return self::unitList('duration');
99 }
100
101 /**
102 * Various pre defined period types.
103 *
104 * @return array
105 */
106 public static function periodType() {
107 return [
108 'rolling' => ts('Rolling'),
109 'fixed' => ts('Fixed'),
110 ];
111 }
112
113 /**
114 * Various pre defined email selection methods.
115 *
116 * @return array
117 */
118 public static function emailSelectMethods() {
119 return [
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'),
124 ];
125 }
126
127 /**
128 * Various pre defined member visibility options.
129 *
130 * @return array
131 */
132 public static function memberVisibility() {
133 return [
134 'Public' => ts('Public'),
135 'Admin' => ts('Admin'),
136 ];
137 }
138
139 /**
140 * Member auto-renew options
141 *
142 * @return array
143 */
144 public static function memberAutoRenew() {
145 return [
146 ts('No auto-renew option'),
147 ts('Give option, but not required'),
148 ts('Auto-renew required'),
149 ];
150 }
151
152 /**
153 * Various pre defined event dates.
154 *
155 * @return array
156 */
157 public static function eventDate() {
158 return [
159 'start_date' => ts('start date'),
160 'end_date' => ts('end date'),
161 'join_date' => ts('member since'),
162 ];
163 }
164
165 /**
166 * Custom form field types.
167 *
168 * @return array
169 */
170 public static function customHtmlType() {
171 return [
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 ],
222 ];
223 }
224
225 /**
226 * Various pre defined extensions for dynamic properties and groups.
227 *
228 * @return array
229 *
230 */
231 public static function customGroupExtends() {
232 $customGroupExtends = [
233 'Activity' => ts('Activities'),
234 'Relationship' => ts('Relationships'),
235 'Contribution' => ts('Contributions'),
236 'ContributionRecur' => ts('Recurring Contributions'),
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'),
248 ];
249 $contactTypes = ['Contact' => ts('Contacts')] + self::contactType();
250 $extendObjs = CRM_Core_OptionGroup::values('cg_extend_objects');
251 $customGroupExtends = array_merge($contactTypes, $customGroupExtends, $extendObjs);
252 return $customGroupExtends;
253 }
254
255 /**
256 * Styles for displaying the custom data group.
257 *
258 * @return array
259 */
260 public static function customGroupStyle() {
261 return [
262 'Tab' => ts('Tab'),
263 'Inline' => ts('Inline'),
264 'Tab with table' => ts('Tab with table'),
265 ];
266 }
267
268 /**
269 * For displaying the uf group types.
270 *
271 * @return array
272 */
273 public static function ufGroupTypes() {
274 $ufGroupType = [
275 'Profile' => ts('Standalone Form or Directory'),
276 'Search Profile' => ts('Search Views'),
277 ];
278
279 if (CRM_Core_Config::singleton()->userSystem->supports_form_extensions) {
280 $ufGroupType += CRM_Core_Config::singleton()->userSystem->getUfGroupTypes();
281 }
282 return $ufGroupType;
283 }
284
285 /**
286 * The status of a contact within a group.
287 *
288 * @return array
289 */
290 public static function groupContactStatus() {
291 return [
292 'Added' => ts('Added'),
293 'Removed' => ts('Removed'),
294 'Pending' => ts('Pending'),
295 ];
296 }
297
298 /**
299 * List of Group Types.
300 *
301 * @return array
302 */
303 public static function groupType() {
304 return [
305 'query' => ts('Dynamic'),
306 'static' => ts('Static'),
307 ];
308 }
309
310 /**
311 * Compose the parameters for a date select object.
312 *
313 * @param string|null $type
314 * the type of date
315 * @param string|null $format
316 * date format (QF format)
317 * @param null $minOffset
318 * @param null $maxOffset
319 * @param string $context
320 *
321 * @return array
322 * the date array
323 * @throws CRM_Core_Exception
324 */
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.
327 $date = [
328 'addEmptyOption' => TRUE,
329 'emptyOptionText' => ts('- select -'),
330 'emptyOptionValue' => '',
331 ];
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)) {
341 throw new CRM_Core_Exception('Date preferences not configured.');
342 }
343 if (!$maxOffset) {
344 $maxOffset = $dao->end;
345 }
346 if (!$minOffset) {
347 $minOffset = $dao->start;
348 }
349
350 $date['format'] = $dao->date_format;
351 $date['time'] = (bool) $dao->time_format;
352 }
353
354 if (empty($date['format'])) {
355 if ($context === 'Input') {
356 $date['format'] = Civi::settings()->get('dateInputFormat');
357 }
358 else {
359 $date['format'] = 'M d';
360 }
361 }
362 }
363
364 $date['smarty_view_format'] = CRM_Utils_Date::getDateFieldViewFormat($date['format']);
365 if (!isset($date['time'])) {
366 $date['time'] = FALSE;
367 }
368
369 $year = date('Y');
370 $date['minYear'] = $year - (int) $minOffset;
371 $date['maxYear'] = $year + (int) $maxOffset;
372 return $date;
373 }
374
375 /**
376 * Values for UF form visibility options.
377 *
378 * @return array
379 */
380 public static function ufVisibility() {
381 return [
382 'User and User Admin Only' => ts('User and User Admin Only'),
383 'Public Pages' => ts('Expose Publicly'),
384 'Public Pages and Listings' => ts('Expose Publicly and for Listings'),
385 ];
386 }
387
388 /**
389 * Values for group form visibility options.
390 *
391 * @return array
392 */
393 public static function groupVisibility() {
394 return [
395 'User and User Admin Only' => ts('User and User Admin Only'),
396 'Public Pages' => ts('Public Pages'),
397 ];
398 }
399
400 /**
401 * Different type of Mailing Components.
402 *
403 * @return array
404 */
405 public static function mailingComponents() {
406 return [
407 'Header' => ts('Header'),
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'),
415 ];
416 }
417
418 /**
419 * Get hours.
420 *
421 * @return array
422 */
423 public function getHours() {
424 $hours = [];
425 for ($i = 0; $i <= 6; $i++) {
426 $hours[$i] = $i;
427 }
428 return $hours;
429 }
430
431 /**
432 * Get minutes.
433 *
434 * @return array
435 */
436 public function getMinutes() {
437 $minutes = [];
438 for ($i = 0; $i < 60; $i = $i + 15) {
439 $minutes[$i] = $i;
440 }
441 return $minutes;
442 }
443
444 /**
445 * Get the Map Provider.
446 *
447 * @return array
448 * array of map providers
449 */
450 public static function mapProvider() {
451 static $map = NULL;
452 if (!$map) {
453 $map = ['' => ts('- select -')] + CRM_Utils_System::getPluginList('templates/CRM/Contact/Form/Task/Map', ".tpl");
454 }
455 return $map;
456 }
457
458 /**
459 * Get the Geocoding Providers from available plugins.
460 *
461 * @return array
462 * array of geocoder providers
463 */
464 public static function geoProvider() {
465 static $geo = NULL;
466 if (!$geo) {
467 $geo = ['' => ts('- select -')] + CRM_Utils_System::getPluginList('CRM/Utils/Geocode');
468 }
469 return $geo;
470 }
471
472 /**
473 * Get options for displaying tax.
474 *
475 * @return array
476 *
477 * @throws \CRM_Core_Exception
478 */
479 public static function taxDisplayOptions() {
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
493 /**
494 * Get the Address Standardization Providers from available plugins.
495 *
496 * @return array
497 * array of address standardization providers
498 */
499 public static function addressProvider() {
500 static $addr = NULL;
501 if (!$addr) {
502 $addr = array_merge(['' => ts('- select -')], CRM_Utils_System::getPluginList('CRM/Utils/Address', '.php', ['BatchUpdate']));
503 }
504 return $addr;
505 }
506
507 /**
508 * Different type of Mailing Tokens.
509 *
510 * @return array
511 */
512 public static function mailingTokens() {
513 return [
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'),
523 '{mailing.key}' => ts('Mailing key'),
524 '{mailing.name}' => ts('Mailing name'),
525 '{mailing.group}' => ts('Mailing group'),
526 '{mailing.viewUrl}' => ts('Mailing permalink'),
527 ] + self::domainTokens();
528 }
529
530 /**
531 * Domain tokens
532 *
533 * @return array
534 *
535 * @deprecated
536 */
537 public static function domainTokens() {
538 $tokenProcessor = new TokenProcessor(Civi::dispatcher(), []);
539 return $tokenProcessor->listTokens();
540 }
541
542 /**
543 * Different type of Activity Tokens.
544 *
545 * @return array
546 */
547 public static function activityTokens() {
548 return [
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'),
553 ];
554 }
555
556 /**
557 * Different type of Membership Tokens.
558 *
559 * @return array
560 */
561 public static function membershipTokens(): array {
562 return [
563 '{membership.id}' => ts('Membership ID'),
564 '{membership.status_id:label}' => ts('Status'),
565 '{membership.membership_type_id:label}' => ts('Membership Type'),
566 '{membership.start_date}' => ts('Membership Start Date'),
567 '{membership.join_date}' => ts('Member Since'),
568 '{membership.end_date}' => ts('Membership Expiration Date'),
569 '{membership.fee}' => ts('Membership Fee'),
570 ];
571 }
572
573 /**
574 * Different type of Event Tokens.
575 *
576 * @deprecated
577 *
578 * @return array
579 */
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;
589 }
590
591 /**
592 * Different type of Contribution Tokens.
593 *
594 * @deprecated
595 *
596 * @return array
597 */
598 public static function contributionTokens(): array {
599 $tokenProcessor = new TokenProcessor(Civi::dispatcher(), ['schema' => ['contributionId']]);
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;
607 }
608
609 /**
610 * Different type of Contact Tokens.
611 *
612 * @deprecated
613 *
614 * @return array
615 */
616 public static function contactTokens(): array {
617 $tokenProcessor = new TokenProcessor(Civi::dispatcher(), ['schema' => ['contactId']]);
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;
625 }
626
627 /**
628 * Different type of Participant Tokens.
629 *
630 * @deprecated
631 *
632 * @return array
633 */
634 public static function participantTokens(): array {
635 $tokenProcessor = new TokenProcessor(Civi::dispatcher(), ['schema' => ['participantId']]);
636 $allTokens = $tokenProcessor->listTokens();
637 foreach (array_keys($allTokens) as $token) {
638 if (strpos($token, '{domain.') === 0 || strpos($token, '{event.') === 0) {
639 unset($allTokens[$token]);
640 }
641 }
642 return $allTokens;
643 }
644
645 /**
646 * @param int $caseTypeId
647 * @return array
648 */
649 public static function caseTokens($caseTypeId = NULL) {
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 ];
662
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']}";
666 }
667 return $tokens;
668 }
669
670 /**
671 * CiviCRM supported date input formats.
672 *
673 * @return array
674 */
675 public static function getDatePluginInputFormats() {
676 return [
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)'),
692 ];
693 }
694
695 /**
696 * Time formats.
697 *
698 * @return array
699 */
700 public static function getTimeFormats() {
701 return [
702 '1' => ts('12 Hours'),
703 '2' => ts('24 Hours'),
704 ];
705 }
706
707 /**
708 * Get numeric options.
709 *
710 * @param int $start
711 * @param int $end
712 *
713 * @return array
714 */
715 public static function getNumericOptions($start = 0, $end = 10) {
716 $numericOptions = [];
717 for ($i = $start; $i <= $end; $i++) {
718 $numericOptions[$i] = $i;
719 }
720 return $numericOptions;
721 }
722
723 /**
724 * Barcode types.
725 *
726 * @return array
727 */
728 public static function getBarcodeTypes() {
729 return [
730 'barcode' => ts('Linear (1D)'),
731 'qrcode' => ts('QR code'),
732 ];
733 }
734
735 /**
736 * Dedupe rule types.
737 *
738 * @return array
739 */
740 public static function getDedupeRuleTypes() {
741 return [
742 'Unsupervised' => ts('Unsupervised'),
743 'Supervised' => ts('Supervised'),
744 'General' => ts('General'),
745 ];
746 }
747
748 /**
749 * Campaign group types.
750 *
751 * @return array
752 */
753 public static function getCampaignGroupTypes() {
754 return [
755 'Include' => ts('Include'),
756 'Exclude' => ts('Exclude'),
757 ];
758 }
759
760 /**
761 * Subscription history method.
762 *
763 * @return array
764 */
765 public static function getSubscriptionHistoryMethods() {
766 return [
767 'Admin' => ts('Admin'),
768 'Email' => ts('Email'),
769 'Web' => ts('Web'),
770 'API' => ts('API'),
771 ];
772 }
773
774 /**
775 * Premium units.
776 *
777 * @return array
778 */
779 public static function getPremiumUnits() {
780 return [
781 'day' => ts('Day'),
782 'week' => ts('Week'),
783 'month' => ts('Month'),
784 'year' => ts('Year'),
785 ];
786 }
787
788 /**
789 * Extension types.
790 *
791 * @return array
792 */
793 public static function getExtensionTypes() {
794 return [
795 'payment' => ts('Payment'),
796 'search' => ts('Search'),
797 'report' => ts('Report'),
798 'module' => ts('Module'),
799 'sms' => ts('SMS'),
800 ];
801 }
802
803 /**
804 * Job frequency.
805 *
806 * @return array
807 */
808 public static function getJobFrequency() {
809 return [
810 // CRM-17669
811 'Yearly' => ts('Yearly'),
812 'Quarter' => ts('Quarterly'),
813 'Monthly' => ts('Monthly'),
814 'Weekly' => ts('Weekly'),
815
816 'Daily' => ts('Daily'),
817 'Hourly' => ts('Hourly'),
818 'Always' => ts('Every time cron job is run'),
819 ];
820 }
821
822 /**
823 * Search builder operators.
824 *
825 * @return array
826 */
827 public static function getSearchBuilderOperators() {
828 return [
829 '=' => '=',
830 '!=' => '≠',
831 '>' => '>',
832 '<' => '<',
833 '>=' => '≥',
834 '<=' => '≤',
835 'IN' => ts('In'),
836 'NOT IN' => ts('Not In'),
837 'LIKE' => ts('Like'),
838 'NOT LIKE' => ts('Not Like'),
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'),
844 ];
845 }
846
847 /**
848 * Profile group types.
849 *
850 * @return array
851 */
852 public static function getProfileGroupType() {
853 $profileGroupType = [
854 'Activity' => ts('Activities'),
855 'Contribution' => ts('Contributions'),
856 'Membership' => ts('Memberships'),
857 'Participant' => ts('Participants'),
858 ];
859 $contactTypes = self::contactType();
860 $contactTypes = !empty($contactTypes) ? ['Contact' => 'Contacts'] + $contactTypes : [];
861 $profileGroupType = array_merge($contactTypes, $profileGroupType);
862
863 return $profileGroupType;
864 }
865
866 /**
867 * Word replacement match type.
868 *
869 * @return array
870 */
871 public static function getWordReplacementMatchType() {
872 return [
873 'exactMatch' => ts('Exact Match'),
874 'wildcardMatch' => ts('Wildcard Match'),
875 ];
876 }
877
878 /**
879 * Mailing group types.
880 *
881 * @return array
882 */
883 public static function getMailingGroupTypes() {
884 return [
885 'Include' => ts('Include'),
886 'Exclude' => ts('Exclude'),
887 'Base' => ts('Base'),
888 ];
889 }
890
891 /**
892 * Mailing Job Status.
893 *
894 * @return array
895 */
896 public static function getMailingJobStatus() {
897 return [
898 'Scheduled' => ts('Scheduled'),
899 'Running' => ts('Running'),
900 'Complete' => ts('Complete'),
901 'Paused' => ts('Paused'),
902 'Canceled' => ts('Canceled'),
903 ];
904 }
905
906 /**
907 * @return array
908 */
909 public static function billingMode() {
910 return [
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 ],
926 ];
927 }
928
929 /**
930 * @return array
931 */
932 public static function contributeMode() {
933 return [
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 ],
949 ];
950 }
951
952 /**
953 * Frequency unit for schedule reminders.
954 *
955 * @param int $count
956 * For pluralization
957 * @return array
958 */
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.
963 return [
964 'minute' => ts('minute', ['plural' => 'minutes', 'count' => $count]),
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 ];
971 }
972
973 /**
974 * Relative Date Terms.
975 *
976 * @return array
977 */
978 public static function getRelativeDateTerms() {
979 return [
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'),
995 ];
996 }
997
998 /**
999 * Relative Date Units.
1000 *
1001 * @return array
1002 */
1003 public static function getRelativeDateUnits() {
1004 return [
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'),
1011 ];
1012 }
1013
1014 /**
1015 * Exportable document formats.
1016 *
1017 * @return array
1018 */
1019 public static function documentFormat() {
1020 return [
1021 'pdf' => ts('Portable Document Format (.pdf)'),
1022 'docx' => ts('MS Word (.docx)'),
1023 'odt' => ts('Open Office (.odt)'),
1024 'html' => ts('Webpage (.html)'),
1025 ];
1026 }
1027
1028 /**
1029 * Application type of document.
1030 *
1031 * @return array
1032 */
1033 public static function documentApplicationType() {
1034 return [
1035 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
1036 'odt' => 'application/vnd.oasis.opendocument.text',
1037 ];
1038 }
1039
1040 /**
1041 * Activity Text options.
1042 *
1043 * @return array
1044 */
1045 public static function activityTextOptions() {
1046 return [
1047 2 => ts('Details Only'),
1048 3 => ts('Subject Only'),
1049 6 => ts('Both'),
1050 ];
1051 }
1052
1053 /**
1054 * Relationship permissions
1055 *
1056 * @return array
1057 */
1058 public static function getPermissionedRelationshipOptions() {
1059 return [
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'),
1063 ];
1064 }
1065
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
1081 /**
1082 * Dropdown options for quicksearch in the menu
1083 *
1084 * @return array
1085 * @throws \CiviCRM_API3_Exception
1086 */
1087 public static function quicksearchOptions() {
1088 $includeEmail = civicrm_api3('setting', 'getvalue', ['name' => 'includeEmailInName', 'group' => 'Search Preferences']);
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', [
1103 'return' => ['name', 'label', 'custom_group_id.title'],
1104 'custom_group_id.extends' => ['IN' => array_merge(['Contact'], CRM_Contact_BAO_ContactType::basicTypes())],
1105 'data_type' => ['NOT IN' => ['ContactReference', 'Date', 'File']],
1106 'custom_group_id.is_active' => 1,
1107 'is_active' => 1,
1108 'is_searchable' => 1,
1109 'options' => ['sort' => ['custom_group_id.weight', 'weight'], 'limit' => 0],
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
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
1134 /**
1135 * @return string[]
1136 */
1137 public static function fieldSerialization() {
1138 return [
1139 CRM_Core_DAO::SERIALIZE_NONE => 'none',
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
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
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
1169 /**
1170 * @return array
1171 */
1172 public static function andOr() {
1173 return [
1174 'AND' => ts('And'),
1175 'OR' => ts('Or'),
1176 ];
1177 }
1178
1179 }