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