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