CRM-19179: Only allow one 'set primary' to be checked per entity
[civicrm-core.git] / CRM / Core / SelectValues.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
7e9e8871 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
fa938177 6 | Copyright CiviCRM LLC (c) 2004-2016 |
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 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
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
fa938177 34 * @copyright CiviCRM LLC (c) 2004-2016
6a488035
TO
35 * $Id$
36 *
37 */
38class CRM_Core_SelectValues {
39
14f42e31
CW
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
6a488035 52 /**
f9e31d7f 53 * Preferred mail format.
79d7553f 54 *
76e7a76c 55 * @return array
6a488035 56 */
00be9182 57 public static function pmf() {
6795600d
CW
58 return array(
59 'Both' => ts('Both'),
60 'HTML' => ts('HTML'),
61 'Text' => ts('Text'),
62 );
6a488035
TO
63 }
64
65 /**
f9e31d7f 66 * Privacy options.
76e7a76c
CW
67 *
68 * @return array
6a488035 69 */
00be9182 70 public static function privacy() {
6795600d
CW
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 );
6a488035
TO
79 }
80
81 /**
f9e31d7f 82 * Various pre defined contact super types.
76e7a76c
CW
83 *
84 * @return array
6a488035 85 */
00be9182 86 public static function contactType() {
6a488035
TO
87 static $contactType = NULL;
88 if (!$contactType) {
694e78fd 89 $contactType = CRM_Contact_BAO_ContactType::basicTypePairs();
6a488035
TO
90 }
91 return $contactType;
92 }
93
94 /**
f9e31d7f 95 * Various pre defined unit list.
79d7553f 96 *
76e7a76c
CW
97 * @param string $unitType
98 * @return array
6a488035 99 */
00be9182 100 public static function unitList($unitType = NULL) {
c3831ebd
EM
101 $unitList = array(
102 'day' => ts('day'),
103 'month' => ts('month'),
104 'year' => ts('year'),
105 );
106 if ($unitType == 'duration') {
6795600d 107 $unitList['lifetime'] = ts('lifetime');
6a488035
TO
108 }
109 return $unitList;
110 }
111
93bfa565 112 /**
f9e31d7f 113 * Membership type unit.
76e7a76c
CW
114 *
115 * @return array
93bfa565 116 */
2aa397bc 117 public static function membershipTypeUnitList() {
6795600d 118 return self::unitList('duration');
93bfa565 119 }
120
6a488035 121 /**
f9e31d7f 122 * Various pre defined period types.
76e7a76c
CW
123 *
124 * @return array
6a488035 125 */
00be9182 126 public static function periodType() {
c3831ebd
EM
127 return array(
128 'rolling' => ts('Rolling'),
129 'fixed' => ts('Fixed'),
130 );
6a488035
TO
131 }
132
bac4cd35 133 /**
f9e31d7f 134 * Various pre defined email selection methods.
76e7a76c
CW
135 *
136 * @return array
bac4cd35 137 */
00be9182 138 public static function emailSelectMethods() {
bac4cd35 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"),
21dfd5f5 143 'location-exclude' => ts("Exclude email addresses assigned to the specified location"),
bac4cd35 144 );
145 }
146
6a488035 147 /**
f9e31d7f 148 * Various pre defined member visibility options.
76e7a76c
CW
149 *
150 * @return array
6a488035 151 */
00be9182 152 public static function memberVisibility() {
ab5e0c41
CW
153 return array(
154 'Public' => ts('Public'),
155 'Admin' => ts('Admin'),
156 );
6a488035
TO
157 }
158
dbd82592
CW
159 /**
160 * Member auto-renew options
76e7a76c
CW
161 *
162 * @return array
dbd82592
CW
163 */
164 public static function memberAutoRenew() {
165 return array(
166 ts('No auto-renew option'),
167 ts('Give option, but not required'),
21dfd5f5 168 ts('Auto-renew required'),
dbd82592
CW
169 );
170 }
171
6a488035 172 /**
f9e31d7f 173 * Various pre defined event dates.
76e7a76c
CW
174 *
175 * @return array
6a488035 176 */
00be9182 177 public static function eventDate() {
c3831ebd
EM
178 return array(
179 'start_date' => ts('start date'),
180 'end_date' => ts('end date'),
181 'join_date' => ts('member since'),
182 );
6a488035
TO
183 }
184
6a488035 185 /**
f9e31d7f 186 * Custom form field types.
76e7a76c
CW
187 *
188 * @return array
6a488035 189 */
00be9182 190 public static function customHtmlType() {
c3831ebd
EM
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'),
79dc94e4 208 'ContactReference' => ts('Autocomplete-Select'),
c3831ebd 209 );
6a488035
TO
210 }
211
212 /**
f9e31d7f 213 * Various pre defined extensions for dynamic properties and groups.
6a488035 214 *
76e7a76c
CW
215 * @return array
216 *
6a488035 217 */
00be9182 218 public static function customGroupExtends() {
c3831ebd
EM
219 $customGroupExtends = array(
220 'Activity' => ts('Activities'),
221 'Relationship' => ts('Relationships'),
222 'Contribution' => ts('Contributions'),
95974e8e 223 'ContributionRecur' => ts('Recurring Contributions'),
c3831ebd
EM
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();
6795600d
CW
237 $contactTypes = !empty($contactTypes) ? array('Contact' => 'Contacts') + $contactTypes : array();
238 $extendObjs = CRM_Core_OptionGroup::values('cg_extend_objects');
c3831ebd 239 $customGroupExtends = array_merge($contactTypes, $customGroupExtends, $extendObjs);
6a488035
TO
240 return $customGroupExtends;
241 }
242
243 /**
f9e31d7f 244 * Styles for displaying the custom data group.
6a488035 245 *
76e7a76c 246 * @return array
6a488035 247 */
00be9182 248 public static function customGroupStyle() {
c3831ebd
EM
249 return array(
250 'Tab' => ts('Tab'),
251 'Inline' => ts('Inline'),
252 'Tab with table' => ts('Tab with table'),
253 );
6a488035
TO
254 }
255
256 /**
f9e31d7f 257 * For displaying the uf group types.
6a488035 258 *
76e7a76c 259 * @return array
6a488035 260 */
00be9182 261 public static function ufGroupTypes() {
c3831ebd
EM
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'),
6a488035 271 );
6a488035
TO
272 }
273 return $ufGroupType;
274 }
275
276 /**
f9e31d7f 277 * The status of a contact within a group.
6a488035 278 *
76e7a76c 279 * @return array
6a488035 280 */
00be9182 281 public static function groupContactStatus() {
c3831ebd
EM
282 return array(
283 'Added' => ts('Added'),
284 'Removed' => ts('Removed'),
285 'Pending' => ts('Pending'),
286 );
6a488035
TO
287 }
288
289 /**
f9e31d7f 290 * List of Group Types.
76e7a76c
CW
291 *
292 * @return array
6a488035 293 */
00be9182 294 public static function groupType() {
c3831ebd
EM
295 return array(
296 'query' => ts('Dynamic'),
297 'static' => ts('Static'),
298 );
6a488035
TO
299 }
300
301 /**
f9e31d7f 302 * Compose the parameters for a date select object.
6a488035 303 *
76e7a76c
CW
304 * @param string|NULL $type
305 * the type of date
306 * @param string|NULL $format
307 * date format (QF format)
9bf2a591
EM
308 * @param null $minOffset
309 * @param null $maxOffset
6a488035 310 *
a6c01b45
CW
311 * @return array
312 * the date array
6a488035 313 */
00be9182 314 public static function date($type = NULL, $format = NULL, $minOffset = NULL, $maxOffset = NULL) {
6a488035
TO
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
a7488080 342 if (empty($date['format'])) {
6a488035
TO
343 $date['format'] = 'M d';
344 }
345 }
346
6795600d 347 $year = date('Y');
6a488035
TO
348 $date['minYear'] = $year - $minOffset;
349 $date['maxYear'] = $year + $maxOffset;
350 return $date;
351 }
352
353 /**
f9e31d7f 354 * Values for UF form visibility options.
6a488035 355 *
76e7a76c 356 * @return array
6a488035 357 */
00be9182 358 public static function ufVisibility() {
c3831ebd
EM
359 return array(
360 'User and User Admin Only' => ts('User and User Admin Only'),
fac01cb1
DG
361 'Public Pages' => ts('Expose Publicly'),
362 'Public Pages and Listings' => ts('Expose Publicly and for Listings'),
c3831ebd 363 );
6a488035
TO
364 }
365
93bfa565 366 /**
f9e31d7f 367 * Values for group form visibility options.
93bfa565 368 *
76e7a76c 369 * @return array
93bfa565 370 */
00be9182 371 public static function groupVisibility() {
c3831ebd 372 return array(
6795600d
CW
373 'User and User Admin Only' => ts('User and User Admin Only'),
374 'Public Pages' => ts('Public Pages'),
375 );
93bfa565 376 }
377
6a488035 378 /**
f9e31d7f 379 * Different type of Mailing Components.
6a488035 380 *
76e7a76c 381 * @return array
6a488035 382 */
00be9182 383 public static function mailingComponents() {
2aa397bc 384 return array(
353ffa53 385 'Header' => ts('Header'),
c3831ebd
EM
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 );
6a488035
TO
394 }
395
396 /**
f9e31d7f 397 * Get hours.
6a488035 398 *
76e7a76c 399 * @return array
6a488035 400 */
00be9182 401 public function getHours() {
9fab6f51 402 $hours = array();
6a488035
TO
403 for ($i = 0; $i <= 6; $i++) {
404 $hours[$i] = $i;
405 }
406 return $hours;
407 }
408
409 /**
f9e31d7f 410 * Get minutes.
6a488035 411 *
76e7a76c 412 * @return array
6a488035 413 */
00be9182 414 public function getMinutes() {
9fab6f51 415 $minutes = array();
6a488035
TO
416 for ($i = 0; $i < 60; $i = $i + 15) {
417 $minutes[$i] = $i;
418 }
419 return $minutes;
420 }
421
422 /**
f9e31d7f 423 * Get the Map Provider.
6a488035 424 *
a6c01b45
CW
425 * @return array
426 * array of map providers
6a488035 427 */
00be9182 428 public static function mapProvider() {
6a488035
TO
429 static $map = NULL;
430 if (!$map) {
1ec598f3 431 $map = array('' => '- select -') + CRM_Utils_System::getPluginList('templates/CRM/Contact/Form/Task/Map', ".tpl");
6a488035
TO
432 }
433 return $map;
434 }
435
436 /**
f9e31d7f 437 * Get the Geocoding Providers from available plugins.
6a488035 438 *
a6c01b45
CW
439 * @return array
440 * array of geocoder providers
6a488035 441 */
00be9182 442 public static function geoProvider() {
6a488035
TO
443 static $geo = NULL;
444 if (!$geo) {
1ec598f3 445 $geo = array('' => '- select -') + CRM_Utils_System::getPluginList('CRM/Utils/Geocode');
6a488035
TO
446 }
447 return $geo;
448 }
449
450 /**
f9e31d7f 451 * Get the Address Standardization Providers from available plugins.
6a488035 452 *
a6c01b45
CW
453 * @return array
454 * array of address standardization providers
6a488035 455 */
00be9182 456 public static function addressProvider() {
6a488035
TO
457 static $addr = NULL;
458 if (!$addr) {
6795600d 459 $addr = CRM_Utils_System::getPluginList('CRM/Utils/Address', '.php', array('BatchUpdate'));
6a488035
TO
460 }
461 return $addr;
462 }
463
464 /**
f9e31d7f 465 * Different type of Mailing Tokens.
6a488035 466 *
76e7a76c 467 * @return array
6a488035 468 */
00be9182 469 public static function mailingTokens() {
c3831ebd
EM
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 );
6a488035
TO
488 }
489
490 /**
f9e31d7f 491 * Different type of Activity Tokens.
6a488035 492 *
76e7a76c 493 * @return array
6a488035 494 */
00be9182 495 public static function activityTokens() {
c3831ebd
EM
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 );
6a488035
TO
502 }
503
504 /**
f9e31d7f 505 * Different type of Membership Tokens.
6a488035 506 *
76e7a76c 507 * @return array
6a488035 508 */
00be9182 509 public static function membershipTokens() {
c3831ebd
EM
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 );
6a488035
TO
519 }
520
521 /**
f9e31d7f 522 * Different type of Event Tokens.
6a488035 523 *
76e7a76c 524 * @return array
6a488035 525 */
00be9182 526 public static function eventTokens() {
c3831ebd
EM
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'),
21dfd5f5 541 '{event.balance}' => ts('Event Balance'),
c3831ebd 542 );
6a488035
TO
543 }
544
545 /**
f9e31d7f 546 * Different type of Event Tokens.
6a488035 547 *
76e7a76c 548 * @return array
6a488035 549 */
00be9182 550 public static function contributionTokens() {
c3831ebd
EM
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'),
c94fc35e 556 '{contribution.non_deductible_amount}' => ts('Non-deductible Amount'),
7bc6b5bb 557 '{contribution.receive_date}' => ts('Contribution Date Received'),
536f0e02 558 '{contribution.payment_instrument}' => ts('Payment Method'),
c3831ebd
EM
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 );
6a488035
TO
576 }
577
578 /**
f9e31d7f 579 * Different type of Contact Tokens.
6a488035 580 *
76e7a76c 581 * @return array
6a488035 582 */
00be9182 583 public static function contactTokens() {
6a488035
TO
584 static $tokens = NULL;
585 if (!$tokens) {
2aa397bc 586 $additionalFields = array(
353ffa53 587 'checksum' => array('title' => ts('Checksum')),
6a488035
TO
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(
353ffa53
TO
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',
6a488035 607 );
ea921622 608
72e34731 609 $customFields = CRM_Core_BAO_CustomField::getFields(array('Individual', 'Address'));
cc615373 610 $legacyTokenNames = array_flip(CRM_Utils_Token::legacyContactTokens());
6a488035 611
cc615373 612 foreach ($values as $val) {
6a488035
TO
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
72e34731
CW
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 }
6a488035
TO
623 }
624 else {
cc615373
CW
625 // Support legacy token names
626 $tokenName = CRM_Utils_Array::value($val, $legacyTokenNames, $val);
627 $tokens["{contact.$tokenName}"] = $exportFields[$val]['title'];
6a488035
TO
628 }
629 }
630
9950a1c9 631 // Get all the hook tokens too
6a488035
TO
632 $hookTokens = array();
633 CRM_Utils_Hook::tokens($hookTokens);
94bf1070 634 foreach ($hookTokens as $tokenValues) {
6a488035
TO
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
ea921622 653 /**
f9e31d7f 654 * Different type of Participant Tokens.
ea921622 655 *
76e7a76c 656 * @return array
ea921622 657 */
00be9182 658 public static function participantTokens() {
ea921622
KJ
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(
353ffa53
TO
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',
ea921622
KJ
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)) {
0d8afee2 686 $tokens["{participant.$val}"] = !empty($customFields[$customFieldId]) ? $customFields[$customFieldId]['label'] . " :: " . $customFields[$customFieldId]['groupTitle'] : '';
ea921622
KJ
687 }
688 else {
689 $tokens["{participant.$val}"] = $exportFields[$val]['title'];
690 }
691 }
692 }
693 return $tokens;
694 }
695
07945b3c 696 /**
0fe4153d 697 * @param int $caseTypeId
07945b3c
CW
698 * @return array
699 */
0fe4153d 700 public static function caseTokens($caseTypeId = NULL) {
07945b3c
CW
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
0fe4153d 707 $customFields = CRM_Core_BAO_CustomField::getFields('Case', FALSE, FALSE, $caseTypeId);
07945b3c
CW
708 foreach ($customFields as $id => $field) {
709 $tokens["{case.custom_$id}"] = "{$field['label']} :: {$field['groupTitle']}";
710 }
711 }
712 return $tokens;
713 }
714
6a488035 715 /**
f9e31d7f 716 * CiviCRM supported date input formats.
76e7a76c
CW
717 *
718 * @return array
6a488035 719 */
00be9182 720 public static function getDatePluginInputFormats() {
6a488035
TO
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 /*
e70a7fc0
TO
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
76e7a76c 750 */
6a488035 751
6a488035
TO
752 return $dateInputFormats;
753 }
754
755 /**
f9e31d7f 756 * Map date plugin and actual format that is used by PHP.
76e7a76c
CW
757 *
758 * @return array
6a488035 759 */
00be9182 760 public static function datePluginToPHPFormats() {
6a488035
TO
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 /**
f9e31d7f 782 * Time formats.
76e7a76c
CW
783 *
784 * @return array
6a488035 785 */
00be9182 786 public static function getTimeFormats() {
6795600d
CW
787 return array(
788 '1' => ts('12 Hours'),
6a488035
TO
789 '2' => ts('24 Hours'),
790 );
6a488035
TO
791 }
792
793 /**
f9e31d7f 794 * Get numeric options.
79d7553f 795 *
76e7a76c
CW
796 * @param int $start
797 * @param int $end
6a488035 798 *
76e7a76c 799 * @return array
6a488035
TO
800 */
801 public static function getNumericOptions($start = 0, $end = 10) {
9fab6f51 802 $numericOptions = array();
6a488035 803 for ($i = $start; $i <= $end; $i++) {
2aa397bc 804 $numericOptions[$i] = $i;
6a488035
TO
805 }
806 return $numericOptions;
807 }
f38395f7
KJ
808
809 /**
f9e31d7f 810 * Barcode types.
76e7a76c
CW
811 *
812 * @return array
f38395f7 813 */
00be9182 814 public static function getBarcodeTypes() {
c3831ebd
EM
815 return array(
816 'barcode' => ts('Linear (1D)'),
817 'qrcode' => ts('QR code'),
818 );
f38395f7 819 }
77d0b1f8 820
821 /**
f9e31d7f 822 * Dedupe rule types.
76e7a76c
CW
823 *
824 * @return array
77d0b1f8 825 */
00be9182 826 public static function getDedupeRuleTypes() {
c3831ebd
EM
827 return array(
828 'Unsupervised' => ts('Unsupervised'),
829 'Supervised' => ts('Supervised'),
830 'General' => ts('General'),
831 );
77d0b1f8 832 }
f80ce889 833
834 /**
f9e31d7f 835 * Campaign group types.
76e7a76c
CW
836 *
837 * @return array
f80ce889 838 */
00be9182 839 public static function getCampaignGroupTypes() {
c3831ebd
EM
840 return array(
841 'Include' => ts('Include'),
842 'Exclude' => ts('Exclude'),
843 );
f80ce889 844 }
845
846 /**
f9e31d7f 847 * Subscription history method.
76e7a76c
CW
848 *
849 * @return array
f80ce889 850 */
00be9182 851 public static function getSubscriptionHistoryMethods() {
c3831ebd
EM
852 return array(
853 'Admin' => ts('Admin'),
854 'Email' => ts('Email'),
855 'Web' => ts('Web'),
856 'API' => ts('API'),
857 );
f80ce889 858 }
859
860 /**
f9e31d7f 861 * Premium units.
76e7a76c
CW
862 *
863 * @return array
f80ce889 864 */
00be9182 865 public static function getPremiumUnits() {
c3831ebd
EM
866 return array(
867 'day' => ts('Day'),
868 'week' => ts('Week'),
869 'month' => ts('Month'),
870 'year' => ts('Year'),
871 );
f80ce889 872 }
56251ea7 873
874 /**
f9e31d7f 875 * Extension types.
76e7a76c
CW
876 *
877 * @return array
56251ea7 878 */
00be9182 879 public static function getExtensionTypes() {
2aa397bc 880 return array(
c3831ebd
EM
881 'payment' => ts('Payment'),
882 'search' => ts('Search'),
883 'report' => ts('Report'),
884 'module' => ts('Module'),
885 'sms' => ts('SMS'),
886 );
56251ea7 887 }
888
889 /**
f9e31d7f 890 * Job frequency.
76e7a76c
CW
891 *
892 * @return array
56251ea7 893 */
00be9182 894 public static function getJobFrequency() {
c3831ebd 895 return array(
bda41fcb
DRJ
896 // CRM-17669
897 'Yearly' => ts('Yearly'),
898 'Quarter' => ts('Quarterly'),
899 'Monthly' => ts('Monthly'),
900 'Weekly' => ts('Weekly'),
901
c3831ebd
EM
902 'Daily' => ts('Daily'),
903 'Hourly' => ts('Hourly'),
904 'Always' => ts('Every time cron job is run'),
905 );
56251ea7 906 }
e204d358 907
908 /**
f9e31d7f 909 * Search builder operators.
76e7a76c
CW
910 *
911 * @return array
e204d358 912 */
ed56d481 913 public static function getSearchBuilderOperators($fieldType = NULL) {
759094bd 914 $builderOperators = array(
c3831ebd
EM
915 '=' => '=',
916 '!=' => '≠',
917 '>' => '>',
918 '<' => '<',
919 '>=' => '≥',
920 '<=' => '≤',
921 'IN' => ts('In'),
afa0b07c 922 'NOT IN' => ts('Not In'),
c3831ebd 923 'LIKE' => ts('Like'),
afa0b07c 924 'NOT LIKE' => ts('Not Like'),
c3831ebd
EM
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 );
759094bd
UP
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;
e204d358 942 }
943
944 /**
f9e31d7f 945 * Profile group types.
e204d358 946 *
76e7a76c 947 * @return array
e204d358 948 */
00be9182 949 public static function getProfileGroupType() {
c3831ebd
EM
950 $profileGroupType = array(
951 'Activity' => ts('Activities'),
952 'Contribution' => ts('Contributions'),
953 'Membership' => ts('Memberships'),
954 'Participant' => ts('Participants'),
955 );
956 $contactTypes = self::contactType();
6795600d 957 $contactTypes = !empty($contactTypes) ? array('Contact' => 'Contacts') + $contactTypes : array();
481a74f4 958 $profileGroupType = array_merge($contactTypes, $profileGroupType);
c3831ebd 959
e204d358 960 return $profileGroupType;
961 }
962
963
964 /**
f9e31d7f 965 * Word replacement match type.
76e7a76c
CW
966 *
967 * @return array
e204d358 968 */
00be9182 969 public static function getWordReplacementMatchType() {
c3831ebd 970 return array(
353ffa53
TO
971 'exactMatch' => ts('Exact Match'),
972 'wildcardMatch' => ts('Wildcard Match'),
973 );
e204d358 974 }
975
71a707c3 976 /**
f9e31d7f 977 * Mailing group types.
76e7a76c
CW
978 *
979 * @return array
71a707c3 980 */
00be9182 981 public static function getMailingGroupTypes() {
c3831ebd
EM
982 return array(
983 'Include' => ts('Include'),
984 'Exclude' => ts('Exclude'),
985 'Base' => ts('Base'),
986 );
71a707c3 987 }
988
989 /**
f9e31d7f 990 * Mailing Job Status.
76e7a76c
CW
991 *
992 * @return array
71a707c3 993 */
00be9182 994 public static function getMailingJobStatus() {
c3831ebd
EM
995 return array(
996 'Scheduled' => ts('Scheduled'),
997 'Running' => ts('Running'),
998 'Complete' => ts('Complete'),
999 'Paused' => ts('Paused'),
1000 'Canceled' => ts('Canceled'),
1001 );
71a707c3 1002 }
1003
76e7a76c
CW
1004 /**
1005 * @return array
1006 */
00be9182 1007 public static function billingMode() {
280f1b05
CW
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
9775f926 1015 /**
f9e31d7f 1016 * Frequency unit for schedule reminders.
76e7a76c 1017 *
8fe4b69f
CW
1018 * @param int $count
1019 * For pluralization
76e7a76c 1020 * @return array
9775f926 1021 */
8fe4b69f
CW
1022 public static function getRecurringFrequencyUnits($count = 1) {
1023 // @todo this used to refer to the 'recur_frequency_unit' option_values which
1024 // is for recurring payments and probably not good to re-use for recurring entities.
1025 // If something other than a hard-coded list is desired, add a new option_group.
1026 return array(
1027 'hour' => ts('hour', array('plural' => 'hours', 'count' => $count)),
1028 'day' => ts('day', array('plural' => 'days', 'count' => $count)),
1029 'week' => ts('week', array('plural' => 'weeks', 'count' => $count)),
1030 'month' => ts('month', array('plural' => 'months', 'count' => $count)),
1031 'year' => ts('year', array('plural' => 'years', 'count' => $count)),
1032 );
9775f926 1033 }
96025800 1034
7537a84b
J
1035 /**
1036 * Relative Date Terms.
1037 *
1038 * @return array
1039 */
1040 public static function getRelativeDateTerms() {
1041 return array(
1042 'previous' => ts('Previous'),
1043 'previous_2' => ts('Previous 2'),
1044 'previous_before' => ts('Prior to Previous'),
1045 'before_previous' => ts('All Prior to Previous'),
1046 'earlier' => ts('To End of Previous'),
1047 'greater_previous' => ts('From End of Previous'),
1048 'greater' => ts('From Start Of Current'),
1049 'current' => ts('Current'),
1050 'ending_3' => ts('Last 3'),
1051 'ending_2' => ts('Last 2'),
1052 'ending' => ts('Last'),
1053 'this' => ts('This'),
1054 'starting' => ts('Upcoming'),
1055 'less' => ts('To End of'),
1056 'next' => ts('Next'),
1057 );
1058 }
1059
1060 /**
1061 * Relative Date Units.
1062 *
1063 * @return array
1064 */
1065 public static function getRelativeDateUnits() {
1066 return array(
1067 'year' => ts('Years'),
1068 'fiscal_year' => ts('Fiscal Years'),
1069 'quarter' => ts('Quarters'),
1070 'month' => ts('Months'),
1071 'week' => ts('Weeks'),
1072 'day' => ts('Days'),
1073 );
1074 }
1075
0aeb5a1e
CW
1076 /**
1077 * Exportable document formats.
1078 *
1079 * @return array
1080 */
1081 public static function documentFormat() {
1082 return array(
1083 'pdf' => ts('Portable Document Format (.pdf)'),
1084 'docx' => ts('MS Word (.docx)'),
1085 'odt' => ts('Open Office (.odt)'),
1086 'html' => ts('Webpage (.html)'),
1087 );
1088 }
1089
90a73810 1090 /**
1091 * Application type of document.
1092 *
1093 * @return array
1094 */
1095 public static function documentApplicationType() {
1096 return array(
1097 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
1098 'odt' => 'application/vnd.oasis.opendocument.text',
1099 );
1100 }
1101
6a488035 1102}