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