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