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