3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
12 use Civi\Token\TokenProcessor
;
15 * One place to store frequently used values in Select Elements. Note that
16 * some of the below elements will be dynamic, so we'll probably have a
17 * smart caching scheme on a per domain basis
20 * @copyright CiviCRM LLC https://civicrm.org/licensing
22 class CRM_Core_SelectValues
{
29 public static function boolean() {
37 * Preferred mail format.
41 public static function pmf() {
54 public static function privacy() {
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)'),
66 * Various pre defined contact super types.
70 public static function contactType() {
71 return CRM_Contact_BAO_ContactType
::basicTypePairs();
75 * Various pre defined unit list.
77 * @param string $unitType
80 public static function unitList($unitType = NULL) {
83 'month' => ts('month'),
86 if ($unitType === 'duration') {
87 $unitList['lifetime'] = ts('lifetime');
93 * Membership type unit.
97 public static function membershipTypeUnitList() {
98 return self
::unitList('duration');
102 * Various pre defined period types.
106 public static function periodType() {
108 'rolling' => ts('Rolling'),
109 'fixed' => ts('Fixed'),
114 * Various pre defined email selection methods.
118 public static function emailSelectMethods() {
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'),
128 * Various pre defined member visibility options.
132 public static function memberVisibility() {
134 'Public' => ts('Public'),
135 'Admin' => ts('Admin'),
140 * Member auto-renew options
144 public static function memberAutoRenew() {
146 ts('No auto-renew option'),
147 ts('Give option, but not required'),
148 ts('Auto-renew required'),
153 * Various pre defined event dates.
157 public static function eventDate() {
159 'start_date' => ts('start date'),
160 'end_date' => ts('end date'),
161 'join_date' => ts('member since'),
166 * Custom form field types.
170 public static function customHtmlType() {
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 'RichTextEditor' => ts('Rich Text Editor'),
180 'Autocomplete-Select' => ts('Autocomplete-Select'),
181 'Link' => ts('Link'),
186 * Various pre defined extensions for dynamic properties and groups.
191 public static function customGroupExtends() {
192 $customGroupExtends = [
193 'Activity' => ts('Activities'),
194 'Relationship' => ts('Relationships'),
195 'Contribution' => ts('Contributions'),
196 'ContributionRecur' => ts('Recurring Contributions'),
197 'Group' => ts('Groups'),
198 'Membership' => ts('Memberships'),
199 'Event' => ts('Events'),
200 'Participant' => ts('Participants'),
201 'ParticipantRole' => ts('Participants (Role)'),
202 'ParticipantEventName' => ts('Participants (Event Name)'),
203 'ParticipantEventType' => ts('Participants (Event Type)'),
204 'Pledge' => ts('Pledges'),
205 'Grant' => ts('Grants'),
206 'Address' => ts('Addresses'),
207 'Campaign' => ts('Campaigns'),
209 $contactTypes = ['Contact' => ts('Contacts')] + self
::contactType();
210 $extendObjs = CRM_Core_OptionGroup
::values('cg_extend_objects');
211 $customGroupExtends = array_merge($contactTypes, $customGroupExtends, $extendObjs);
212 return $customGroupExtends;
216 * Styles for displaying the custom data group.
220 public static function customGroupStyle() {
223 'Inline' => ts('Inline'),
224 'Tab with table' => ts('Tab with table'),
229 * For displaying the uf group types.
233 public static function ufGroupTypes() {
235 'Profile' => ts('Standalone Form or Directory'),
236 'Search Profile' => ts('Search Views'),
239 if (CRM_Core_Config
::singleton()->userSystem
->supports_form_extensions
) {
241 'User Registration' => ts('Drupal User Registration'),
242 'User Account' => ts('View/Edit Drupal User Account'),
249 * The status of a contact within a group.
253 public static function groupContactStatus() {
255 'Added' => ts('Added'),
256 'Removed' => ts('Removed'),
257 'Pending' => ts('Pending'),
262 * List of Group Types.
266 public static function groupType() {
268 'query' => ts('Dynamic'),
269 'static' => ts('Static'),
274 * Compose the parameters for a date select object.
276 * @param string|null $type
278 * @param string|null $format
279 * date format (QF format)
280 * @param null $minOffset
281 * @param null $maxOffset
282 * @param string $context
286 * @throws CRM_Core_Exception
288 public static function date($type = NULL, $format = NULL, $minOffset = NULL, $maxOffset = NULL, $context = 'display') {
289 // These options are deprecated. Definitely not used in datepicker. Possibly not even in jcalendar+addDateTime.
291 'addEmptyOption' => TRUE,
292 'emptyOptionText' => ts('- select -'),
293 'emptyOptionValue' => '',
297 $date['format'] = $format;
301 $dao = new CRM_Core_DAO_PreferencesDate();
303 if (!$dao->find(TRUE)) {
304 throw new CRM_Core_Exception('Date preferences not configured.');
307 $maxOffset = $dao->end
;
310 $minOffset = $dao->start
;
313 $date['format'] = $dao->date_format
;
314 $date['time'] = (bool) $dao->time_format
;
317 if (empty($date['format'])) {
318 if ($context === 'Input') {
319 $date['format'] = Civi
::settings()->get('dateInputFormat');
322 $date['format'] = 'M d';
327 $date['smarty_view_format'] = CRM_Utils_Date
::getDateFieldViewFormat($date['format']);
328 if (!isset($date['time'])) {
329 $date['time'] = FALSE;
333 $date['minYear'] = $year - (int) $minOffset;
334 $date['maxYear'] = $year +
(int) $maxOffset;
339 * Values for UF form visibility options.
343 public static function ufVisibility() {
345 'User and User Admin Only' => ts('User and User Admin Only'),
346 'Public Pages' => ts('Expose Publicly'),
347 'Public Pages and Listings' => ts('Expose Publicly and for Listings'),
352 * Values for group form visibility options.
356 public static function groupVisibility() {
358 'User and User Admin Only' => ts('User and User Admin Only'),
359 'Public Pages' => ts('Public Pages'),
364 * Different type of Mailing Components.
368 public static function mailingComponents() {
370 'Header' => ts('Header'),
371 'Footer' => ts('Footer'),
372 'Reply' => ts('Reply Auto-responder'),
373 'OptOut' => ts('Opt-out Message'),
374 'Subscribe' => ts('Subscription Confirmation Request'),
375 'Welcome' => ts('Welcome Message'),
376 'Unsubscribe' => ts('Unsubscribe Message'),
377 'Resubscribe' => ts('Resubscribe Message'),
386 public function getHours() {
388 for ($i = 0; $i <= 6; $i++
) {
399 public function getMinutes() {
401 for ($i = 0; $i < 60; $i = $i +
15) {
408 * Get the Map Provider.
411 * array of map providers
413 public static function mapProvider() {
416 $map = ['' => '- select -'] + CRM_Utils_System
::getPluginList('templates/CRM/Contact/Form/Task/Map', ".tpl");
422 * Get the Geocoding Providers from available plugins.
425 * array of geocoder providers
427 public static function geoProvider() {
430 $geo = ['' => '- select -'] + CRM_Utils_System
::getPluginList('CRM/Utils/Geocode');
436 * Get options for displaying tax.
440 * @throws \CRM_Core_Exception
442 public static function taxDisplayOptions() {
444 'Do_not_show' => ts('Do not show breakdown, only show total - i.e %1', [
445 1 => CRM_Utils_Money
::format(120),
447 'Inclusive' => ts('Show [tax term] inclusive price - i.e. %1', [
448 1 => ts('%1 (includes [tax term] of %2)', [1 => CRM_Utils_Money
::format(120), 2 => CRM_Utils_Money
::format(20)]),
450 'Exclusive' => ts('Show [tax term] exclusive price - i.e. %1', [
451 1 => ts('%1 + %2 [tax term]', [1 => CRM_Utils_Money
::format(120), 2 => CRM_Utils_Money
::format(20)]),
457 * Get the Address Standardization Providers from available plugins.
460 * array of address standardization providers
462 public static function addressProvider() {
465 $addr = array_merge(['' => '- select -'], CRM_Utils_System
::getPluginList('CRM/Utils/Address', '.php', ['BatchUpdate']));
471 * Different type of Mailing Tokens.
475 public static function mailingTokens() {
477 '{action.unsubscribe}' => ts('Unsubscribe via email'),
478 '{action.unsubscribeUrl}' => ts('Unsubscribe via web page'),
479 '{action.resubscribe}' => ts('Resubscribe via email'),
480 '{action.resubscribeUrl}' => ts('Resubscribe via web page'),
481 '{action.optOut}' => ts('Opt out via email'),
482 '{action.optOutUrl}' => ts('Opt out via web page'),
483 '{action.forward}' => ts('Forward this email (link)'),
484 '{action.reply}' => ts('Reply to this email (link)'),
485 '{action.subscribeUrl}' => ts('Subscribe via web page'),
486 '{mailing.key}' => ts('Mailing key'),
487 '{mailing.name}' => ts('Mailing name'),
488 '{mailing.group}' => ts('Mailing group'),
489 '{mailing.viewUrl}' => ts('Mailing permalink'),
490 ] + self
::domainTokens();
500 public static function domainTokens() {
501 $tokenProcessor = new TokenProcessor(Civi
::dispatcher(), []);
502 return $tokenProcessor->listTokens();
506 * Different type of Activity Tokens.
510 public static function activityTokens() {
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'),
520 * Different type of Membership Tokens.
524 public static function membershipTokens(): array {
526 '{membership.id}' => ts('Membership ID'),
527 '{membership.status_id:label}' => ts('Membership Status'),
528 '{membership.membership_type_id:label}' => 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'),
537 * Different type of Event Tokens.
543 public static function eventTokens(): array {
544 $tokenProcessor = new TokenProcessor(Civi
::dispatcher(), ['schema' => ['eventId']]);
545 $allTokens = $tokenProcessor->listTokens();
546 foreach (array_keys($allTokens) as $token) {
547 if (strpos($token, '{domain.') === 0) {
548 unset($allTokens[$token]);
555 * Different type of Contribution Tokens.
561 public static function contributionTokens(): array {
562 $tokenProcessor = new TokenProcessor(Civi
::dispatcher(), ['schema' => ['contributionId']]);
563 $allTokens = $tokenProcessor->listTokens();
564 foreach (array_keys($allTokens) as $token) {
565 if (strpos($token, '{domain.') === 0) {
566 unset($allTokens[$token]);
573 * Different type of Contact Tokens.
579 public static function contactTokens(): array {
580 $tokenProcessor = new TokenProcessor(Civi
::dispatcher(), ['schema' => ['contactId']]);
581 $allTokens = $tokenProcessor->listTokens();
582 foreach (array_keys($allTokens) as $token) {
583 if (strpos($token, '{domain.') === 0) {
584 unset($allTokens[$token]);
591 * Different type of Participant Tokens.
597 public static function participantTokens(): array {
598 $tokenProcessor = new TokenProcessor(Civi
::dispatcher(), ['schema' => ['participantId']]);
599 $allTokens = $tokenProcessor->listTokens();
600 foreach (array_keys($allTokens) as $token) {
601 if (strpos($token, '{domain.') === 0) {
602 unset($allTokens[$token]);
609 * @param int $caseTypeId
612 public static function caseTokens($caseTypeId = NULL) {
613 static $tokens = NULL;
616 '{case.id}' => 'Case ID',
617 '{case.case_type_id:label}' => 'Case Type',
618 '{case.subject}' => 'Case Subject',
619 '{case.start_date}' => 'Case Start Date',
620 '{case.end_date}' => 'Case End Date',
621 '{case.details}' => 'Details',
622 '{case.status_id:label}' => 'Case Status',
623 '{case.is_deleted:label}' => 'Case is in the Trash',
624 '{case.created_date}' => 'Created Date',
625 '{case.modified_date}' => 'Modified Date',
628 $customFields = CRM_Core_BAO_CustomField
::getFields('Case', FALSE, FALSE, $caseTypeId);
629 foreach ($customFields as $id => $field) {
630 $tokens["{case.custom_$id}"] = "{$field['label']} :: {$field['groupTitle']}";
637 * CiviCRM supported date input formats.
641 public static function getDatePluginInputFormats() {
643 'mm/dd/yy' => ts('mm/dd/yy (12/31/2009)'),
644 'dd/mm/yy' => ts('dd/mm/yy (31/12/2009)'),
645 'yy-mm-dd' => ts('yy-mm-dd (2009-12-31)'),
646 'dd-mm-yy' => ts('dd-mm-yy (31-12-2009)'),
647 'dd.mm.yy' => ts('dd.mm.yy (31.12.2009)'),
648 'M d, yy' => ts('M d, yy (Dec 31, 2009)'),
649 'd M yy' => ts('d M yy (31 Dec 2009)'),
650 'MM d, yy' => ts('MM d, yy (December 31, 2009)'),
651 'd MM yy' => ts('d MM yy (31 December 2009)'),
652 'DD, d MM yy' => ts('DD, d MM yy (Thursday, 31 December 2009)'),
653 'mm/dd' => ts('mm/dd (12/31)'),
654 'dd-mm' => ts('dd-mm (31-12)'),
655 'yy-mm' => ts('yy-mm (2009-12)'),
656 'M yy' => ts('M yy (Dec 2009)'),
657 'yy' => ts('yy (2009)'),
666 public static function getTimeFormats() {
668 '1' => ts('12 Hours'),
669 '2' => ts('24 Hours'),
674 * Get numeric options.
681 public static function getNumericOptions($start = 0, $end = 10) {
682 $numericOptions = [];
683 for ($i = $start; $i <= $end; $i++
) {
684 $numericOptions[$i] = $i;
686 return $numericOptions;
694 public static function getBarcodeTypes() {
696 'barcode' => ts('Linear (1D)'),
697 'qrcode' => ts('QR code'),
706 public static function getDedupeRuleTypes() {
708 'Unsupervised' => ts('Unsupervised'),
709 'Supervised' => ts('Supervised'),
710 'General' => ts('General'),
715 * Campaign group types.
719 public static function getCampaignGroupTypes() {
721 'Include' => ts('Include'),
722 'Exclude' => ts('Exclude'),
727 * Subscription history method.
731 public static function getSubscriptionHistoryMethods() {
733 'Admin' => ts('Admin'),
734 'Email' => ts('Email'),
745 public static function getPremiumUnits() {
748 'week' => ts('Week'),
749 'month' => ts('Month'),
750 'year' => ts('Year'),
759 public static function getExtensionTypes() {
761 'payment' => ts('Payment'),
762 'search' => ts('Search'),
763 'report' => ts('Report'),
764 'module' => ts('Module'),
774 public static function getJobFrequency() {
777 'Yearly' => ts('Yearly'),
778 'Quarter' => ts('Quarterly'),
779 'Monthly' => ts('Monthly'),
780 'Weekly' => ts('Weekly'),
782 'Daily' => ts('Daily'),
783 'Hourly' => ts('Hourly'),
784 'Always' => ts('Every time cron job is run'),
789 * Search builder operators.
793 public static function getSearchBuilderOperators() {
802 'NOT IN' => ts('Not In'),
803 'LIKE' => ts('Like'),
804 'NOT LIKE' => ts('Not Like'),
805 'RLIKE' => ts('Regex'),
806 'IS EMPTY' => ts('Is Empty'),
807 'IS NOT EMPTY' => ts('Not Empty'),
808 'IS NULL' => ts('Is Null'),
809 'IS NOT NULL' => ts('Not Null'),
814 * Profile group types.
818 public static function getProfileGroupType() {
819 $profileGroupType = [
820 'Activity' => ts('Activities'),
821 'Contribution' => ts('Contributions'),
822 'Membership' => ts('Memberships'),
823 'Participant' => ts('Participants'),
825 $contactTypes = self
::contactType();
826 $contactTypes = !empty($contactTypes) ?
['Contact' => 'Contacts'] +
$contactTypes : [];
827 $profileGroupType = array_merge($contactTypes, $profileGroupType);
829 return $profileGroupType;
833 * Word replacement match type.
837 public static function getWordReplacementMatchType() {
839 'exactMatch' => ts('Exact Match'),
840 'wildcardMatch' => ts('Wildcard Match'),
845 * Mailing group types.
849 public static function getMailingGroupTypes() {
851 'Include' => ts('Include'),
852 'Exclude' => ts('Exclude'),
853 'Base' => ts('Base'),
858 * Mailing Job Status.
862 public static function getMailingJobStatus() {
864 'Scheduled' => ts('Scheduled'),
865 'Running' => ts('Running'),
866 'Complete' => ts('Complete'),
867 'Paused' => ts('Paused'),
868 'Canceled' => ts('Canceled'),
875 public static function billingMode() {
877 CRM_Core_Payment
::BILLING_MODE_FORM
=> 'form',
878 CRM_Core_Payment
::BILLING_MODE_BUTTON
=> 'button',
879 CRM_Core_Payment
::BILLING_MODE_NOTIFY
=> 'notify',
886 public static function contributeMode() {
888 CRM_Core_Payment
::BILLING_MODE_FORM
=> 'direct',
889 CRM_Core_Payment
::BILLING_MODE_BUTTON
=> 'directIPN',
890 CRM_Core_Payment
::BILLING_MODE_NOTIFY
=> 'notify',
895 * Frequency unit for schedule reminders.
901 public static function getRecurringFrequencyUnits($count = 1) {
902 // @todo this used to refer to the 'recur_frequency_unit' option_values which
903 // is for recurring payments and probably not good to re-use for recurring entities.
904 // If something other than a hard-coded list is desired, add a new option_group.
906 'hour' => ts('hour', ['plural' => 'hours', 'count' => $count]),
907 'day' => ts('day', ['plural' => 'days', 'count' => $count]),
908 'week' => ts('week', ['plural' => 'weeks', 'count' => $count]),
909 'month' => ts('month', ['plural' => 'months', 'count' => $count]),
910 'year' => ts('year', ['plural' => 'years', 'count' => $count]),
915 * Relative Date Terms.
919 public static function getRelativeDateTerms() {
921 'previous' => ts('Previous'),
922 'previous_2' => ts('Previous 2'),
923 'previous_before' => ts('Prior to Previous'),
924 'before_previous' => ts('All Prior to Previous'),
925 'earlier' => ts('To End of Previous'),
926 'greater_previous' => ts('From End of Previous'),
927 'greater' => ts('From Start Of Current'),
928 'current' => ts('Current'),
929 'ending_3' => ts('Last 3'),
930 'ending_2' => ts('Last 2'),
931 'ending' => ts('Last'),
932 'this' => ts('This'),
933 'starting' => ts('Upcoming'),
934 'less' => ts('To End of'),
935 'next' => ts('Next'),
940 * Relative Date Units.
944 public static function getRelativeDateUnits() {
946 'year' => ts('Years'),
947 'fiscal_year' => ts('Fiscal Years'),
948 'quarter' => ts('Quarters'),
949 'month' => ts('Months'),
950 'week' => ts('Weeks'),
956 * Exportable document formats.
960 public static function documentFormat() {
962 'pdf' => ts('Portable Document Format (.pdf)'),
963 'docx' => ts('MS Word (.docx)'),
964 'odt' => ts('Open Office (.odt)'),
965 'html' => ts('Webpage (.html)'),
970 * Application type of document.
974 public static function documentApplicationType() {
976 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
977 'odt' => 'application/vnd.oasis.opendocument.text',
982 * Activity Text options.
986 public static function activityTextOptions() {
988 2 => ts('Details Only'),
989 3 => ts('Subject Only'),
995 * Relationship permissions
999 public static function getPermissionedRelationshipOptions() {
1001 CRM_Contact_BAO_Relationship
::NONE
=> ts('None'),
1002 CRM_Contact_BAO_Relationship
::VIEW
=> ts('View only'),
1003 CRM_Contact_BAO_Relationship
::EDIT
=> ts('View and update'),
1008 * Get option values for dashboard entries (used for 'how many events to display on dashboard').
1011 * Dashboard entries options - in practice [-1 => 'Show All', 10 => 10, 20 => 20, ... 100 => 100].
1013 public static function getDashboardEntriesCount() {
1015 $optionValues[-1] = ts('show all');
1016 for ($i = 10; $i <= 100; $i +
= 10) {
1017 $optionValues[$i] = $i;
1019 return $optionValues;
1023 * Dropdown options for quicksearch in the menu
1026 * @throws \CiviCRM_API3_Exception
1028 public static function quicksearchOptions() {
1029 $includeEmail = civicrm_api3('setting', 'getvalue', ['name' => 'includeEmailInName', 'group' => 'Search Preferences']);
1031 'sort_name' => $includeEmail ?
ts('Name/Email') : ts('Name'),
1032 'contact_id' => ts('Contact ID'),
1033 'external_identifier' => ts('External ID'),
1034 'first_name' => ts('First Name'),
1035 'last_name' => ts('Last Name'),
1036 'email' => ts('Email'),
1037 'phone_numeric' => ts('Phone'),
1038 'street_address' => ts('Street Address'),
1039 'city' => ts('City'),
1040 'postal_code' => ts('Postal Code'),
1041 'job_title' => ts('Job Title'),
1043 $custom = civicrm_api3('CustomField', 'get', [
1044 'return' => ['name', 'label', 'custom_group_id.title'],
1045 'custom_group_id.extends' => ['IN' => ['Contact', 'Individual', 'Organization', 'Household']],
1046 'data_type' => ['NOT IN' => ['ContactReference', 'Date', 'File']],
1047 'custom_group_id.is_active' => 1,
1049 'is_searchable' => 1,
1050 'options' => ['sort' => ['custom_group_id.weight', 'weight'], 'limit' => 0],
1052 foreach ($custom['values'] as $field) {
1053 $options['custom_' . $field['name']] = $field['custom_group_id.title'] . ': ' . $field['label'];
1059 * Get components (translated for display.
1063 * @throws \Exception
1065 public static function getComponentSelectValues() {
1067 $components = CRM_Core_Component
::getComponents();
1068 foreach ($components as $name => $object) {
1069 $ret[$name] = $object->info
['translatedName'];
1078 public static function fieldSerialization() {
1080 CRM_Core_DAO
::SERIALIZE_SEPARATOR_BOOKEND
=> 'separator_bookend',
1081 CRM_Core_DAO
::SERIALIZE_SEPARATOR_TRIMMED
=> 'separator_trimmed',
1082 CRM_Core_DAO
::SERIALIZE_JSON
=> 'json',
1083 CRM_Core_DAO
::SERIALIZE_PHP
=> 'php',
1084 CRM_Core_DAO
::SERIALIZE_COMMA
=> 'comma',
1091 public static function navigationMenuSeparator() {
1094 ts('After menu element'),
1095 ts('Before menu element'),
1102 public static function relationshipOrientation() {
1104 'a_b' => ts('A to B'),
1105 'b_a' => ts('B to A'),