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