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