Merge pull request #18378 from colemanw/noMoreStupidHTMLTypes
[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 /**
13 * One place to store frequently used values in Select Elements. Note that
14 * some of the below elements will be dynamic, so we'll probably have a
15 * smart caching scheme on a per domain basis
16 *
17 * @package CRM
18 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 */
20 class CRM_Core_SelectValues {
21
22 /**
23 * Yes/No options
24 *
25 * @return array
26 */
27 public static function boolean() {
28 return [
29 1 => ts('Yes'),
30 0 => ts('No'),
31 ];
32 }
33
34 /**
35 * Preferred mail format.
36 *
37 * @return array
38 */
39 public static function pmf() {
40 return [
41 'Both' => ts('Both'),
42 'HTML' => ts('HTML'),
43 'Text' => ts('Text'),
44 ];
45 }
46
47 /**
48 * Privacy options.
49 *
50 * @return array
51 */
52 public static function privacy() {
53 return [
54 'do_not_phone' => ts('Do not phone'),
55 'do_not_email' => ts('Do not email'),
56 'do_not_mail' => ts('Do not mail'),
57 'do_not_sms' => ts('Do not sms'),
58 'do_not_trade' => ts('Do not trade'),
59 'is_opt_out' => ts('No bulk emails (User Opt Out)'),
60 ];
61 }
62
63 /**
64 * Various pre defined contact super types.
65 *
66 * @return array
67 */
68 public static function contactType() {
69 return CRM_Contact_BAO_ContactType::basicTypePairs();
70 }
71
72 /**
73 * Various pre defined unit list.
74 *
75 * @param string $unitType
76 * @return array
77 */
78 public static function unitList($unitType = NULL) {
79 $unitList = [
80 'day' => ts('day'),
81 'month' => ts('month'),
82 'year' => ts('year'),
83 ];
84 if ($unitType === 'duration') {
85 $unitList['lifetime'] = ts('lifetime');
86 }
87 return $unitList;
88 }
89
90 /**
91 * Membership type unit.
92 *
93 * @return array
94 */
95 public static function membershipTypeUnitList() {
96 return self::unitList('duration');
97 }
98
99 /**
100 * Various pre defined period types.
101 *
102 * @return array
103 */
104 public static function periodType() {
105 return [
106 'rolling' => ts('Rolling'),
107 'fixed' => ts('Fixed'),
108 ];
109 }
110
111 /**
112 * Various pre defined email selection methods.
113 *
114 * @return array
115 */
116 public static function emailSelectMethods() {
117 return [
118 'automatic' => ts('Automatic'),
119 'location-only' => ts('Only send to email addresses assigned to the specified location'),
120 'location-prefer' => ts('Prefer email addresses assigned to the specified location'),
121 'location-exclude' => ts('Exclude email addresses assigned to the specified location'),
122 ];
123 }
124
125 /**
126 * Various pre defined member visibility options.
127 *
128 * @return array
129 */
130 public static function memberVisibility() {
131 return [
132 'Public' => ts('Public'),
133 'Admin' => ts('Admin'),
134 ];
135 }
136
137 /**
138 * Member auto-renew options
139 *
140 * @return array
141 */
142 public static function memberAutoRenew() {
143 return [
144 ts('No auto-renew option'),
145 ts('Give option, but not required'),
146 ts('Auto-renew required'),
147 ];
148 }
149
150 /**
151 * Various pre defined event dates.
152 *
153 * @return array
154 */
155 public static function eventDate() {
156 return [
157 'start_date' => ts('start date'),
158 'end_date' => ts('end date'),
159 'join_date' => ts('member since'),
160 ];
161 }
162
163 /**
164 * Custom form field types.
165 *
166 * @return array
167 */
168 public static function customHtmlType() {
169 return [
170 'Text' => ts('Single-line input field (text or numeric)'),
171 'TextArea' => ts('Multi-line text box (textarea)'),
172 'Select' => ts('Drop-down (select list)'),
173 'Radio' => ts('Radio buttons'),
174 'CheckBox' => ts('Checkbox(es)'),
175 'Select Date' => ts('Select Date'),
176 'File' => ts('File'),
177 'RichTextEditor' => ts('Rich Text Editor'),
178 'Autocomplete-Select' => ts('Autocomplete-Select'),
179 'Link' => ts('Link'),
180 'ContactReference' => ts('Autocomplete-Select'),
181 ];
182 }
183
184 /**
185 * Various pre defined extensions for dynamic properties and groups.
186 *
187 * @return array
188 *
189 */
190 public static function customGroupExtends() {
191 $customGroupExtends = [
192 'Activity' => ts('Activities'),
193 'Relationship' => ts('Relationships'),
194 'Contribution' => ts('Contributions'),
195 'ContributionRecur' => ts('Recurring Contributions'),
196 'Group' => ts('Groups'),
197 'Membership' => ts('Memberships'),
198 'Event' => ts('Events'),
199 'Participant' => ts('Participants'),
200 'ParticipantRole' => ts('Participants (Role)'),
201 'ParticipantEventName' => ts('Participants (Event Name)'),
202 'ParticipantEventType' => ts('Participants (Event Type)'),
203 'Pledge' => ts('Pledges'),
204 'Grant' => ts('Grants'),
205 'Address' => ts('Addresses'),
206 'Campaign' => ts('Campaigns'),
207 ];
208 $contactTypes = self::contactType();
209 $contactTypes = !empty($contactTypes) ? ['Contact' => 'Contacts'] + $contactTypes : [];
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 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 public static function domainTokens() {
499 return [
500 '{domain.name}' => ts('Domain name'),
501 '{domain.address}' => ts('Domain (organization) address'),
502 '{domain.phone}' => ts('Domain (organization) phone'),
503 '{domain.email}' => ts('Domain (organization) email'),
504 ];
505 }
506
507 /**
508 * Different type of Activity Tokens.
509 *
510 * @return array
511 */
512 public static function activityTokens() {
513 return [
514 '{activity.activity_id}' => ts('Activity ID'),
515 '{activity.subject}' => ts('Activity Subject'),
516 '{activity.details}' => ts('Activity Details'),
517 '{activity.activity_date_time}' => ts('Activity Date Time'),
518 ];
519 }
520
521 /**
522 * Different type of Membership Tokens.
523 *
524 * @return array
525 */
526 public static function membershipTokens() {
527 return [
528 '{membership.id}' => ts('Membership ID'),
529 '{membership.status}' => ts('Membership Status'),
530 '{membership.type}' => ts('Membership Type'),
531 '{membership.start_date}' => ts('Membership Start Date'),
532 '{membership.join_date}' => ts('Membership Join Date'),
533 '{membership.end_date}' => ts('Membership End Date'),
534 '{membership.fee}' => ts('Membership Fee'),
535 ];
536 }
537
538 /**
539 * Different type of Event Tokens.
540 *
541 * @return array
542 */
543 public static function eventTokens() {
544 return [
545 '{event.event_id}' => ts('Event ID'),
546 '{event.title}' => ts('Event Title'),
547 '{event.start_date}' => ts('Event Start Date'),
548 '{event.end_date}' => ts('Event End Date'),
549 '{event.event_type}' => ts('Event Type'),
550 '{event.summary}' => ts('Event Summary'),
551 '{event.contact_email}' => ts('Event Contact Email'),
552 '{event.contact_phone}' => ts('Event Contact Phone'),
553 '{event.description}' => ts('Event Description'),
554 '{event.location}' => ts('Event Location'),
555 '{event.fee_amount}' => ts('Event Fees'),
556 '{event.info_url}' => ts('Event Info URL'),
557 '{event.registration_url}' => ts('Event Registration URL'),
558 '{event.balance}' => ts('Event Balance'),
559 ];
560 }
561
562 /**
563 * Different type of Event Tokens.
564 *
565 * @return array
566 */
567 public static function contributionTokens() {
568 return array_merge([
569 '{contribution.contribution_id}' => ts('Contribution ID'),
570 '{contribution.total_amount}' => ts('Total Amount'),
571 '{contribution.fee_amount}' => ts('Fee Amount'),
572 '{contribution.net_amount}' => ts('Net Amount'),
573 '{contribution.non_deductible_amount}' => ts('Non-deductible Amount'),
574 '{contribution.receive_date}' => ts('Contribution Date Received'),
575 '{contribution.payment_instrument}' => ts('Payment Method'),
576 '{contribution.trxn_id}' => ts('Transaction ID'),
577 '{contribution.invoice_id}' => ts('Invoice ID'),
578 '{contribution.currency}' => ts('Currency'),
579 '{contribution.cancel_date}' => ts('Contribution Cancel Date'),
580 '{contribution.cancel_reason}' => ts('Contribution Cancel Reason'),
581 '{contribution.receipt_date}' => ts('Receipt Date'),
582 '{contribution.thankyou_date}' => ts('Thank You Date'),
583 '{contribution.contribution_source}' => ts('Contribution Source'),
584 '{contribution.amount_level}' => ts('Amount Level'),
585 //'{contribution.contribution_recur_id}' => ts('Contribution Recurring ID'),
586 //'{contribution.honor_contact_id}' => ts('Honor Contact ID'),
587 '{contribution.contribution_status_id}' => ts('Contribution Status'),
588 //'{contribution.honor_type_id}' => ts('Honor Type ID'),
589 //'{contribution.address_id}' => ts('Address ID'),
590 '{contribution.check_number}' => ts('Check Number'),
591 '{contribution.campaign}' => ts('Contribution Campaign'),
592 ], CRM_Utils_Token::getCustomFieldTokens('contribution', TRUE));
593 }
594
595 /**
596 * Different type of Contact Tokens.
597 *
598 * @return array
599 */
600 public static function contactTokens() {
601 static $tokens = NULL;
602 if (!$tokens) {
603 $additionalFields = [
604 'checksum' => ['title' => ts('Checksum')],
605 'contact_id' => ['title' => ts('Internal Contact ID')],
606 ];
607 $exportFields = array_merge(CRM_Contact_BAO_Contact::exportableFields(), $additionalFields);
608
609 $values = array_merge(array_keys($exportFields));
610 unset($values[0]);
611
612 //FIXME:skipping some tokens for time being.
613 $skipTokens = [
614 'is_bulkmail',
615 'group',
616 'tag',
617 'contact_sub_type',
618 'note',
619 'is_deceased',
620 'deceased_date',
621 'legal_identifier',
622 'contact_sub_type',
623 'user_unique_id',
624 ];
625
626 $customFields = CRM_Core_BAO_CustomField::getFields(['Individual', 'Address']);
627 $legacyTokenNames = array_flip(CRM_Utils_Token::legacyContactTokens());
628
629 foreach ($values as $val) {
630 if (in_array($val, $skipTokens)) {
631 continue;
632 }
633 //keys for $tokens should be constant. $token Values are changed for Custom Fields. CRM-3734
634 $customFieldId = CRM_Core_BAO_CustomField::getKeyID($val);
635 if ($customFieldId) {
636 // CRM-15191 - if key is not in $customFields then the field is disabled and should be ignored
637 if (!empty($customFields[$customFieldId])) {
638 $tokens["{contact.$val}"] = $customFields[$customFieldId]['label'] . " :: " . $customFields[$customFieldId]['groupTitle'];
639 }
640 }
641 else {
642 // Support legacy token names
643 $tokenName = CRM_Utils_Array::value($val, $legacyTokenNames, $val);
644 $tokens["{contact.$tokenName}"] = $exportFields[$val]['title'];
645 }
646 }
647
648 // Get all the hook tokens too
649 $hookTokens = [];
650 CRM_Utils_Hook::tokens($hookTokens);
651 foreach ($hookTokens as $tokenValues) {
652 foreach ($tokenValues as $key => $value) {
653 if (is_numeric($key)) {
654 $key = $value;
655 }
656 if (!preg_match('/^\{[^\}]+\}$/', $key)) {
657 $key = '{' . $key . '}';
658 }
659 if (preg_match('/^\{([^\}]+)\}$/', $value, $matches)) {
660 $value = $matches[1];
661 }
662 $tokens[$key] = $value;
663 }
664 }
665 }
666
667 return $tokens;
668 }
669
670 /**
671 * Different type of Participant Tokens.
672 *
673 * @return array
674 */
675 public static function participantTokens() {
676 static $tokens = NULL;
677 if (!$tokens) {
678 $exportFields = CRM_Event_BAO_Participant::exportableFields();
679
680 $values = array_merge(array_keys($exportFields));
681 unset($values[0]);
682
683 // skipping some tokens for time being.
684 $skipTokens = [
685 'event_id',
686 'participant_is_pay_later',
687 'participant_is_test',
688 'participant_contact_id',
689 'participant_fee_currency',
690 'participant_campaign_id',
691 'participant_status',
692 'participant_discount_name',
693 ];
694
695 $customFields = CRM_Core_BAO_CustomField::getFields('Participant');
696
697 foreach ($values as $key => $val) {
698 if (in_array($val, $skipTokens)) {
699 continue;
700 }
701 //keys for $tokens should be constant. $token Values are changed for Custom Fields. CRM-3734
702 if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($val)) {
703 $tokens["{participant.$val}"] = !empty($customFields[$customFieldId]) ? $customFields[$customFieldId]['label'] . " :: " . $customFields[$customFieldId]['groupTitle'] : '';
704 }
705 else {
706 $tokens["{participant.$val}"] = $exportFields[$val]['title'];
707 }
708 }
709 }
710 return $tokens;
711 }
712
713 /**
714 * @param int $caseTypeId
715 * @return array
716 */
717 public static function caseTokens($caseTypeId = NULL) {
718 static $tokens = NULL;
719 if (!$tokens) {
720 foreach (CRM_Case_BAO_Case::fields() as $field) {
721 $tokens["{case.{$field['name']}}"] = $field['title'];
722 }
723
724 $customFields = CRM_Core_BAO_CustomField::getFields('Case', FALSE, FALSE, $caseTypeId);
725 foreach ($customFields as $id => $field) {
726 $tokens["{case.custom_$id}"] = "{$field['label']} :: {$field['groupTitle']}";
727 }
728 }
729 return $tokens;
730 }
731
732 /**
733 * CiviCRM supported date input formats.
734 *
735 * @return array
736 */
737 public static function getDatePluginInputFormats() {
738 return [
739 'mm/dd/yy' => ts('mm/dd/yy (12/31/2009)'),
740 'dd/mm/yy' => ts('dd/mm/yy (31/12/2009)'),
741 'yy-mm-dd' => ts('yy-mm-dd (2009-12-31)'),
742 'dd-mm-yy' => ts('dd-mm-yy (31-12-2009)'),
743 'dd.mm.yy' => ts('dd.mm.yy (31.12.2009)'),
744 'M d, yy' => ts('M d, yy (Dec 31, 2009)'),
745 'd M yy' => ts('d M yy (31 Dec 2009)'),
746 'MM d, yy' => ts('MM d, yy (December 31, 2009)'),
747 'd MM yy' => ts('d MM yy (31 December 2009)'),
748 'DD, d MM yy' => ts('DD, d MM yy (Thursday, 31 December 2009)'),
749 'mm/dd' => ts('mm/dd (12/31)'),
750 'dd-mm' => ts('dd-mm (31-12)'),
751 'yy-mm' => ts('yy-mm (2009-12)'),
752 'M yy' => ts('M yy (Dec 2009)'),
753 'yy' => ts('yy (2009)'),
754 ];
755 }
756
757 /**
758 * Time formats.
759 *
760 * @return array
761 */
762 public static function getTimeFormats() {
763 return [
764 '1' => ts('12 Hours'),
765 '2' => ts('24 Hours'),
766 ];
767 }
768
769 /**
770 * Get numeric options.
771 *
772 * @param int $start
773 * @param int $end
774 *
775 * @return array
776 */
777 public static function getNumericOptions($start = 0, $end = 10) {
778 $numericOptions = [];
779 for ($i = $start; $i <= $end; $i++) {
780 $numericOptions[$i] = $i;
781 }
782 return $numericOptions;
783 }
784
785 /**
786 * Barcode types.
787 *
788 * @return array
789 */
790 public static function getBarcodeTypes() {
791 return [
792 'barcode' => ts('Linear (1D)'),
793 'qrcode' => ts('QR code'),
794 ];
795 }
796
797 /**
798 * Dedupe rule types.
799 *
800 * @return array
801 */
802 public static function getDedupeRuleTypes() {
803 return [
804 'Unsupervised' => ts('Unsupervised'),
805 'Supervised' => ts('Supervised'),
806 'General' => ts('General'),
807 ];
808 }
809
810 /**
811 * Campaign group types.
812 *
813 * @return array
814 */
815 public static function getCampaignGroupTypes() {
816 return [
817 'Include' => ts('Include'),
818 'Exclude' => ts('Exclude'),
819 ];
820 }
821
822 /**
823 * Subscription history method.
824 *
825 * @return array
826 */
827 public static function getSubscriptionHistoryMethods() {
828 return [
829 'Admin' => ts('Admin'),
830 'Email' => ts('Email'),
831 'Web' => ts('Web'),
832 'API' => ts('API'),
833 ];
834 }
835
836 /**
837 * Premium units.
838 *
839 * @return array
840 */
841 public static function getPremiumUnits() {
842 return [
843 'day' => ts('Day'),
844 'week' => ts('Week'),
845 'month' => ts('Month'),
846 'year' => ts('Year'),
847 ];
848 }
849
850 /**
851 * Extension types.
852 *
853 * @return array
854 */
855 public static function getExtensionTypes() {
856 return [
857 'payment' => ts('Payment'),
858 'search' => ts('Search'),
859 'report' => ts('Report'),
860 'module' => ts('Module'),
861 'sms' => ts('SMS'),
862 ];
863 }
864
865 /**
866 * Job frequency.
867 *
868 * @return array
869 */
870 public static function getJobFrequency() {
871 return [
872 // CRM-17669
873 'Yearly' => ts('Yearly'),
874 'Quarter' => ts('Quarterly'),
875 'Monthly' => ts('Monthly'),
876 'Weekly' => ts('Weekly'),
877
878 'Daily' => ts('Daily'),
879 'Hourly' => ts('Hourly'),
880 'Always' => ts('Every time cron job is run'),
881 ];
882 }
883
884 /**
885 * Search builder operators.
886 *
887 * @return array
888 */
889 public static function getSearchBuilderOperators() {
890 return [
891 '=' => '=',
892 '!=' => '≠',
893 '>' => '>',
894 '<' => '<',
895 '>=' => '≥',
896 '<=' => '≤',
897 'IN' => ts('In'),
898 'NOT IN' => ts('Not In'),
899 'LIKE' => ts('Like'),
900 'NOT LIKE' => ts('Not Like'),
901 'RLIKE' => ts('Regex'),
902 'IS EMPTY' => ts('Is Empty'),
903 'IS NOT EMPTY' => ts('Not Empty'),
904 'IS NULL' => ts('Is Null'),
905 'IS NOT NULL' => ts('Not Null'),
906 ];
907 }
908
909 /**
910 * Profile group types.
911 *
912 * @return array
913 */
914 public static function getProfileGroupType() {
915 $profileGroupType = [
916 'Activity' => ts('Activities'),
917 'Contribution' => ts('Contributions'),
918 'Membership' => ts('Memberships'),
919 'Participant' => ts('Participants'),
920 ];
921 $contactTypes = self::contactType();
922 $contactTypes = !empty($contactTypes) ? ['Contact' => 'Contacts'] + $contactTypes : [];
923 $profileGroupType = array_merge($contactTypes, $profileGroupType);
924
925 return $profileGroupType;
926 }
927
928 /**
929 * Word replacement match type.
930 *
931 * @return array
932 */
933 public static function getWordReplacementMatchType() {
934 return [
935 'exactMatch' => ts('Exact Match'),
936 'wildcardMatch' => ts('Wildcard Match'),
937 ];
938 }
939
940 /**
941 * Mailing group types.
942 *
943 * @return array
944 */
945 public static function getMailingGroupTypes() {
946 return [
947 'Include' => ts('Include'),
948 'Exclude' => ts('Exclude'),
949 'Base' => ts('Base'),
950 ];
951 }
952
953 /**
954 * Mailing Job Status.
955 *
956 * @return array
957 */
958 public static function getMailingJobStatus() {
959 return [
960 'Scheduled' => ts('Scheduled'),
961 'Running' => ts('Running'),
962 'Complete' => ts('Complete'),
963 'Paused' => ts('Paused'),
964 'Canceled' => ts('Canceled'),
965 ];
966 }
967
968 /**
969 * @return array
970 */
971 public static function billingMode() {
972 return [
973 CRM_Core_Payment::BILLING_MODE_FORM => 'form',
974 CRM_Core_Payment::BILLING_MODE_BUTTON => 'button',
975 CRM_Core_Payment::BILLING_MODE_NOTIFY => 'notify',
976 ];
977 }
978
979 /**
980 * @return array
981 */
982 public static function contributeMode() {
983 return [
984 CRM_Core_Payment::BILLING_MODE_FORM => 'direct',
985 CRM_Core_Payment::BILLING_MODE_BUTTON => 'directIPN',
986 CRM_Core_Payment::BILLING_MODE_NOTIFY => 'notify',
987 ];
988 }
989
990 /**
991 * Frequency unit for schedule reminders.
992 *
993 * @param int $count
994 * For pluralization
995 * @return array
996 */
997 public static function getRecurringFrequencyUnits($count = 1) {
998 // @todo this used to refer to the 'recur_frequency_unit' option_values which
999 // is for recurring payments and probably not good to re-use for recurring entities.
1000 // If something other than a hard-coded list is desired, add a new option_group.
1001 return [
1002 'hour' => ts('hour', ['plural' => 'hours', 'count' => $count]),
1003 'day' => ts('day', ['plural' => 'days', 'count' => $count]),
1004 'week' => ts('week', ['plural' => 'weeks', 'count' => $count]),
1005 'month' => ts('month', ['plural' => 'months', 'count' => $count]),
1006 'year' => ts('year', ['plural' => 'years', 'count' => $count]),
1007 ];
1008 }
1009
1010 /**
1011 * Relative Date Terms.
1012 *
1013 * @return array
1014 */
1015 public static function getRelativeDateTerms() {
1016 return [
1017 'previous' => ts('Previous'),
1018 'previous_2' => ts('Previous 2'),
1019 'previous_before' => ts('Prior to Previous'),
1020 'before_previous' => ts('All Prior to Previous'),
1021 'earlier' => ts('To End of Previous'),
1022 'greater_previous' => ts('From End of Previous'),
1023 'greater' => ts('From Start Of Current'),
1024 'current' => ts('Current'),
1025 'ending_3' => ts('Last 3'),
1026 'ending_2' => ts('Last 2'),
1027 'ending' => ts('Last'),
1028 'this' => ts('This'),
1029 'starting' => ts('Upcoming'),
1030 'less' => ts('To End of'),
1031 'next' => ts('Next'),
1032 ];
1033 }
1034
1035 /**
1036 * Relative Date Units.
1037 *
1038 * @return array
1039 */
1040 public static function getRelativeDateUnits() {
1041 return [
1042 'year' => ts('Years'),
1043 'fiscal_year' => ts('Fiscal Years'),
1044 'quarter' => ts('Quarters'),
1045 'month' => ts('Months'),
1046 'week' => ts('Weeks'),
1047 'day' => ts('Days'),
1048 ];
1049 }
1050
1051 /**
1052 * Exportable document formats.
1053 *
1054 * @return array
1055 */
1056 public static function documentFormat() {
1057 return [
1058 'pdf' => ts('Portable Document Format (.pdf)'),
1059 'docx' => ts('MS Word (.docx)'),
1060 'odt' => ts('Open Office (.odt)'),
1061 'html' => ts('Webpage (.html)'),
1062 ];
1063 }
1064
1065 /**
1066 * Application type of document.
1067 *
1068 * @return array
1069 */
1070 public static function documentApplicationType() {
1071 return [
1072 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
1073 'odt' => 'application/vnd.oasis.opendocument.text',
1074 ];
1075 }
1076
1077 /**
1078 * Activity Text options.
1079 *
1080 * @return array
1081 */
1082 public static function activityTextOptions() {
1083 return [
1084 2 => ts('Details Only'),
1085 3 => ts('Subject Only'),
1086 6 => ts('Both'),
1087 ];
1088 }
1089
1090 /**
1091 * Relationship permissions
1092 *
1093 * @return array
1094 */
1095 public static function getPermissionedRelationshipOptions() {
1096 return [
1097 CRM_Contact_BAO_Relationship::NONE => ts('None'),
1098 CRM_Contact_BAO_Relationship::VIEW => ts('View only'),
1099 CRM_Contact_BAO_Relationship::EDIT => ts('View and update'),
1100 ];
1101 }
1102
1103 /**
1104 * Get option values for dashboard entries (used for 'how many events to display on dashboard').
1105 *
1106 * @return array
1107 * Dashboard entries options - in practice [-1 => 'Show All', 10 => 10, 20 => 20, ... 100 => 100].
1108 */
1109 public static function getDashboardEntriesCount() {
1110 $optionValues = [];
1111 $optionValues[-1] = ts('show all');
1112 for ($i = 10; $i <= 100; $i += 10) {
1113 $optionValues[$i] = $i;
1114 }
1115 return $optionValues;
1116 }
1117
1118 /**
1119 * Dropdown options for quicksearch in the menu
1120 *
1121 * @return array
1122 * @throws \CiviCRM_API3_Exception
1123 */
1124 public static function quicksearchOptions() {
1125 $includeEmail = civicrm_api3('setting', 'getvalue', ['name' => 'includeEmailInName', 'group' => 'Search Preferences']);
1126 $options = [
1127 'sort_name' => $includeEmail ? ts('Name/Email') : ts('Name'),
1128 'contact_id' => ts('Contact ID'),
1129 'external_identifier' => ts('External ID'),
1130 'first_name' => ts('First Name'),
1131 'last_name' => ts('Last Name'),
1132 'email' => ts('Email'),
1133 'phone_numeric' => ts('Phone'),
1134 'street_address' => ts('Street Address'),
1135 'city' => ts('City'),
1136 'postal_code' => ts('Postal Code'),
1137 'job_title' => ts('Job Title'),
1138 ];
1139 $custom = civicrm_api3('CustomField', 'get', [
1140 'return' => ['name', 'label', 'custom_group_id.title'],
1141 'custom_group_id.extends' => ['IN' => ['Contact', 'Individual', 'Organization', 'Household']],
1142 'data_type' => ['NOT IN' => ['ContactReference', 'Date', 'File']],
1143 'custom_group_id.is_active' => 1,
1144 'is_active' => 1,
1145 'is_searchable' => 1,
1146 'options' => ['sort' => ['custom_group_id.weight', 'weight'], 'limit' => 0],
1147 ]);
1148 foreach ($custom['values'] as $field) {
1149 $options['custom_' . $field['name']] = $field['custom_group_id.title'] . ': ' . $field['label'];
1150 }
1151 return $options;
1152 }
1153
1154 /**
1155 * Get components (translated for display.
1156 *
1157 * @return array
1158 *
1159 * @throws \Exception
1160 */
1161 public static function getComponentSelectValues() {
1162 $ret = [];
1163 $components = CRM_Core_Component::getComponents();
1164 foreach ($components as $name => $object) {
1165 $ret[$name] = $object->info['translatedName'];
1166 }
1167
1168 return $ret;
1169 }
1170
1171 /**
1172 * @return string[]
1173 */
1174 public static function fieldSerialization() {
1175 return [
1176 CRM_Core_DAO::SERIALIZE_SEPARATOR_BOOKEND => 'separator_bookend',
1177 CRM_Core_DAO::SERIALIZE_SEPARATOR_TRIMMED => 'separator_trimmed',
1178 CRM_Core_DAO::SERIALIZE_JSON => 'json',
1179 CRM_Core_DAO::SERIALIZE_PHP => 'php',
1180 CRM_Core_DAO::SERIALIZE_COMMA => 'comma',
1181 ];
1182 }
1183
1184 /**
1185 * @return array
1186 */
1187 public static function navigationMenuSeparator() {
1188 return [
1189 ts('None'),
1190 ts('After menu element'),
1191 ts('Before menu element'),
1192 ];
1193 }
1194
1195 /**
1196 * @return array
1197 */
1198 public static function relationshipOrientation() {
1199 return [
1200 'a_b' => ts('A to B'),
1201 'b_a' => ts('B to A'),
1202 ];
1203 }
1204
1205 }