Merge pull request #15558 from eileenmcnaughton/report_page519
[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 return [
734 "mm/dd/yy" => ts('mm/dd/yyyy (12/31/2009)'),
735 "dd/mm/yy" => ts('dd/mm/yyyy (31/12/2009)'),
736 "yy-mm-dd" => ts('yyyy-mm-dd (2009-12-31)'),
737 "dd-mm-yy" => ts('dd-mm-yyyy (31-12-2009)'),
738 'dd.mm.yy' => ts('dd.mm.yyyy (31.12.2009)'),
739 "M d, yy" => ts('M d, yyyy (Dec 31, 2009)'),
740 'd M yy' => ts('d M yyyy (31 Dec 2009)'),
741 "MM d, yy" => ts('MM d, yyyy (December 31, 2009)'),
742 'd MM yy' => ts('d MM yyyy (31 December 2009)'),
743 "DD, d MM yy" => ts('DD, d MM yyyy (Thursday, 31 December 2009)'),
744 "mm/dd" => ts('mm/dd (12/31)'),
745 "dd-mm" => ts('dd-mm (31-12)'),
746 "yy-mm" => ts('yyyy-mm (2009-12)'),
747 'M yy' => ts('M yyyy (Dec 2009)'),
748 "yy" => ts('yyyy (2009)'),
749 ];
750 }
751
752 /**
753 * Time formats.
754 *
755 * @return array
756 */
757 public static function getTimeFormats() {
758 return [
759 '1' => ts('12 Hours'),
760 '2' => ts('24 Hours'),
761 ];
762 }
763
764 /**
765 * Get numeric options.
766 *
767 * @param int $start
768 * @param int $end
769 *
770 * @return array
771 */
772 public static function getNumericOptions($start = 0, $end = 10) {
773 $numericOptions = [];
774 for ($i = $start; $i <= $end; $i++) {
775 $numericOptions[$i] = $i;
776 }
777 return $numericOptions;
778 }
779
780 /**
781 * Barcode types.
782 *
783 * @return array
784 */
785 public static function getBarcodeTypes() {
786 return [
787 'barcode' => ts('Linear (1D)'),
788 'qrcode' => ts('QR code'),
789 ];
790 }
791
792 /**
793 * Dedupe rule types.
794 *
795 * @return array
796 */
797 public static function getDedupeRuleTypes() {
798 return [
799 'Unsupervised' => ts('Unsupervised'),
800 'Supervised' => ts('Supervised'),
801 'General' => ts('General'),
802 ];
803 }
804
805 /**
806 * Campaign group types.
807 *
808 * @return array
809 */
810 public static function getCampaignGroupTypes() {
811 return [
812 'Include' => ts('Include'),
813 'Exclude' => ts('Exclude'),
814 ];
815 }
816
817 /**
818 * Subscription history method.
819 *
820 * @return array
821 */
822 public static function getSubscriptionHistoryMethods() {
823 return [
824 'Admin' => ts('Admin'),
825 'Email' => ts('Email'),
826 'Web' => ts('Web'),
827 'API' => ts('API'),
828 ];
829 }
830
831 /**
832 * Premium units.
833 *
834 * @return array
835 */
836 public static function getPremiumUnits() {
837 return [
838 'day' => ts('Day'),
839 'week' => ts('Week'),
840 'month' => ts('Month'),
841 'year' => ts('Year'),
842 ];
843 }
844
845 /**
846 * Extension types.
847 *
848 * @return array
849 */
850 public static function getExtensionTypes() {
851 return [
852 'payment' => ts('Payment'),
853 'search' => ts('Search'),
854 'report' => ts('Report'),
855 'module' => ts('Module'),
856 'sms' => ts('SMS'),
857 ];
858 }
859
860 /**
861 * Job frequency.
862 *
863 * @return array
864 */
865 public static function getJobFrequency() {
866 return [
867 // CRM-17669
868 'Yearly' => ts('Yearly'),
869 'Quarter' => ts('Quarterly'),
870 'Monthly' => ts('Monthly'),
871 'Weekly' => ts('Weekly'),
872
873 'Daily' => ts('Daily'),
874 'Hourly' => ts('Hourly'),
875 'Always' => ts('Every time cron job is run'),
876 ];
877 }
878
879 /**
880 * Search builder operators.
881 *
882 * @return array
883 */
884 public static function getSearchBuilderOperators($fieldType = NULL) {
885 return [
886 '=' => '=',
887 '!=' => '≠',
888 '>' => '>',
889 '<' => '<',
890 '>=' => '≥',
891 '<=' => '≤',
892 'IN' => ts('In'),
893 'NOT IN' => ts('Not In'),
894 'LIKE' => ts('Like'),
895 'NOT LIKE' => ts('Not Like'),
896 'RLIKE' => ts('Regex'),
897 'IS EMPTY' => ts('Is Empty'),
898 'IS NOT EMPTY' => ts('Not Empty'),
899 'IS NULL' => ts('Is Null'),
900 'IS NOT NULL' => ts('Not Null'),
901 ];
902 }
903
904 /**
905 * Profile group types.
906 *
907 * @return array
908 */
909 public static function getProfileGroupType() {
910 $profileGroupType = [
911 'Activity' => ts('Activities'),
912 'Contribution' => ts('Contributions'),
913 'Membership' => ts('Memberships'),
914 'Participant' => ts('Participants'),
915 ];
916 $contactTypes = self::contactType();
917 $contactTypes = !empty($contactTypes) ? ['Contact' => 'Contacts'] + $contactTypes : [];
918 $profileGroupType = array_merge($contactTypes, $profileGroupType);
919
920 return $profileGroupType;
921 }
922
923 /**
924 * Word replacement match type.
925 *
926 * @return array
927 */
928 public static function getWordReplacementMatchType() {
929 return [
930 'exactMatch' => ts('Exact Match'),
931 'wildcardMatch' => ts('Wildcard Match'),
932 ];
933 }
934
935 /**
936 * Mailing group types.
937 *
938 * @return array
939 */
940 public static function getMailingGroupTypes() {
941 return [
942 'Include' => ts('Include'),
943 'Exclude' => ts('Exclude'),
944 'Base' => ts('Base'),
945 ];
946 }
947
948 /**
949 * Mailing Job Status.
950 *
951 * @return array
952 */
953 public static function getMailingJobStatus() {
954 return [
955 'Scheduled' => ts('Scheduled'),
956 'Running' => ts('Running'),
957 'Complete' => ts('Complete'),
958 'Paused' => ts('Paused'),
959 'Canceled' => ts('Canceled'),
960 ];
961 }
962
963 /**
964 * @return array
965 */
966 public static function billingMode() {
967 return [
968 CRM_Core_Payment::BILLING_MODE_FORM => 'form',
969 CRM_Core_Payment::BILLING_MODE_BUTTON => 'button',
970 CRM_Core_Payment::BILLING_MODE_NOTIFY => 'notify',
971 ];
972 }
973
974 /**
975 * @return array
976 */
977 public static function contributeMode() {
978 return [
979 CRM_Core_Payment::BILLING_MODE_FORM => 'direct',
980 CRM_Core_Payment::BILLING_MODE_BUTTON => 'directIPN',
981 CRM_Core_Payment::BILLING_MODE_NOTIFY => 'notify',
982 ];
983 }
984
985 /**
986 * Frequency unit for schedule reminders.
987 *
988 * @param int $count
989 * For pluralization
990 * @return array
991 */
992 public static function getRecurringFrequencyUnits($count = 1) {
993 // @todo this used to refer to the 'recur_frequency_unit' option_values which
994 // is for recurring payments and probably not good to re-use for recurring entities.
995 // If something other than a hard-coded list is desired, add a new option_group.
996 return [
997 'hour' => ts('hour', ['plural' => 'hours', 'count' => $count]),
998 'day' => ts('day', ['plural' => 'days', 'count' => $count]),
999 'week' => ts('week', ['plural' => 'weeks', 'count' => $count]),
1000 'month' => ts('month', ['plural' => 'months', 'count' => $count]),
1001 'year' => ts('year', ['plural' => 'years', 'count' => $count]),
1002 ];
1003 }
1004
1005 /**
1006 * Relative Date Terms.
1007 *
1008 * @return array
1009 */
1010 public static function getRelativeDateTerms() {
1011 return [
1012 'previous' => ts('Previous'),
1013 'previous_2' => ts('Previous 2'),
1014 'previous_before' => ts('Prior to Previous'),
1015 'before_previous' => ts('All Prior to Previous'),
1016 'earlier' => ts('To End of Previous'),
1017 'greater_previous' => ts('From End of Previous'),
1018 'greater' => ts('From Start Of Current'),
1019 'current' => ts('Current'),
1020 'ending_3' => ts('Last 3'),
1021 'ending_2' => ts('Last 2'),
1022 'ending' => ts('Last'),
1023 'this' => ts('This'),
1024 'starting' => ts('Upcoming'),
1025 'less' => ts('To End of'),
1026 'next' => ts('Next'),
1027 ];
1028 }
1029
1030 /**
1031 * Relative Date Units.
1032 *
1033 * @return array
1034 */
1035 public static function getRelativeDateUnits() {
1036 return [
1037 'year' => ts('Years'),
1038 'fiscal_year' => ts('Fiscal Years'),
1039 'quarter' => ts('Quarters'),
1040 'month' => ts('Months'),
1041 'week' => ts('Weeks'),
1042 'day' => ts('Days'),
1043 ];
1044 }
1045
1046 /**
1047 * Exportable document formats.
1048 *
1049 * @return array
1050 */
1051 public static function documentFormat() {
1052 return [
1053 'pdf' => ts('Portable Document Format (.pdf)'),
1054 'docx' => ts('MS Word (.docx)'),
1055 'odt' => ts('Open Office (.odt)'),
1056 'html' => ts('Webpage (.html)'),
1057 ];
1058 }
1059
1060 /**
1061 * Application type of document.
1062 *
1063 * @return array
1064 */
1065 public static function documentApplicationType() {
1066 return [
1067 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
1068 'odt' => 'application/vnd.oasis.opendocument.text',
1069 ];
1070 }
1071
1072 /**
1073 * Activity Text options.
1074 *
1075 * @return array
1076 */
1077 public static function activityTextOptions() {
1078 return [
1079 2 => ts('Details Only'),
1080 3 => ts('Subject Only'),
1081 6 => ts('Both'),
1082 ];
1083 }
1084
1085 /**
1086 * Relationship permissions
1087 *
1088 * @return array
1089 */
1090 public static function getPermissionedRelationshipOptions() {
1091 return [
1092 CRM_Contact_BAO_Relationship::NONE => ts('None'),
1093 CRM_Contact_BAO_Relationship::VIEW => ts('View only'),
1094 CRM_Contact_BAO_Relationship::EDIT => ts('View and update'),
1095 ];
1096 }
1097
1098 /**
1099 * Get option values for dashboard entries (used for 'how many events to display on dashboard').
1100 *
1101 * @return array
1102 * Dashboard entries options - in practice [-1 => 'Show All', 10 => 10, 20 => 20, ... 100 => 100].
1103 */
1104 public static function getDashboardEntriesCount() {
1105 $optionValues = [];
1106 $optionValues[-1] = ts('show all');
1107 for ($i = 10; $i <= 100; $i += 10) {
1108 $optionValues[$i] = $i;
1109 }
1110 return $optionValues;
1111 }
1112
1113 /**
1114 * Dropdown options for quicksearch in the menu
1115 *
1116 * @return array
1117 */
1118 public static function quicksearchOptions() {
1119 $includeEmail = civicrm_api3('setting', 'getvalue', ['name' => 'includeEmailInName', 'group' => 'Search Preferences']);
1120 $options = [
1121 'sort_name' => $includeEmail ? ts('Name/Email') : ts('Name'),
1122 'contact_id' => ts('Contact ID'),
1123 'external_identifier' => ts('External ID'),
1124 'first_name' => ts('First Name'),
1125 'last_name' => ts('Last Name'),
1126 'email' => ts('Email'),
1127 'phone_numeric' => ts('Phone'),
1128 'street_address' => ts('Street Address'),
1129 'city' => ts('City'),
1130 'postal_code' => ts('Postal Code'),
1131 'job_title' => ts('Job Title'),
1132 ];
1133 $custom = civicrm_api3('CustomField', 'get', [
1134 'return' => ['name', 'label', 'custom_group_id.title'],
1135 'custom_group_id.extends' => ['IN' => ['Contact', 'Individual', 'Organization', 'Household']],
1136 'data_type' => ['NOT IN' => ['ContactReference', 'Date', 'File']],
1137 'custom_group_id.is_active' => 1,
1138 'is_active' => 1,
1139 'is_searchable' => 1,
1140 'options' => ['sort' => ['custom_group_id.weight', 'weight'], 'limit' => 0],
1141 ]);
1142 foreach ($custom['values'] as $field) {
1143 $options['custom_' . $field['name']] = $field['custom_group_id.title'] . ': ' . $field['label'];
1144 }
1145 return $options;
1146 }
1147
1148 /**
1149 * Get components (translated for display.
1150 *
1151 * @return array
1152 *
1153 * @throws \Exception
1154 */
1155 public static function getComponentSelectValues() {
1156 $ret = [];
1157 $components = CRM_Core_Component::getComponents();
1158 foreach ($components as $name => $object) {
1159 $ret[$name] = $object->info['translatedName'];
1160 }
1161
1162 return $ret;
1163 }
1164
1165 }