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