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