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