Merge pull request #2666 from kurund/test-fixes
[civicrm-core.git] / CRM / Core / SelectValues.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
35 * $Id$
36 *
37 */
38 class CRM_Core_SelectValues {
39
40 /**CRM/Core/SelectValues.php
41 * different types of phones
42 * @static
43 */
44 static function &phoneType() {
45 static $phoneType = NULL;
46 if (!$phoneType) {
47 $phoneType = array(
48 '' => ts('- select -'),
49 'Phone' => ts('Phone'),
50 'Mobile' => ts('Mobile'),
51 'Fax' => ts('Fax'),
52 'Pager' => ts('Pager'),
53 );
54 }
55 return $phoneType;
56 }
57
58 /**
59 * preferred mail format
60 * @static
61 */
62 static function &pmf() {
63 static $pmf = NULL;
64 if (!$pmf) {
65 $pmf = array(
66 'Both' => ts('Both'),
67 'HTML' => ts('HTML'),
68 'Text' => ts('Text'),
69 );
70 }
71 return $pmf;
72 }
73
74 /**
75 * privacy options
76 * @static
77 */
78 static function &privacy() {
79 static $privacy = NULL;
80 if (!$privacy) {
81 $privacy = array(
82 'do_not_phone' => ts('Do not phone'),
83 'do_not_email' => ts('Do not email'),
84 'do_not_mail' => ts('Do not mail'),
85 'do_not_sms' => ts('Do not sms'),
86 'do_not_trade' => ts('Do not trade'),
87 'is_opt_out' => ts('No bulk emails (User Opt Out)'),
88 );
89 }
90 return $privacy;
91 }
92
93 /**
94 * various pre defined contact super types
95 * @static
96 */
97 static function &contactType() {
98 static $contactType = NULL;
99 if (!$contactType) {
100 $contactType = CRM_Contact_BAO_ContactType::basicTypePairs();
101 }
102 return $contactType;
103 }
104
105 /**
106 * various pre defined unit list
107 * @static
108 */
109 static function &unitList($unitType = NULL) {
110 static $unitList = NULL;
111 if (!$unitList) {
112 $unitList = array(
113 '' => ts('- select -'),
114 'day' => ts('day'),
115 'month' => ts('month'),
116 'year' => ts('year'),
117 );
118 if ($unitType == 'duration') {
119 $unitAdd = array(
120 'lifetime' => ts('lifetime'),
121 );
122 $unitList = array_merge($unitList, $unitAdd);
123 }
124 }
125 return $unitList;
126 }
127
128 /**
129 * membership type unit
130 * @static
131 */
132 static function membershipTypeUnitList( ) {
133 static $membershipTypeUnitList = NULL;
134 if (!$membershipTypeUnitList) {
135 $membershipTypeUnitList = self::unitList('duration');
136 }
137 return $membershipTypeUnitList;
138 }
139
140 /**
141 * various pre defined period types
142 * @static
143 */
144 static function &periodType() {
145 static $periodType = NULL;
146 if (!$periodType) {
147 $periodType = array(
148 '' => ts('- select -'),
149 'rolling' => ts('Rolling'),
150 'fixed' => ts('Fixed'),
151 );
152 }
153 return $periodType;
154 }
155
156 /**
157 * various pre defined member visibility options
158 * @static
159 */
160 static function &memberVisibility() {
161 static $visible = NULL;
162 if (!$visible) {
163 $visible = array(
164 'Public' => ts('Public'),
165 'Admin' => ts('Admin'),
166 );
167 }
168 return $visible;
169 }
170
171 /**
172 * various pre defined event dates
173 * @static
174 */
175 static function &eventDate() {
176 static $eventDate = NULL;
177 if (!$eventDate) {
178 $eventDate = array(
179 '' => ts('- select -'),
180 'start_date' => ts('start date'),
181 'end_date' => ts('end date'),
182 'join_date' => ts('member since'),
183 );
184 }
185 return $eventDate;
186 }
187
188 /**
189 * Custom form field types
190 * @static
191 */
192 static function &customHtmlType() {
193 static $customHtmlType = NULL;
194 if (!$customHtmlType) {
195 $customHtmlType = array(
196 '' => ts('- select -'),
197 'Text' => ts('Single-line input field (text or numeric)'),
198 'TextArea' => ts('Multi-line text box (textarea)'),
199 'Select' => ts('Drop-down (select list)'),
200 'Radio' => ts('Radio buttons'),
201 'CheckBox' => ts('Checkbox(es)'),
202 'Date' => ts('Select Date'),
203 'File' => ts('File'),
204 'StateProvince' => ts('Select State/Province'),
205 'Country' => ts('Select Country'),
206 'RichTextEditor' => ts('Rich Text Editor'),
207 'Autocomplete-Select' => ts('Autocomplete-Select'),
208 'Multi-Select' => ts('Multi-Select'),
209 'AdvMulti-Select' => ts('AdvMulti-Select'),
210 'Link' => ts('Link'),
211 'ContactReference' => ts('Autocomplete Select'),
212 );
213 }
214 return $customHtmlType;
215 }
216
217 /**
218 * various pre defined extensions for dynamic properties and groups
219 *
220 * @static
221 */
222 static function &customGroupExtends() {
223 static $customGroupExtends = NULL;
224 if (!$customGroupExtends) {
225 $customGroupExtends = array(
226 'Activity' => ts('Activities'),
227 'Relationship' => ts('Relationships'),
228 'Contribution' => ts('Contributions'),
229 'Group' => ts('Groups'),
230 'Membership' => ts('Memberships'),
231 'Event' => ts('Events'),
232 'Participant' => ts('Participants'),
233 'ParticipantRole' => ts('Participants (Role)'),
234 'ParticipantEventName' => ts('Participants (Event Name)'),
235 'ParticipantEventType' => ts('Participants (Event Type)'),
236 'Pledge' => ts('Pledges'),
237 'Grant' => ts('Grants'),
238 'Address' => ts('Addresses'),
239 'Campaign' => ts('Campaigns'),
240 );
241 $contactTypes = self::contactType();
242 $contactTypes = !empty($contactTypes) ? array('Contact' => 'Contacts') + $contactTypes : array();
243 $extendObjs = CRM_Core_OptionGroup::values('cg_extend_objects');
244 $customGroupExtends = array_merge($contactTypes, $customGroupExtends, $extendObjs);
245 }
246 return $customGroupExtends;
247 }
248
249 /**
250 * styles for displaying the custom data group
251 *
252 * @static
253 */
254 static function &customGroupStyle() {
255 static $customGroupStyle = NULL;
256 if (!$customGroupStyle) {
257 $customGroupStyle = array(
258 'Tab' => ts('Tab'),
259 'Inline' => ts('Inline'),
260 'Tab with table' => ts('Tab with table'),
261 );
262 }
263 return $customGroupStyle;
264 }
265
266 /**
267 * for displaying the uf group types
268 *
269 * @static
270 */
271 static function &ufGroupTypes() {
272 static $ufGroupType = NULL;
273 if (!$ufGroupType) {
274 $ufGroupType = array(
275 'Profile' => ts('Standalone Form or Directory'),
276 'Search Profile' => ts('Search Views'),
277 );
278 $config = CRM_Core_Config::singleton();
279 if ($config->userSystem->supports_form_extensions) {
280 $ufGroupType += array(
281 'User Registration' => ts('Drupal User Registration'),
282 'User Account' => ts('View/Edit Drupal User Account'),
283 );
284 }
285 }
286 return $ufGroupType;
287 }
288
289 /**
290 * the status of a contact within a group
291 *
292 * @static
293 */
294 static function &groupContactStatus() {
295 static $groupContactStatus = NULL;
296 if (!$groupContactStatus) {
297 $groupContactStatus = array(
298 'Added' => ts('Added'),
299 'Removed' => ts('Removed'),
300 'Pending' => ts('Pending'),
301 );
302 }
303 return $groupContactStatus;
304 }
305
306 /**
307 * list of Group Types
308 * @static
309 */
310 static function &groupType() {
311 static $groupType = NULL;
312 if (!$groupType) {
313 $groupType = array(
314 'query' => ts('Dynamic'),
315 'static' => ts('Static'),
316 );
317 }
318 return $groupType;
319 }
320
321 /**
322 * compose the parameters for a date select object
323 *
324 * @param $type the type of date
325 * @param $format date format ( QF format)
326 *
327 * @return array the date array
328 * @static
329 */
330 static function &date($type = NULL, $format = NULL, $minOffset = NULL, $maxOffset = NULL) {
331
332 $date = array(
333 'addEmptyOption' => TRUE,
334 'emptyOptionText' => ts('- select -'),
335 'emptyOptionValue' => '',
336 );
337
338 if ($format) {
339 $date['format'] = $format;
340 }
341 else {
342 if ($type) {
343 $dao = new CRM_Core_DAO_PreferencesDate();
344 $dao->name = $type;
345 if (!$dao->find(TRUE)) {
346 CRM_Core_Error::fatal();
347 }
348 }
349
350 if ($type == 'creditCard') {
351 $minOffset = $dao->start;
352 $maxOffset = $dao->end;
353 $date['format'] = $dao->date_format;
354 $date['addEmptyOption'] = TRUE;
355 $date['emptyOptionText'] = ts('- select -');
356 $date['emptyOptionValue'] = '';
357 }
358
359 if (empty($date['format'])) {
360 $date['format'] = 'M d';
361 }
362 }
363
364 $year = date('Y');
365 $date['minYear'] = $year - $minOffset;
366 $date['maxYear'] = $year + $maxOffset;
367 return $date;
368 }
369
370 /**
371 * values for UF form visibility options
372 *
373 * @static
374 */
375 static function ufVisibility($isGroup = FALSE) {
376 $key = 'uf';
377 if ($isGroup) {
378 $key = 'group';
379 }
380
381 if (!$_visibility) {
382 static $_visibility = array();
383 }
384
385 if (!isset($_visibility[$key])) {
386 $_visibility[$key] = array(
387 'User and User Admin Only' => ts('User and User Admin Only'),
388 'Public Pages' => ts('Public Pages'),
389 'Public Pages and Listings' => ts('Public Pages and Listings'),
390 );
391 if ($isGroup) {
392 unset($_visibility[$key]['Public Pages and Listings']);
393 }
394 }
395 return $_visibility[$key];
396 }
397
398 /**
399 * values for group form visibility options
400 *
401 * @static
402 */
403 static function groupVisibility() {
404 static $_groupVisibility = NULL;
405 if (!$_groupVisibility) {
406 $_groupVisibility = self::ufVisibility(true);
407 }
408 return $_groupVisibility;
409 }
410
411 /**
412 * different type of Mailing Components
413 *
414 * @static
415 * return array
416 */
417 static function &mailingComponents() {
418 static $components = NULL;
419
420 if (!$components) {
421 $components = array('Header' => ts('Header'),
422 'Footer' => ts('Footer'),
423 'Reply' => ts('Reply Auto-responder'),
424 'OptOut' => ts('Opt-out Message'),
425 'Subscribe' => ts('Subscription Confirmation Request'),
426 'Welcome' => ts('Welcome Message'),
427 'Unsubscribe' => ts('Unsubscribe Message'),
428 'Resubscribe' => ts('Resubscribe Message'),
429 );
430 }
431 return $components;
432 }
433
434 /**
435 * Function to get hours
436 *
437 *
438 * @static
439 */
440 function getHours() {
441 for ($i = 0; $i <= 6; $i++) {
442 $hours[$i] = $i;
443 }
444 return $hours;
445 }
446
447 /**
448 * Function to get minutes
449 *
450 *
451 * @static
452 */
453 function getMinutes() {
454 for ($i = 0; $i < 60; $i = $i + 15) {
455 $minutes[$i] = $i;
456 }
457 return $minutes;
458 }
459
460 /**
461 * Function to get the Map Provider
462 *
463 * @return array $map array of map providers
464 * @static
465 */
466 static function mapProvider() {
467 static $map = NULL;
468 if (!$map) {
469 return CRM_Utils_System::getPluginList('templates/CRM/Contact/Form/Task/Map', ".tpl");
470 }
471 return $map;
472 }
473
474 /**
475 * Function to get the Geocoding Providers from available plugins
476 *
477 * @return array $geo array of geocoder providers
478 * @static
479 */
480 static function geoProvider() {
481 static $geo = NULL;
482 if (!$geo) {
483 return CRM_Utils_System::getPluginList('CRM/Utils/Geocode');
484 }
485 return $geo;
486 }
487
488 /**
489 * Function to get the Address Standardization Providers from available
490 * plugins
491 *
492 * @return array $addr array of address standardization providers
493 * @static
494 */
495 static function addressProvider() {
496 static $addr = NULL;
497 if (!$addr) {
498 return CRM_Utils_System::getPluginList('CRM/Utils/Address',
499 '.php',
500 array('BatchUpdate')
501 );
502 }
503 return $addr;
504 }
505
506 /**
507 * different type of Mailing Tokens
508 *
509 * @static
510 * return array
511 */
512 static function &mailingTokens() {
513 static $tokens = NULL;
514
515 if (!$tokens) {
516 $tokens = array('{action.unsubscribe}' => ts('Unsubscribe via email'),
517 '{action.unsubscribeUrl}' => ts('Unsubscribe via web page'),
518 '{action.resubscribe}' => ts('Resubscribe via email'),
519 '{action.resubscribeUrl}' => ts('Resubscribe via web page'),
520 '{action.optOut}' => ts('Opt out via email'),
521 '{action.optOutUrl}' => ts('Opt out via web page'),
522 '{action.forward}' => ts('Forward this email (link)'),
523 '{action.reply}' => ts('Reply to this email (link)'),
524 '{action.subscribeUrl}' => ts('Subscribe via web page'),
525 '{domain.name}' => ts('Domain name'),
526 '{domain.address}' => ts('Domain (organization) address'),
527 '{domain.phone}' => ts('Domain (organization) phone'),
528 '{domain.email}' => ts('Domain (organization) email'),
529 '{mailing.name}' => ts('Mailing name'),
530 '{mailing.group}' => ts('Mailing group'),
531 '{mailing.viewUrl}' => ts('Mailing permalink'),
532 );
533 }
534 return $tokens;
535 }
536
537 /**
538 * different type of Activity Tokens
539 *
540 * @static
541 * return array
542 */
543 static function &activityTokens() {
544 static $tokens = NULL;
545
546 if (!$tokens) {
547 $tokens = array(
548 '{activity.activity_id}' => ts('Activity ID'),
549 '{activity.subject}' => ts('Activity Subject'),
550 '{activity.details}' => ts('Activity Details'),
551 '{activity.activity_date_time}' => ts('Activity Date Time'),
552 );
553 }
554 return $tokens;
555 }
556
557 /**
558 * different type of Membership Tokens
559 *
560 * @static
561 * return array
562 */
563 static function &membershipTokens() {
564 static $tokens = NULL;
565
566 if (!$tokens) {
567 $tokens = array(
568 '{membership.id}' => ts('Membership ID'),
569 '{membership.status}' => ts('Membership Status'),
570 '{membership.type}' => ts('Membership Type'),
571 '{membership.start_date}' => ts('Membership Start Date'),
572 '{membership.join_date}' => ts('Membership Join Date'),
573 '{membership.end_date}' => ts('Membership End Date'),
574 '{membership.fee}' => ts('Membership Fee'),
575 );
576 }
577 return $tokens;
578 }
579
580 /**
581 * different type of Event Tokens
582 *
583 * @static
584 * return array
585 */
586 static function &eventTokens() {
587 static $tokens = NULL;
588
589 if (!$tokens) {
590 $tokens = array(
591 '{event.event_id}' => ts('Event ID'),
592 '{event.title}' => ts('Event Title'),
593 '{event.start_date}' => ts('Event Start Date'),
594 '{event.end_date}' => ts('Event End Date'),
595 '{event.event_type}' => ts('Event Type'),
596 '{event.summary}' => ts('Event Summary'),
597 '{event.description}' => ts('Event Description'),
598 '{event.contact_email}' => ts('Event Contact Email'),
599 '{event.contact_phone}' => ts('Event Contact Phone'),
600 '{event.location}' => ts('Event Location'),
601 '{event.description}' => ts('Event Description'),
602 '{event.location}' => ts('Event Location'),
603 '{event.fee_amount}' => ts('Event Fees'),
604 '{event.info_url}' => ts('Event Info URL'),
605 '{event.registration_url}' => ts('Event Registration URL'),
606 '{event.balance}' => ts('Event Balance')
607 );
608 }
609 return $tokens;
610 }
611
612 /**
613 * different type of Event Tokens
614 *
615 * @static
616 * return array
617 */
618 static function &contributionTokens() {
619 static $tokens = NULL;
620
621 if (!$tokens) {
622 $tokens = array(
623 '{contribution.contribution_id}' => ts('Contribution ID'),
624 '{contribution.total_amount}' => ts('Total Amount'),
625 '{contribution.fee_amount}' => ts('Fee Amount'),
626 '{contribution.net_amount}' => ts('Net Amount'),
627 '{contribution.non_deductible_amount}' => ts('Non Deductible Amount'),
628 '{contribution.receive_date}' => ts('Contribution Receive Date'),
629 '{contribution.payment_instrument}' => ts('Payment Instrument'),
630 '{contribution.trxn_id}' => ts('Transaction ID'),
631 '{contribution.invoice_id}' => ts('Invoice ID'),
632 '{contribution.currency}' => ts('Currency'),
633 '{contribution.cancel_date}' => ts('Contribution Cancel Date'),
634 '{contribution.cancel_reason}' => ts('Contribution Cancel Reason'),
635 '{contribution.receipt_date}' => ts('Receipt Date'),
636 '{contribution.thankyou_date}' => ts('Thank You Date'),
637 '{contribution.contribution_source}' => ts('Contribution Source'),
638 '{contribution.amount_level}' => ts('Amount Level'),
639 //'{contribution.contribution_recur_id}' => ts('Contribution Recurring ID'),
640 //'{contribution.honor_contact_id}' => ts('Honor Contact ID'),
641 '{contribution.contribution_status_id}' => ts('Contribution Status'),
642 //'{contribution.honor_type_id}' => ts('Honor Type ID'),
643 //'{contribution.address_id}' => ts('Address ID'),
644 '{contribution.check_number}' => ts('Check Number'),
645 '{contribution.campaign}' => ts('Contribution Campaign'),
646 );
647 }
648 return $tokens;
649 }
650
651 /**
652 * different type of Contact Tokens
653 *
654 * @static
655 * return array
656 */
657 static function &contactTokens() {
658 static $tokens = NULL;
659 if (!$tokens) {
660 $additionalFields = array('checksum' => array('title' => ts('Checksum')),
661 'contact_id' => array('title' => ts('Internal Contact ID')),
662 );
663 $exportFields = array_merge(CRM_Contact_BAO_Contact::exportableFields(), $additionalFields);
664
665 $values = array_merge(array_keys($exportFields));
666 unset($values[0]);
667
668 //FIXME:skipping some tokens for time being.
669 $skipTokens = array(
670 'is_bulkmail', 'group', 'tag', 'contact_sub_type', 'note',
671 'is_deceased', 'deceased_date', 'legal_identifier', 'contact_sub_type', 'user_unique_id',
672 );
673
674 $customFields = CRM_Core_BAO_CustomField::getFields('Individual');
675 $customFieldsAddress = CRM_Core_BAO_CustomField::getFields('Address');
676 $customFields = $customFields + $customFieldsAddress;
677 $legacyTokenNames = array_flip(CRM_Utils_Token::legacyContactTokens());
678
679 foreach ($values as $val) {
680 if (in_array($val, $skipTokens)) {
681 continue;
682 }
683 //keys for $tokens should be constant. $token Values are changed for Custom Fields. CRM-3734
684 if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($val)) {
685 $tokens["{contact.$val}"] = !empty($customFields[$customFieldId]) ? $customFields[$customFieldId]['label'] . " :: " . $customFields[$customFieldId]['groupTitle'] : '';
686 }
687 else {
688 // Support legacy token names
689 $tokenName = CRM_Utils_Array::value($val, $legacyTokenNames, $val);
690 $tokens["{contact.$tokenName}"] = $exportFields[$val]['title'];
691 }
692 }
693
694 // might as well get all the hook tokens to
695 $hookTokens = array();
696 CRM_Utils_Hook::tokens($hookTokens);
697 foreach ($hookTokens as $category => $tokenValues) {
698 foreach ($tokenValues as $key => $value) {
699 if (is_numeric($key)) {
700 $key = $value;
701 }
702 if (!preg_match('/^\{[^\}]+\}$/', $key)) {
703 $key = '{' . $key . '}';
704 }
705 if (preg_match('/^\{([^\}]+)\}$/', $value, $matches)) {
706 $value = $matches[1];
707 }
708 $tokens[$key] = $value;
709 }
710 }
711 }
712
713 return $tokens;
714 }
715
716 /**
717 * different type of Participant Tokens
718 *
719 * @static
720 * return array
721 */
722 static function &participantTokens() {
723 static $tokens = NULL;
724 if (!$tokens) {
725 $exportFields = CRM_Event_BAO_Participant::exportableFields();
726
727 $values = array_merge(array_keys($exportFields));
728 unset($values[0]);
729
730 // skipping some tokens for time being.
731 $skipTokens = array(
732 'event_id', 'participant_is_pay_later', 'participant_is_test', 'participant_contact_id',
733 'participant_fee_currency', 'participant_campaign_id', 'participant_status', 'participant_discount_name',
734 );
735
736 $customFields = CRM_Core_BAO_CustomField::getFields('Participant');
737
738 foreach ($values as $key => $val) {
739 if (in_array($val, $skipTokens)) {
740 continue;
741 }
742 //keys for $tokens should be constant. $token Values are changed for Custom Fields. CRM-3734
743 if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($val)) {
744 $tokens["{participant.$val}"] = !empty($customFields[$customFieldId]) ? $customFields[$customFieldId]['label'] . " :: " . $customFields[$customFieldId]['groupTitle'] : '';
745 }
746 else {
747 $tokens["{participant.$val}"] = $exportFields[$val]['title'];
748 }
749 }
750 }
751 return $tokens;
752 }
753
754 /**
755 * get qf mappig for all date parts.
756 *
757 */
758 static function &qfDatePartsMapping() {
759 static $qfDatePartsMapping = NULL;
760 if (!$qfDatePartsMapping) {
761 $qfDatePartsMapping = array(
762 '%b' => 'M',
763 '%B' => 'F',
764 '%d' => 'd',
765 '%e' => 'j',
766 '%E' => 'j',
767 '%f' => 'S',
768 '%H' => 'H',
769 '%I' => 'h',
770 '%k' => 'G',
771 '%l' => 'g',
772 '%m' => 'm',
773 '%M' => 'i',
774 '%p' => 'a',
775 '%P' => 'A',
776 '%Y' => 'Y',
777 );
778 }
779
780 return $qfDatePartsMapping;
781 }
782
783 /**
784 * CiviCRM supported date input formats
785 */
786 static function getDatePluginInputFormats() {
787 $dateInputFormats = array(
788 "mm/dd/yy" => ts('mm/dd/yyyy (12/31/2009)'),
789 "dd/mm/yy" => ts('dd/mm/yyyy (31/12/2009)'),
790 "yy-mm-dd" => ts('yyyy-mm-dd (2009-12-31)'),
791 "dd-mm-yy" => ts('dd-mm-yyyy (31-12-2009)'),
792 'dd.mm.yy' => ts('dd.mm.yyyy (31.12.2009)'),
793 "M d, yy" => ts('M d, yyyy (Dec 31, 2009)'),
794 'd M yy' => ts('d M yyyy (31 Dec 2009)'),
795 "MM d, yy" => ts('MM d, yyyy (December 31, 2009)'),
796 'd MM yy' => ts('d MM yyyy (31 December 2009)'),
797 "DD, d MM yy" => ts('DD, d MM yyyy (Thursday, 31 December 2009)'),
798 "mm/dd" => ts('mm/dd (12/31)'),
799 "dd-mm" => ts('dd-mm (31-12)'),
800 "yy-mm" => ts('yyyy-mm (2009-12)'),
801 'M yy' => ts('M yyyy (Dec 2009)'),
802 "yy" => ts('yyyy (2009)'),
803 );
804
805 /*
806 Year greater than 2000 get wrong result for following format
807 echo date( 'Y-m-d', strtotime( '7 Nov, 2001') );
808 echo date( 'Y-m-d', strtotime( '7 November, 2001') );
809 Return current year
810 expected :: 2001-11-07
811 output :: 2009-11-07
812 However
813 echo date( 'Y-m-d', strtotime( 'Nov 7, 2001') );
814 echo date( 'Y-m-d', strtotime( 'November 7, 2001') );
815 gives proper result
816 */
817
818
819 return $dateInputFormats;
820 }
821
822 /**
823 * Map date plugin and actual format that is used by PHP
824 */
825 static function datePluginToPHPFormats() {
826 $dateInputFormats = array(
827 "mm/dd/yy" => 'm/d/Y',
828 "dd/mm/yy" => 'd/m/Y',
829 "yy-mm-dd" => 'Y-m-d',
830 "dd-mm-yy" => 'd-m-Y',
831 "dd.mm.yy" => 'd.m.Y',
832 "M d, yy" => 'M j, Y',
833 "d M yy" => 'j M Y',
834 "MM d, yy" => 'F j, Y',
835 "d MM yy" => 'j F Y',
836 "DD, d MM yy" => 'l, j F Y',
837 "mm/dd" => 'm/d',
838 "dd-mm" => 'd-m',
839 "yy-mm" => 'Y-m',
840 "M yy" => 'M Y',
841 "yy" => 'Y',
842 );
843 return $dateInputFormats;
844 }
845
846 /**
847 * Time formats
848 */
849 static function getTimeFormats() {
850 $timeFormats = array('1' => ts('12 Hours'),
851 '2' => ts('24 Hours'),
852 );
853 return $timeFormats;
854 }
855
856 /**
857 * Function to get numeric options
858 *
859 *
860 * @static
861 */
862 public static function getNumericOptions($start = 0, $end = 10) {
863 for ($i = $start; $i <= $end; $i++) {
864 $numericOptions[$i] = $i;
865 }
866 return $numericOptions;
867 }
868
869 /**
870 * barcode types
871 * @static
872 */
873 static function getBarcodeTypes() {
874 static $barcodeTypes = NULL;
875 if (!$barcodeTypes) {
876 $barcodeTypes = array(
877 'barcode' => ts('Linear (1D)'),
878 'qrcode' => ts('QR code'),
879 );
880 }
881 return $barcodeTypes;
882 }
883
884 /**
885 * dedupe rule types
886 */
887 static function getDedupeRuleTypes() {
888 static $dedupeRuleTypes = NULL;
889 if (!$dedupeRuleTypes) {
890 $dedupeRuleTypes = array(
891 'Unsupervised' => ts('Unsupervised'),
892 'Supervised' => ts('Supervised'),
893 'General' => ts('General'),
894 );
895 }
896 return $dedupeRuleTypes;
897 }
898
899 /**
900 * campaign group types
901 */
902 static function getCampaignGroupTypes() {
903 static $campaignGroupTypes = NULL;
904 if (!$campaignGroupTypes) {
905 $campaignGroupTypes = array(
906 'Include' => ts('Include'),
907 'Exclude' => ts('Exclude'),
908 );
909 }
910 return $campaignGroupTypes;
911 }
912
913 /**
914 * subscription history method
915 */
916 static function getSubscriptionHistoryMethods() {
917 static $subscriptionHistoryMethods = NULL;
918 if (!$subscriptionHistoryMethods) {
919 $subscriptionHistoryMethods = array(
920 'Admin' => ts('Admin'),
921 'Email' => ts('Email'),
922 'Web' => ts('Web'),
923 'API' => ts('API'),
924 );
925 }
926
927 return $subscriptionHistoryMethods;
928 }
929
930 /**
931 * premium units
932 */
933 static function getPremiumUnits() {
934 static $premiumUnits = NULL;
935 if (!$premiumUnits) {
936 $premiumUnits = array(
937 'day' => ts('Day'),
938 'week' => ts('Week'),
939 'month' => ts('Month'),
940 'year' => ts('Year'),
941 );
942 }
943
944 return $premiumUnits;
945 }
946
947 /**
948 * extension types
949 */
950 static function getExtensionTypes() {
951 static $extensionTypes = NULL;
952 if (!$extensionTypes) {
953 $extensionTypes = array(
954 'payment' => ts('Payment'),
955 'search' => ts('Search'),
956 'report' => ts('Report'),
957 'module' => ts('Module'),
958 'sms' => ts('SMS'),
959 );
960 }
961
962 return $extensionTypes;
963 }
964
965 /**
966 * job frequency
967 */
968 static function getJobFrequency() {
969 static $jobFrequency = NULL;
970 if (!$jobFrequency) {
971 $jobFrequency = array(
972 'Daily' => ts('Daily'),
973 'Hourly' => ts('Hourly'),
974 'Always' => ts('Every time cron job is run'),
975 );
976 }
977
978 return $jobFrequency;
979 }
980
981 /**
982 * Search builder operators
983 */
984 static function getSearchBuilderOperators() {
985 static $searchBuilderOperators = NULL;
986 if (!$searchBuilderOperators) {
987 $searchBuilderOperators = array(
988 '=' => '=',
989 '!=' => '≠',
990 '>' => '>',
991 '<' => '<',
992 '>=' => '≥',
993 '<=' => '≤',
994 'IN' => ts('In'),
995 'LIKE' => ts('Like'),
996 'RLIKE' => ts('Regex'),
997 'IS EMPTY' => ts('Is Empty'),
998 'IS NOT EMPTY' => ts('Not Empty'),
999 'IS NULL' => ts('Is Null'),
1000 'IS NOT NULL' => ts('Not Null'),
1001 );
1002 }
1003
1004 return $searchBuilderOperators;
1005 }
1006
1007 /**
1008 * profile group types
1009 *
1010 * @static
1011 */
1012 static function getProfileGroupType() {
1013 static $profileGroupType = NULL;
1014 if (!$profileGroupType) {
1015 $profileGroupType = array(
1016 'Activity' => ts('Activities'),
1017 'Contribution' => ts('Contributions'),
1018 'Membership' => ts('Memberships'),
1019 'Participant' => ts('Participants'),
1020 );
1021 $contactTypes = self::contactType();
1022 $contactTypes = !empty($contactTypes) ? array('Contact' => 'Contacts') + $contactTypes : array();
1023 $profileGroupType = array_merge($contactTypes, $profileGroupType );
1024 }
1025 return $profileGroupType;
1026 }
1027
1028
1029 /**
1030 * word replacement match type
1031 */
1032 static function getWordReplacementMatchType() {
1033 static $wordReplacementMatchType = NULL;
1034 if (!$wordReplacementMatchType) {
1035 $wordReplacementMatchType = array(
1036 'exactMatch' => ts('Exact Match'),
1037 'wildcardMatch' => ts('Wildcard Match'),
1038 );
1039 }
1040
1041 return $jobFrequency;
1042 }
1043
1044 /**
1045 * mailing group types
1046 */
1047 static function getMailingGroupTypes() {
1048 static $mailingGroupTypes = NULL;
1049 if (!$mailingGroupTypes) {
1050 $mailingGroupTypes = array(
1051 'Include' => ts('Include'),
1052 'Exclude' => ts('Exclude'),
1053 'Base' => ts('Base'),
1054 );
1055 }
1056 return $mailingGroupTypes;
1057 }
1058
1059 /**
1060 * Mailing Job Status
1061 */
1062 static function getMailingJobStatus() {
1063 static $mailingJobStatus = NULL;
1064 if (!$mailingJobStatus) {
1065 $mailingJobStatus = array(
1066 'Scheduled' => ts('Scheduled'),
1067 'Running' => ts('Running'),
1068 'Complete' => ts('Complete'),
1069 'Paused' => ts('Paused'),
1070 'Canceled' => ts('Canceled'),
1071 );
1072 }
1073
1074 return $mailingJobStatus;
1075 }
1076
1077 /**
1078 * Frequency unit for schedule reminders
1079 */
1080 static function getScheduleReminderFrequencyUnits() {
1081 static $scheduleReminderFrequencyUnits = NULL;
1082 if (!$scheduleReminderFrequencyUnits) {
1083 $scheduleReminderFrequencyUnits = array(
1084 'hour' => ts('hour')) + CRM_Core_OptionGroup::values('recur_frequency_units');
1085 }
1086
1087 return $scheduleReminderFrequencyUnits;
1088 }
1089 }
1090