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