Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
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 = array('' => ts('- any contact type -')); | |
101 | $contactType = $contactType + CRM_Contact_BAO_ContactType::basicTypePairs(); | |
102 | } | |
103 | return $contactType; | |
104 | } | |
105 | ||
106 | /** | |
107 | * various pre defined unit list | |
108 | * @static | |
109 | */ | |
110 | static function &unitList($unitType = NULL) { | |
111 | static $unitList = NULL; | |
112 | if (!$unitList) { | |
113 | $unitList = array( | |
114 | '' => ts('- select -'), | |
115 | 'day' => ts('day'), | |
116 | 'month' => ts('month'), | |
117 | 'year' => ts('year'), | |
118 | ); | |
119 | if ($unitType == 'duration') { | |
120 | $unitAdd = array( | |
121 | 'lifetime' => ts('lifetime'), | |
122 | ); | |
123 | $unitList = array_merge($unitList, $unitAdd); | |
124 | } | |
125 | } | |
126 | return $unitList; | |
127 | } | |
128 | ||
129 | /** | |
130 | * various pre defined period types | |
131 | * @static | |
132 | */ | |
133 | static function &periodType() { | |
134 | static $periodType = NULL; | |
135 | if (!$periodType) { | |
136 | $periodType = array( | |
137 | '' => ts('- select -'), | |
138 | 'rolling' => ts('rolling'), | |
139 | 'fixed' => ts('fixed'), | |
140 | ); | |
141 | } | |
142 | return $periodType; | |
143 | } | |
144 | ||
145 | /** | |
146 | * various pre defined member visibility options | |
147 | * @static | |
148 | */ | |
149 | static function &memberVisibility() { | |
150 | static $visible = NULL; | |
151 | if (!$visible) { | |
152 | $visible = array( | |
153 | 'Public' => ts('Public'), | |
154 | 'Admin' => ts('Admin'), | |
155 | ); | |
156 | } | |
157 | return $visible; | |
158 | } | |
159 | ||
160 | /** | |
161 | * various pre defined event dates | |
162 | * @static | |
163 | */ | |
164 | static function &eventDate() { | |
165 | static $eventDate = NULL; | |
166 | if (!$eventDate) { | |
167 | $eventDate = array( | |
168 | '' => ts('- select -'), | |
169 | 'start_date' => ts('start date'), | |
170 | 'end_date' => ts('end date'), | |
171 | 'join_date' => ts('member since'), | |
172 | ); | |
173 | } | |
174 | return $eventDate; | |
175 | } | |
176 | ||
177 | /** | |
178 | * Extended property (custom field) data types | |
179 | * @static | |
180 | */ | |
181 | static function &customDataType() { | |
182 | static $customDataType = NULL; | |
183 | if (!$customDataType) { | |
184 | $customDataType = array( | |
185 | '' => ts('- select -'), | |
186 | 'String' => ts('Text'), | |
187 | 'Int' => ts('Integer'), | |
188 | 'Float' => ts('Decimal Number'), | |
189 | 'Money' => ts('Money'), | |
190 | 'Text' => ts('Memo'), | |
191 | 'Date' => ts('Date'), | |
192 | 'File' => ts('File'), | |
193 | 'Boolean' => ts('Yes/No'), | |
194 | 'Link' => ts('Link'), | |
195 | 'Auto-complete' => ts('Auto-complete'), | |
196 | ); | |
197 | } | |
198 | return $customDataType; | |
199 | } | |
200 | ||
201 | /** | |
202 | * Custom form field types | |
203 | * @static | |
204 | */ | |
205 | static function &customHtmlType() { | |
206 | static $customHtmlType = NULL; | |
207 | if (!$customHtmlType) { | |
208 | $customHtmlType = array( | |
209 | '' => ts('- select -'), | |
210 | 'Text' => ts('Single-line input field (text or numeric)'), | |
211 | 'TextArea' => ts('Multi-line text box (textarea)'), | |
212 | 'Select' => ts('Drop-down (select list)'), | |
213 | 'Radio' => ts('Radio buttons'), | |
214 | 'Checkbox' => ts('Checkbox(es)'), | |
215 | 'Select Date' => ts('Date selector'), | |
216 | 'File' => ts('File'), | |
217 | 'Select State / Province' => ts('State / Province selector'), | |
218 | 'Select Country' => ts('Country selector'), | |
219 | 'RichTextEditor' => ts('Rich Text Editor'), | |
220 | 'Auto-complete' => ts('Contact Reference'), | |
221 | ); | |
222 | } | |
223 | return $customHtmlType; | |
224 | } | |
225 | ||
226 | /** | |
227 | * various pre defined extensions for dynamic properties and groups | |
228 | * | |
229 | * @static | |
230 | */ | |
231 | static function &customGroupExtends() { | |
232 | static $customGroupExtends = NULL; | |
233 | if (!$customGroupExtends) { | |
234 | $customGroupExtends = array( | |
235 | 'Activity' => ts('Activities'), | |
236 | 'Relationship' => ts('Relationships'), | |
237 | 'Contribution' => ts('Contributions'), | |
238 | 'Group' => ts('Groups'), | |
239 | 'Membership' => ts('Memberships'), | |
240 | 'Event' => ts('Events'), | |
241 | 'Participant' => ts('Participants'), | |
242 | 'ParticipantRole' => ts('Participants (Role)'), | |
243 | 'ParticipantEventName' => ts('Participants (Event Name)'), | |
244 | 'ParticipantEventType' => ts('Participants (Event Type)'), | |
245 | 'Pledge' => ts('Pledges'), | |
246 | 'Grant' => ts('Grants'), | |
247 | 'Address' => ts('Addresses'), | |
248 | 'Campaign' => ts('Campaigns'), | |
249 | ); | |
250 | $contactTypes = self::contactType(); | |
251 | unset($contactTypes['']); | |
252 | $contactTypes = !empty($contactTypes) ? array('Contact' => 'Contacts') + $contactTypes : array(); | |
253 | $extendObjs = CRM_Core_OptionGroup::values('cg_extend_objects'); | |
254 | $customGroupExtends = array_merge($contactTypes, $customGroupExtends, $extendObjs); | |
255 | } | |
256 | return $customGroupExtends; | |
257 | } | |
258 | ||
259 | /** | |
260 | * styles for displaying the custom data group | |
261 | * | |
262 | * @static | |
263 | */ | |
264 | static function &customGroupStyle() { | |
265 | static $customGroupStyle = NULL; | |
266 | if (!$customGroupStyle) { | |
267 | $customGroupStyle = array( | |
268 | 'Tab' => ts('Tab'), | |
269 | 'Inline' => ts('Inline'), | |
270 | ); | |
271 | } | |
272 | return $customGroupStyle; | |
273 | } | |
274 | ||
275 | /** | |
276 | * for displaying the uf group types | |
277 | * | |
278 | * @static | |
279 | */ | |
280 | static function &ufGroupTypes() { | |
281 | static $ufGroupType = NULL; | |
282 | if (!$ufGroupType) { | |
283 | $ufGroupType = array( | |
284 | 'Profile' => ts('Standalone Form or Directory'), | |
285 | 'Search Profile' => ts('Search Views'), | |
286 | ); | |
287 | $config = CRM_Core_Config::singleton(); | |
288 | if ($config->userSystem->supports_form_extensions) { | |
289 | $ufGroupType += array( | |
290 | 'User Registration' => ts('Drupal User Registration'), | |
291 | 'User Account' => ts('View/Edit Drupal User Account'), | |
292 | ); | |
293 | } | |
294 | } | |
295 | return $ufGroupType; | |
296 | } | |
297 | ||
298 | /** | |
299 | * the status of a contact within a group | |
300 | * | |
301 | * @static | |
302 | */ | |
303 | static function &groupContactStatus() { | |
304 | static $groupContactStatus = NULL; | |
305 | if (!$groupContactStatus) { | |
306 | $groupContactStatus = array( | |
307 | 'Added' => ts('Added'), | |
308 | 'Removed' => ts('Removed'), | |
309 | 'Pending' => ts('Pending'), | |
310 | ); | |
311 | } | |
312 | return $groupContactStatus; | |
313 | } | |
314 | ||
315 | /** | |
316 | * list of Group Types | |
317 | * @static | |
318 | */ | |
319 | static function &groupType() { | |
320 | static $groupType = NULL; | |
321 | if (!$groupType) { | |
322 | $groupType = array( | |
323 | 'query' => ts('Dynamic'), | |
324 | 'static' => ts('Static'), | |
325 | ); | |
326 | } | |
327 | return $groupType; | |
328 | } | |
329 | ||
330 | /** | |
331 | * compose the parameters for a date select object | |
332 | * | |
333 | * @param $type the type of date | |
334 | * @param $format date format ( QF format) | |
335 | * | |
336 | * @return array the date array | |
337 | * @static | |
338 | */ | |
339 | static function &date($type = NULL, $format = NULL, $minOffset = NULL, $maxOffset = NULL) { | |
340 | ||
341 | $date = array( | |
342 | 'addEmptyOption' => TRUE, | |
343 | 'emptyOptionText' => ts('- select -'), | |
344 | 'emptyOptionValue' => '', | |
345 | ); | |
346 | ||
347 | if ($format) { | |
348 | $date['format'] = $format; | |
349 | } | |
350 | else { | |
351 | if ($type) { | |
352 | $dao = new CRM_Core_DAO_PreferencesDate(); | |
353 | $dao->name = $type; | |
354 | if (!$dao->find(TRUE)) { | |
355 | CRM_Core_Error::fatal(); | |
356 | } | |
357 | } | |
358 | ||
359 | if ($type == 'creditCard') { | |
360 | $minOffset = $dao->start; | |
361 | $maxOffset = $dao->end; | |
362 | $date['format'] = $dao->date_format; | |
363 | $date['addEmptyOption'] = TRUE; | |
364 | $date['emptyOptionText'] = ts('- select -'); | |
365 | $date['emptyOptionValue'] = ''; | |
366 | } | |
367 | ||
368 | if (!CRM_Utils_Array::value('format', $date)) { | |
369 | $date['format'] = 'M d'; | |
370 | } | |
371 | } | |
372 | ||
373 | $year = date('Y'); | |
374 | $date['minYear'] = $year - $minOffset; | |
375 | $date['maxYear'] = $year + $maxOffset; | |
376 | return $date; | |
377 | } | |
378 | ||
379 | /** | |
380 | * values for UF form visibility options | |
381 | * | |
382 | * @static | |
383 | */ | |
384 | static function ufVisibility($isGroup = FALSE) { | |
385 | static $_visibility = NULL; | |
386 | if (!$_visibility) { | |
387 | $_visibility = array( | |
388 | 'User and User Admin Only' => ts('User and User Admin Only'), | |
389 | 'Public Pages' => ts('Public Pages'), | |
390 | 'Public Pages and Listings' => ts('Public Pages and Listings'), | |
391 | ); | |
392 | if ($isGroup) { | |
393 | unset($_visibility['Public Pages and Listings']); | |
394 | } | |
395 | } | |
396 | return $_visibility; | |
397 | } | |
398 | ||
399 | /** | |
400 | * different type of Mailing Components | |
401 | * | |
402 | * @static | |
403 | * return array | |
404 | */ | |
405 | static function &mailingComponents() { | |
406 | static $components = NULL; | |
407 | ||
408 | if (!$components) { | |
409 | $components = array('Header' => ts('Header'), | |
410 | 'Footer' => ts('Footer'), | |
411 | 'Reply' => ts('Reply Auto-responder'), | |
412 | 'OptOut' => ts('Opt-out Message'), | |
413 | 'Subscribe' => ts('Subscription Confirmation Request'), | |
414 | 'Welcome' => ts('Welcome Message'), | |
415 | 'Unsubscribe' => ts('Unsubscribe Message'), | |
416 | 'Resubscribe' => ts('Resubscribe Message'), | |
417 | ); | |
418 | } | |
419 | return $components; | |
420 | } | |
421 | ||
422 | /** | |
423 | * Function to get hours | |
424 | * | |
425 | * | |
426 | * @static | |
427 | */ | |
428 | function getHours() { | |
429 | for ($i = 0; $i <= 6; $i++) { | |
430 | $hours[$i] = $i; | |
431 | } | |
432 | return $hours; | |
433 | } | |
434 | ||
435 | /** | |
436 | * Function to get minutes | |
437 | * | |
438 | * | |
439 | * @static | |
440 | */ | |
441 | function getMinutes() { | |
442 | for ($i = 0; $i < 60; $i = $i + 15) { | |
443 | $minutes[$i] = $i; | |
444 | } | |
445 | return $minutes; | |
446 | } | |
447 | ||
448 | /** | |
449 | * Function to get the Map Provider | |
450 | * | |
451 | * @return array $map array of map providers | |
452 | * @static | |
453 | */ | |
454 | static function mapProvider() { | |
455 | static $map = NULL; | |
456 | if (!$map) { | |
457 | return CRM_Utils_System::getPluginList('templates/CRM/Contact/Form/Task/Map', ".tpl"); | |
458 | } | |
459 | return $map; | |
460 | } | |
461 | ||
462 | /** | |
463 | * Function to get the Geocoding Providers from available plugins | |
464 | * | |
465 | * @return array $geo array of geocoder providers | |
466 | * @static | |
467 | */ | |
468 | static function geoProvider() { | |
469 | static $geo = NULL; | |
470 | if (!$geo) { | |
471 | return CRM_Utils_System::getPluginList('CRM/Utils/Geocode'); | |
472 | } | |
473 | return $geo; | |
474 | } | |
475 | ||
476 | /** | |
477 | * Function to get the Address Standardization Providers from available | |
478 | * plugins | |
479 | * | |
480 | * @return array $addr array of address standardization providers | |
481 | * @static | |
482 | */ | |
483 | static function addressProvider() { | |
484 | static $addr = NULL; | |
485 | if (!$addr) { | |
486 | return CRM_Utils_System::getPluginList('CRM/Utils/Address', | |
487 | '.php', | |
488 | array('BatchUpdate') | |
489 | ); | |
490 | } | |
491 | return $addr; | |
492 | } | |
493 | ||
494 | /** | |
495 | * different type of Mailing Tokens | |
496 | * | |
497 | * @static | |
498 | * return array | |
499 | */ | |
500 | static function &mailingTokens() { | |
501 | static $tokens = NULL; | |
502 | ||
503 | if (!$tokens) { | |
504 | $tokens = array('{action.unsubscribe}' => ts('Unsubscribe via email'), | |
505 | '{action.unsubscribeUrl}' => ts('Unsubscribe via web page'), | |
506 | '{action.resubscribe}' => ts('Resubscribe via email'), | |
507 | '{action.resubscribeUrl}' => ts('Resubscribe via web page'), | |
508 | '{action.optOut}' => ts('Opt out via email'), | |
509 | '{action.optOutUrl}' => ts('Opt out via web page'), | |
510 | '{action.forward}' => ts('Forward this email (link)'), | |
511 | '{action.reply}' => ts('Reply to this email (link)'), | |
512 | '{action.subscribeUrl}' => ts('Subscribe via web page'), | |
513 | '{domain.name}' => ts('Domain name'), | |
514 | '{domain.address}' => ts('Domain (organization) address'), | |
515 | '{domain.phone}' => ts('Domain (organization) phone'), | |
516 | '{domain.email}' => ts('Domain (organization) email'), | |
517 | '{mailing.name}' => ts('Mailing name'), | |
518 | '{mailing.group}' => ts('Mailing group'), | |
519 | '{mailing.viewUrl}' => ts('Mailing permalink'), | |
520 | ); | |
521 | } | |
522 | return $tokens; | |
523 | } | |
524 | ||
525 | /** | |
526 | * different type of Activity Tokens | |
527 | * | |
528 | * @static | |
529 | * return array | |
530 | */ | |
531 | static function &activityTokens() { | |
532 | static $tokens = NULL; | |
533 | ||
534 | if (!$tokens) { | |
535 | $tokens = array( | |
536 | '{activity.activity_id}' => ts('Activity ID'), | |
537 | '{activity.subject}' => ts('Activity Subject'), | |
538 | '{activity.details}' => ts('Activity Details'), | |
539 | '{activity.activity_date_time}' => ts('Activity Date Time'), | |
540 | ); | |
541 | } | |
542 | return $tokens; | |
543 | } | |
544 | ||
545 | /** | |
546 | * different type of Membership Tokens | |
547 | * | |
548 | * @static | |
549 | * return array | |
550 | */ | |
551 | static function &membershipTokens() { | |
552 | static $tokens = NULL; | |
553 | ||
554 | if (!$tokens) { | |
555 | $tokens = array( | |
556 | '{membership.id}' => ts('Membership ID'), | |
557 | '{membership.status}' => ts('Membership Status'), | |
558 | '{membership.type}' => ts('Membership Type'), | |
559 | '{membership.start_date}' => ts('Membership Start Date'), | |
560 | '{membership.join_date}' => ts('Membership Join Date'), | |
561 | '{membership.end_date}' => ts('Membership End Date'), | |
562 | '{membership.fee}' => ts('Membership Fee'), | |
563 | ); | |
564 | } | |
565 | return $tokens; | |
566 | } | |
567 | ||
568 | /** | |
569 | * different type of Event Tokens | |
570 | * | |
571 | * @static | |
572 | * return array | |
573 | */ | |
574 | static function &eventTokens() { | |
575 | static $tokens = NULL; | |
576 | ||
577 | if (!$tokens) { | |
578 | $tokens = array( | |
579 | '{event.event_id}' => ts('Event ID'), | |
580 | '{event.title}' => ts('Event Title'), | |
581 | '{event.start_date}' => ts('Event Start Date'), | |
582 | '{event.end_date}' => ts('Event End Date'), | |
583 | '{event.event_type}' => ts('Event Type'), | |
584 | '{event.summary}' => ts('Event Summary'), | |
585 | '{event.description}' => ts('Event Description'), | |
586 | '{event.contact_email}' => ts('Event Contact Email'), | |
587 | '{event.contact_phone}' => ts('Event Contact Phone'), | |
588 | '{event.location}' => ts('Event Location'), | |
589 | '{event.description}' => ts('Event Description'), | |
590 | '{event.location}' => ts('Event Location'), | |
591 | '{event.fee_amount}' => ts('Event Fees'), | |
592 | '{event.info_url}' => ts('Event Info URL'), | |
593 | '{event.registration_url}' => ts('Event Registration URL'), | |
594 | ); | |
595 | } | |
596 | return $tokens; | |
597 | } | |
598 | ||
599 | /** | |
600 | * different type of Event Tokens | |
601 | * | |
602 | * @static | |
603 | * return array | |
604 | */ | |
605 | static function &contributionTokens() { | |
606 | static $tokens = NULL; | |
607 | ||
608 | if (!$tokens) { | |
609 | $tokens = array( | |
610 | '{contribution.contribution_id}' => ts('Contribution ID'), | |
611 | '{contribution.total_amount}' => ts('Total Amount'), | |
612 | '{contribution.fee_amount}' => ts('Fee Amount'), | |
613 | '{contribution.net_amount}' => ts('Net Amount'), | |
614 | '{contribution.non_deductible_amount}' => ts('Non Deductible Amount'), | |
615 | '{contribution.receive_date}' => ts('Contribution Receive Date'), | |
616 | '{contribution.payment_instrument}' => ts('Payment Instrument'), | |
617 | '{contribution.trxn_id}' => ts('Transaction ID'), | |
618 | '{contribution.invoice_id}' => ts('Invoice ID'), | |
619 | '{contribution.currency}' => ts('Currency'), | |
620 | '{contribution.cancel_date}' => ts('Contribution Cancel Date'), | |
621 | '{contribution.cancel_reason}' => ts('Contribution Cancel Reason'), | |
622 | '{contribution.receipt_date}' => ts('Receipt Date'), | |
623 | '{contribution.thankyou_date}' => ts('Thank You Date'), | |
624 | '{contribution.contribution_source}' => ts('Contribution Source'), | |
625 | '{contribution.amount_level}' => ts('Amount Level'), | |
626 | //'{contribution.contribution_recur_id}' => ts('Contribution Recurring ID'), | |
627 | //'{contribution.honor_contact_id}' => ts('Honor Contact ID'), | |
628 | '{contribution.contribution_status_id}' => ts('Contribution Status'), | |
629 | //'{contribution.honor_type_id}' => ts('Honor Type ID'), | |
630 | //'{contribution.address_id}' => ts('Address ID'), | |
631 | '{contribution.check_number}' => ts('Check Number'), | |
632 | '{contribution.campaign}' => ts('Contribution Campaign'), | |
633 | ); | |
634 | } | |
635 | return $tokens; | |
636 | } | |
637 | ||
638 | /** | |
639 | * different type of Contact Tokens | |
640 | * | |
641 | * @static | |
642 | * return array | |
643 | */ | |
644 | static function &contactTokens() { | |
645 | static $tokens = NULL; | |
646 | if (!$tokens) { | |
647 | $additionalFields = array('checksum' => array('title' => ts('Checksum')), | |
648 | 'contact_id' => array('title' => ts('Internal Contact ID')), | |
649 | ); | |
650 | $exportFields = array_merge(CRM_Contact_BAO_Contact::exportableFields(), $additionalFields); | |
651 | ||
652 | $values = array_merge(array_keys($exportFields)); | |
653 | unset($values[0]); | |
654 | ||
655 | //FIXME:skipping some tokens for time being. | |
656 | $skipTokens = array( | |
657 | 'is_bulkmail', 'group', 'tag', 'contact_sub_type', 'note', | |
658 | 'is_deceased', 'deceased_date', 'legal_identifier', 'contact_sub_type', 'user_unique_id', | |
659 | ); | |
ea921622 | 660 | |
6a488035 TO |
661 | $customFields = CRM_Core_BAO_CustomField::getFields('Individual'); |
662 | $customFieldsAddress = CRM_Core_BAO_CustomField::getFields('Address'); | |
663 | $customFields = $customFields + $customFieldsAddress; | |
664 | ||
665 | foreach ($values as $key => $val) { | |
666 | if (in_array($val, $skipTokens)) { | |
667 | continue; | |
668 | } | |
669 | //keys for $tokens should be constant. $token Values are changed for Custom Fields. CRM-3734 | |
670 | if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($val)) { | |
671 | $tokens["{contact.$val}"] = CRM_Utils_Array::value($customFieldId, $customFields) ? $customFields[$customFieldId]['label'] . " :: " . $customFields[$customFieldId]['groupTitle'] : ''; | |
672 | } | |
673 | else { | |
674 | $tokens["{contact.$val}"] = $exportFields[$val]['title']; | |
675 | } | |
676 | } | |
677 | ||
678 | // might as well get all the hook tokens to | |
679 | $hookTokens = array(); | |
680 | CRM_Utils_Hook::tokens($hookTokens); | |
681 | foreach ($hookTokens as $category => $tokenValues) { | |
682 | foreach ($tokenValues as $key => $value) { | |
683 | if (is_numeric($key)) { | |
684 | $key = $value; | |
685 | } | |
686 | if (!preg_match('/^\{[^\}]+\}$/', $key)) { | |
687 | $key = '{' . $key . '}'; | |
688 | } | |
689 | if (preg_match('/^\{([^\}]+)\}$/', $value, $matches)) { | |
690 | $value = $matches[1]; | |
691 | } | |
692 | $tokens[$key] = $value; | |
693 | } | |
694 | } | |
695 | } | |
696 | ||
697 | return $tokens; | |
698 | } | |
699 | ||
ea921622 KJ |
700 | /** |
701 | * different type of Participant Tokens | |
702 | * | |
703 | * @static | |
704 | * return array | |
705 | */ | |
706 | static function &participantTokens() { | |
707 | static $tokens = NULL; | |
708 | if (!$tokens) { | |
709 | $exportFields = CRM_Event_BAO_Participant::exportableFields(); | |
710 | ||
711 | $values = array_merge(array_keys($exportFields)); | |
712 | unset($values[0]); | |
713 | ||
714 | // skipping some tokens for time being. | |
715 | $skipTokens = array( | |
716 | 'event_id', 'participant_is_pay_later', 'participant_is_test', 'participant_contact_id', | |
717 | 'participant_fee_currency', 'participant_campaign_id', 'participant_status', 'participant_discount_name', | |
718 | ); | |
719 | ||
720 | $customFields = CRM_Core_BAO_CustomField::getFields('Participant'); | |
721 | ||
722 | foreach ($values as $key => $val) { | |
723 | if (in_array($val, $skipTokens)) { | |
724 | continue; | |
725 | } | |
726 | //keys for $tokens should be constant. $token Values are changed for Custom Fields. CRM-3734 | |
727 | if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($val)) { | |
728 | $tokens["{participant.$val}"] = CRM_Utils_Array::value($customFieldId, $customFields) ? $customFields[$customFieldId]['label'] . " :: " . $customFields[$customFieldId]['groupTitle'] : ''; | |
729 | } | |
730 | else { | |
731 | $tokens["{participant.$val}"] = $exportFields[$val]['title']; | |
732 | } | |
733 | } | |
734 | } | |
735 | return $tokens; | |
736 | } | |
737 | ||
6a488035 TO |
738 | /** |
739 | * get qf mappig for all date parts. | |
740 | * | |
741 | */ | |
742 | static function &qfDatePartsMapping() { | |
743 | static $qfDatePartsMapping = NULL; | |
744 | if (!$qfDatePartsMapping) { | |
745 | $qfDatePartsMapping = array( | |
746 | '%b' => 'M', | |
747 | '%B' => 'F', | |
748 | '%d' => 'd', | |
749 | '%e' => 'j', | |
750 | '%E' => 'j', | |
751 | '%f' => 'S', | |
752 | '%H' => 'H', | |
753 | '%I' => 'h', | |
754 | '%k' => 'G', | |
755 | '%l' => 'g', | |
756 | '%m' => 'm', | |
757 | '%M' => 'i', | |
758 | '%p' => 'a', | |
759 | '%P' => 'A', | |
760 | '%Y' => 'Y', | |
761 | ); | |
762 | } | |
763 | ||
764 | return $qfDatePartsMapping; | |
765 | } | |
766 | ||
767 | /** | |
768 | * CiviCRM supported date input formats | |
769 | */ | |
770 | static function getDatePluginInputFormats() { | |
771 | $dateInputFormats = array( | |
772 | "mm/dd/yy" => ts('mm/dd/yyyy (12/31/2009)'), | |
773 | "dd/mm/yy" => ts('dd/mm/yyyy (31/12/2009)'), | |
774 | "yy-mm-dd" => ts('yyyy-mm-dd (2009-12-31)'), | |
775 | "dd-mm-yy" => ts('dd-mm-yyyy (31-12-2009)'), | |
776 | 'dd.mm.yy' => ts('dd.mm.yyyy (31.12.2009)'), | |
777 | "M d, yy" => ts('M d, yyyy (Dec 31, 2009)'), | |
778 | 'd M yy' => ts('d M yyyy (31 Dec 2009)'), | |
779 | "MM d, yy" => ts('MM d, yyyy (December 31, 2009)'), | |
780 | 'd MM yy' => ts('d MM yyyy (31 December 2009)'), | |
781 | "DD, d MM yy" => ts('DD, d MM yyyy (Thursday, 31 December 2009)'), | |
782 | "mm/dd" => ts('mm/dd (12/31)'), | |
783 | "dd-mm" => ts('dd-mm (31-12)'), | |
784 | "yy-mm" => ts('yyyy-mm (2009-12)'), | |
785 | 'M yy' => ts('M yyyy (Dec 2009)'), | |
786 | "yy" => ts('yyyy (2009)'), | |
787 | ); | |
788 | ||
789 | /* | |
790 | Year greater than 2000 get wrong result for following format | |
791 | echo date( 'Y-m-d', strtotime( '7 Nov, 2001') ); | |
792 | echo date( 'Y-m-d', strtotime( '7 November, 2001') ); | |
793 | Return current year | |
794 | expected :: 2001-11-07 | |
795 | output :: 2009-11-07 | |
796 | However | |
797 | echo date( 'Y-m-d', strtotime( 'Nov 7, 2001') ); | |
798 | echo date( 'Y-m-d', strtotime( 'November 7, 2001') ); | |
799 | gives proper result | |
800 | */ | |
801 | ||
802 | ||
803 | return $dateInputFormats; | |
804 | } | |
805 | ||
806 | /** | |
807 | * Map date plugin and actual format that is used by PHP | |
808 | */ | |
809 | static function datePluginToPHPFormats() { | |
810 | $dateInputFormats = array( | |
811 | "mm/dd/yy" => 'm/d/Y', | |
812 | "dd/mm/yy" => 'd/m/Y', | |
813 | "yy-mm-dd" => 'Y-m-d', | |
814 | "dd-mm-yy" => 'd-m-Y', | |
815 | "dd.mm.yy" => 'd.m.Y', | |
816 | "M d, yy" => 'M j, Y', | |
817 | "d M yy" => 'j M Y', | |
818 | "MM d, yy" => 'F j, Y', | |
819 | "d MM yy" => 'j F Y', | |
820 | "DD, d MM yy" => 'l, j F Y', | |
821 | "mm/dd" => 'm/d', | |
822 | "dd-mm" => 'd-m', | |
823 | "yy-mm" => 'Y-m', | |
824 | "M yy" => 'M Y', | |
825 | "yy" => 'Y', | |
826 | ); | |
827 | return $dateInputFormats; | |
828 | } | |
829 | ||
830 | /** | |
831 | * Time formats | |
832 | */ | |
833 | static function getTimeFormats() { | |
834 | $timeFormats = array('1' => ts('12 Hours'), | |
835 | '2' => ts('24 Hours'), | |
836 | ); | |
837 | return $timeFormats; | |
838 | } | |
839 | ||
840 | /** | |
841 | * Function to get numeric options | |
842 | * | |
843 | * | |
844 | * @static | |
845 | */ | |
846 | public static function getNumericOptions($start = 0, $end = 10) { | |
847 | for ($i = $start; $i <= $end; $i++) { | |
848 | $numericOptions[$i] = $i; | |
849 | } | |
850 | return $numericOptions; | |
851 | } | |
f38395f7 KJ |
852 | |
853 | /** | |
854 | * barcode types | |
855 | * @static | |
856 | */ | |
857 | static function getBarcodeTypes() { | |
858 | static $barcodeTypes = NULL; | |
859 | if (!$barcodeTypes) { | |
860 | $barcodeTypes = array( | |
861 | 'barcode' => ts('Linear (1D)'), | |
862 | 'qrcode' => ts('QR code'), | |
863 | ); | |
864 | } | |
865 | return $barcodeTypes; | |
866 | } | |
6a488035 TO |
867 | } |
868 |