Merge pull request #14133 from civicrm/5.13
[civicrm-core.git] / CRM / Core / SelectValues.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
fee14197 4 | CiviCRM version 5 |
6a488035 5 +--------------------------------------------------------------------+
6b83d5bd 6 | Copyright CiviCRM LLC (c) 2004-2019 |
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
6b83d5bd 34 * @copyright CiviCRM LLC (c) 2004-2019
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() {
be2fb01f 46 return [
14f42e31
CW
47 1 => ts('Yes'),
48 0 => ts('No'),
be2fb01f 49 ];
14f42e31
CW
50 }
51
6a488035 52 /**
f9e31d7f 53 * Preferred mail format.
79d7553f 54 *
76e7a76c 55 * @return array
6a488035 56 */
00be9182 57 public static function pmf() {
be2fb01f 58 return [
6795600d
CW
59 'Both' => ts('Both'),
60 'HTML' => ts('HTML'),
61 'Text' => ts('Text'),
be2fb01f 62 ];
6a488035
TO
63 }
64
65 /**
f9e31d7f 66 * Privacy options.
76e7a76c
CW
67 *
68 * @return array
6a488035 69 */
00be9182 70 public static function privacy() {
be2fb01f 71 return [
6795600d
CW
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)'),
be2fb01f 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) {
be2fb01f 101 $unitList = [
c3831ebd
EM
102 'day' => ts('day'),
103 'month' => ts('month'),
104 'year' => ts('year'),
be2fb01f 105 ];
c3831ebd 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() {
be2fb01f 127 return [
c3831ebd
EM
128 'rolling' => ts('Rolling'),
129 'fixed' => ts('Fixed'),
be2fb01f 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() {
be2fb01f 139 return [
bac4cd35 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"),
be2fb01f 144 ];
bac4cd35 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() {
be2fb01f 153 return [
ab5e0c41
CW
154 'Public' => ts('Public'),
155 'Admin' => ts('Admin'),
be2fb01f 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() {
be2fb01f 165 return [
dbd82592
CW
166 ts('No auto-renew option'),
167 ts('Give option, but not required'),
21dfd5f5 168 ts('Auto-renew required'),
be2fb01f 169 ];
dbd82592
CW
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() {
be2fb01f 178 return [
c3831ebd
EM
179 'start_date' => ts('start date'),
180 'end_date' => ts('end date'),
181 'join_date' => ts('member since'),
be2fb01f 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() {
be2fb01f 191 return [
c3831ebd
EM
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'),
c3831ebd 206 'Link' => ts('Link'),
79dc94e4 207 'ContactReference' => ts('Autocomplete-Select'),
be2fb01f 208 ];
6a488035
TO
209 }
210
211 /**
f9e31d7f 212 * Various pre defined extensions for dynamic properties and groups.
6a488035 213 *
76e7a76c
CW
214 * @return array
215 *
6a488035 216 */
00be9182 217 public static function customGroupExtends() {
be2fb01f 218 $customGroupExtends = [
c3831ebd
EM
219 'Activity' => ts('Activities'),
220 'Relationship' => ts('Relationships'),
221 'Contribution' => ts('Contributions'),
95974e8e 222 'ContributionRecur' => ts('Recurring Contributions'),
c3831ebd
EM
223 'Group' => ts('Groups'),
224 'Membership' => ts('Memberships'),
225 'Event' => ts('Events'),
226 'Participant' => ts('Participants'),
227 'ParticipantRole' => ts('Participants (Role)'),
228 'ParticipantEventName' => ts('Participants (Event Name)'),
229 'ParticipantEventType' => ts('Participants (Event Type)'),
230 'Pledge' => ts('Pledges'),
231 'Grant' => ts('Grants'),
232 'Address' => ts('Addresses'),
233 'Campaign' => ts('Campaigns'),
be2fb01f 234 ];
c3831ebd 235 $contactTypes = self::contactType();
be2fb01f 236 $contactTypes = !empty($contactTypes) ? ['Contact' => 'Contacts'] + $contactTypes : [];
6795600d 237 $extendObjs = CRM_Core_OptionGroup::values('cg_extend_objects');
c3831ebd 238 $customGroupExtends = array_merge($contactTypes, $customGroupExtends, $extendObjs);
6a488035
TO
239 return $customGroupExtends;
240 }
241
242 /**
f9e31d7f 243 * Styles for displaying the custom data group.
6a488035 244 *
76e7a76c 245 * @return array
6a488035 246 */
00be9182 247 public static function customGroupStyle() {
be2fb01f 248 return [
c3831ebd
EM
249 'Tab' => ts('Tab'),
250 'Inline' => ts('Inline'),
251 'Tab with table' => ts('Tab with table'),
be2fb01f 252 ];
6a488035
TO
253 }
254
255 /**
f9e31d7f 256 * For displaying the uf group types.
6a488035 257 *
76e7a76c 258 * @return array
6a488035 259 */
00be9182 260 public static function ufGroupTypes() {
be2fb01f 261 $ufGroupType = [
c3831ebd
EM
262 'Profile' => ts('Standalone Form or Directory'),
263 'Search Profile' => ts('Search Views'),
be2fb01f 264 ];
c3831ebd
EM
265
266 if (CRM_Core_Config::singleton()->userSystem->supports_form_extensions) {
be2fb01f 267 $ufGroupType += [
c3831ebd
EM
268 'User Registration' => ts('Drupal User Registration'),
269 'User Account' => ts('View/Edit Drupal User Account'),
be2fb01f 270 ];
6a488035
TO
271 }
272 return $ufGroupType;
273 }
274
275 /**
f9e31d7f 276 * The status of a contact within a group.
6a488035 277 *
76e7a76c 278 * @return array
6a488035 279 */
00be9182 280 public static function groupContactStatus() {
be2fb01f 281 return [
c3831ebd
EM
282 'Added' => ts('Added'),
283 'Removed' => ts('Removed'),
284 'Pending' => ts('Pending'),
be2fb01f 285 ];
6a488035
TO
286 }
287
288 /**
f9e31d7f 289 * List of Group Types.
76e7a76c
CW
290 *
291 * @return array
6a488035 292 */
00be9182 293 public static function groupType() {
be2fb01f 294 return [
c3831ebd
EM
295 'query' => ts('Dynamic'),
296 'static' => ts('Static'),
be2fb01f 297 ];
6a488035
TO
298 }
299
300 /**
f9e31d7f 301 * Compose the parameters for a date select object.
6a488035 302 *
76e7a76c
CW
303 * @param string|NULL $type
304 * the type of date
305 * @param string|NULL $format
306 * date format (QF format)
9bf2a591
EM
307 * @param null $minOffset
308 * @param null $maxOffset
518fa0ee 309 * @param string $context
a6c01b45
CW
310 * @return array
311 * the date array
6a488035 312 */
1285ac45 313 public static function date($type = NULL, $format = NULL, $minOffset = NULL, $maxOffset = NULL, $context = 'display') {
314 // These options are deprecated. Definitely not used in datepicker. Possibly not even in jcalendar+addDateTime.
be2fb01f 315 $date = [
6a488035
TO
316 'addEmptyOption' => TRUE,
317 'emptyOptionText' => ts('- select -'),
318 'emptyOptionValue' => '',
be2fb01f 319 ];
6a488035
TO
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 }
1285ac45 331 if (!$maxOffset) {
332 $maxOffset = $dao->end;
333 }
334 if (!$minOffset) {
335 $minOffset = $dao->start;
336 }
6a488035 337
6a488035 338 $date['format'] = $dao->date_format;
1285ac45 339 $date['time'] = (bool) $dao->time_format;
6a488035
TO
340 }
341
a7488080 342 if (empty($date['format'])) {
1285ac45 343 if ($context == 'Input') {
344 $date['format'] = Civi::settings()->get('dateInputFormat');
1285ac45 345 }
346 else {
347 $date['format'] = 'M d';
348 }
6a488035
TO
349 }
350 }
2732685b 351
ed0ca248 352 $date['smarty_view_format'] = CRM_Utils_Date::getDateFieldViewFormat($date['format']);
1285ac45 353 if (!isset($date['time'])) {
354 $date['time'] = FALSE;
355 }
6a488035 356
6795600d 357 $year = date('Y');
1285ac45 358 $date['minYear'] = $year - (int) $minOffset;
359 $date['maxYear'] = $year + (int) $maxOffset;
6a488035
TO
360 return $date;
361 }
362
363 /**
f9e31d7f 364 * Values for UF form visibility options.
6a488035 365 *
76e7a76c 366 * @return array
6a488035 367 */
00be9182 368 public static function ufVisibility() {
be2fb01f 369 return [
c3831ebd 370 'User and User Admin Only' => ts('User and User Admin Only'),
fac01cb1
DG
371 'Public Pages' => ts('Expose Publicly'),
372 'Public Pages and Listings' => ts('Expose Publicly and for Listings'),
be2fb01f 373 ];
6a488035
TO
374 }
375
93bfa565 376 /**
f9e31d7f 377 * Values for group form visibility options.
93bfa565 378 *
76e7a76c 379 * @return array
93bfa565 380 */
00be9182 381 public static function groupVisibility() {
be2fb01f 382 return [
6795600d
CW
383 'User and User Admin Only' => ts('User and User Admin Only'),
384 'Public Pages' => ts('Public Pages'),
be2fb01f 385 ];
93bfa565 386 }
387
6a488035 388 /**
f9e31d7f 389 * Different type of Mailing Components.
6a488035 390 *
76e7a76c 391 * @return array
6a488035 392 */
00be9182 393 public static function mailingComponents() {
be2fb01f 394 return [
353ffa53 395 'Header' => ts('Header'),
c3831ebd
EM
396 'Footer' => ts('Footer'),
397 'Reply' => ts('Reply Auto-responder'),
398 'OptOut' => ts('Opt-out Message'),
399 'Subscribe' => ts('Subscription Confirmation Request'),
400 'Welcome' => ts('Welcome Message'),
401 'Unsubscribe' => ts('Unsubscribe Message'),
402 'Resubscribe' => ts('Resubscribe Message'),
be2fb01f 403 ];
6a488035
TO
404 }
405
406 /**
f9e31d7f 407 * Get hours.
6a488035 408 *
76e7a76c 409 * @return array
6a488035 410 */
00be9182 411 public function getHours() {
be2fb01f 412 $hours = [];
6a488035
TO
413 for ($i = 0; $i <= 6; $i++) {
414 $hours[$i] = $i;
415 }
416 return $hours;
417 }
418
419 /**
f9e31d7f 420 * Get minutes.
6a488035 421 *
76e7a76c 422 * @return array
6a488035 423 */
00be9182 424 public function getMinutes() {
be2fb01f 425 $minutes = [];
6a488035
TO
426 for ($i = 0; $i < 60; $i = $i + 15) {
427 $minutes[$i] = $i;
428 }
429 return $minutes;
430 }
431
432 /**
f9e31d7f 433 * Get the Map Provider.
6a488035 434 *
a6c01b45
CW
435 * @return array
436 * array of map providers
6a488035 437 */
00be9182 438 public static function mapProvider() {
6a488035
TO
439 static $map = NULL;
440 if (!$map) {
be2fb01f 441 $map = ['' => '- select -'] + CRM_Utils_System::getPluginList('templates/CRM/Contact/Form/Task/Map', ".tpl");
6a488035
TO
442 }
443 return $map;
444 }
445
446 /**
f9e31d7f 447 * Get the Geocoding Providers from available plugins.
6a488035 448 *
a6c01b45
CW
449 * @return array
450 * array of geocoder providers
6a488035 451 */
00be9182 452 public static function geoProvider() {
6a488035
TO
453 static $geo = NULL;
454 if (!$geo) {
be2fb01f 455 $geo = ['' => '- select -'] + CRM_Utils_System::getPluginList('CRM/Utils/Geocode');
6a488035
TO
456 }
457 return $geo;
458 }
459
460 /**
f9e31d7f 461 * Get the Address Standardization Providers from available plugins.
6a488035 462 *
a6c01b45
CW
463 * @return array
464 * array of address standardization providers
6a488035 465 */
00be9182 466 public static function addressProvider() {
6a488035
TO
467 static $addr = NULL;
468 if (!$addr) {
be2fb01f 469 $addr = array_merge(['' => '- select -'], CRM_Utils_System::getPluginList('CRM/Utils/Address', '.php', ['BatchUpdate']));
6a488035
TO
470 }
471 return $addr;
472 }
473
474 /**
f9e31d7f 475 * Different type of Mailing Tokens.
6a488035 476 *
76e7a76c 477 * @return array
6a488035 478 */
00be9182 479 public static function mailingTokens() {
be2fb01f 480 return [
c3831ebd
EM
481 '{action.unsubscribe}' => ts('Unsubscribe via email'),
482 '{action.unsubscribeUrl}' => ts('Unsubscribe via web page'),
483 '{action.resubscribe}' => ts('Resubscribe via email'),
484 '{action.resubscribeUrl}' => ts('Resubscribe via web page'),
485 '{action.optOut}' => ts('Opt out via email'),
486 '{action.optOutUrl}' => ts('Opt out via web page'),
487 '{action.forward}' => ts('Forward this email (link)'),
488 '{action.reply}' => ts('Reply to this email (link)'),
489 '{action.subscribeUrl}' => ts('Subscribe via web page'),
490 '{domain.name}' => ts('Domain name'),
491 '{domain.address}' => ts('Domain (organization) address'),
492 '{domain.phone}' => ts('Domain (organization) phone'),
493 '{domain.email}' => ts('Domain (organization) email'),
494 '{mailing.name}' => ts('Mailing name'),
495 '{mailing.group}' => ts('Mailing group'),
496 '{mailing.viewUrl}' => ts('Mailing permalink'),
be2fb01f 497 ];
6a488035
TO
498 }
499
500 /**
f9e31d7f 501 * Different type of Activity Tokens.
6a488035 502 *
76e7a76c 503 * @return array
6a488035 504 */
00be9182 505 public static function activityTokens() {
be2fb01f 506 return [
c3831ebd
EM
507 '{activity.activity_id}' => ts('Activity ID'),
508 '{activity.subject}' => ts('Activity Subject'),
509 '{activity.details}' => ts('Activity Details'),
510 '{activity.activity_date_time}' => ts('Activity Date Time'),
be2fb01f 511 ];
6a488035
TO
512 }
513
514 /**
f9e31d7f 515 * Different type of Membership Tokens.
6a488035 516 *
76e7a76c 517 * @return array
6a488035 518 */
00be9182 519 public static function membershipTokens() {
be2fb01f 520 return [
c3831ebd
EM
521 '{membership.id}' => ts('Membership ID'),
522 '{membership.status}' => ts('Membership Status'),
523 '{membership.type}' => ts('Membership Type'),
524 '{membership.start_date}' => ts('Membership Start Date'),
525 '{membership.join_date}' => ts('Membership Join Date'),
526 '{membership.end_date}' => ts('Membership End Date'),
527 '{membership.fee}' => ts('Membership Fee'),
be2fb01f 528 ];
6a488035
TO
529 }
530
531 /**
f9e31d7f 532 * Different type of Event Tokens.
6a488035 533 *
76e7a76c 534 * @return array
6a488035 535 */
00be9182 536 public static function eventTokens() {
be2fb01f 537 return [
c3831ebd
EM
538 '{event.event_id}' => ts('Event ID'),
539 '{event.title}' => ts('Event Title'),
540 '{event.start_date}' => ts('Event Start Date'),
541 '{event.end_date}' => ts('Event End Date'),
542 '{event.event_type}' => ts('Event Type'),
543 '{event.summary}' => ts('Event Summary'),
544 '{event.contact_email}' => ts('Event Contact Email'),
545 '{event.contact_phone}' => ts('Event Contact Phone'),
546 '{event.description}' => ts('Event Description'),
547 '{event.location}' => ts('Event Location'),
548 '{event.fee_amount}' => ts('Event Fees'),
549 '{event.info_url}' => ts('Event Info URL'),
550 '{event.registration_url}' => ts('Event Registration URL'),
21dfd5f5 551 '{event.balance}' => ts('Event Balance'),
be2fb01f 552 ];
6a488035
TO
553 }
554
555 /**
f9e31d7f 556 * Different type of Event Tokens.
6a488035 557 *
76e7a76c 558 * @return array
6a488035 559 */
00be9182 560 public static function contributionTokens() {
be2fb01f 561 return array_merge([
c3831ebd
EM
562 '{contribution.contribution_id}' => ts('Contribution ID'),
563 '{contribution.total_amount}' => ts('Total Amount'),
564 '{contribution.fee_amount}' => ts('Fee Amount'),
565 '{contribution.net_amount}' => ts('Net Amount'),
c94fc35e 566 '{contribution.non_deductible_amount}' => ts('Non-deductible Amount'),
7bc6b5bb 567 '{contribution.receive_date}' => ts('Contribution Date Received'),
536f0e02 568 '{contribution.payment_instrument}' => ts('Payment Method'),
c3831ebd
EM
569 '{contribution.trxn_id}' => ts('Transaction ID'),
570 '{contribution.invoice_id}' => ts('Invoice ID'),
571 '{contribution.currency}' => ts('Currency'),
572 '{contribution.cancel_date}' => ts('Contribution Cancel Date'),
573 '{contribution.cancel_reason}' => ts('Contribution Cancel Reason'),
574 '{contribution.receipt_date}' => ts('Receipt Date'),
575 '{contribution.thankyou_date}' => ts('Thank You Date'),
576 '{contribution.contribution_source}' => ts('Contribution Source'),
577 '{contribution.amount_level}' => ts('Amount Level'),
578 //'{contribution.contribution_recur_id}' => ts('Contribution Recurring ID'),
579 //'{contribution.honor_contact_id}' => ts('Honor Contact ID'),
580 '{contribution.contribution_status_id}' => ts('Contribution Status'),
581 //'{contribution.honor_type_id}' => ts('Honor Type ID'),
582 //'{contribution.address_id}' => ts('Address ID'),
583 '{contribution.check_number}' => ts('Check Number'),
584 '{contribution.campaign}' => ts('Contribution Campaign'),
be2fb01f 585 ], CRM_Utils_Token::getCustomFieldTokens('contribution', TRUE));
6a488035
TO
586 }
587
588 /**
f9e31d7f 589 * Different type of Contact Tokens.
6a488035 590 *
76e7a76c 591 * @return array
6a488035 592 */
00be9182 593 public static function contactTokens() {
6a488035
TO
594 static $tokens = NULL;
595 if (!$tokens) {
be2fb01f
CW
596 $additionalFields = [
597 'checksum' => ['title' => ts('Checksum')],
598 'contact_id' => ['title' => ts('Internal Contact ID')],
599 ];
6a488035
TO
600 $exportFields = array_merge(CRM_Contact_BAO_Contact::exportableFields(), $additionalFields);
601
602 $values = array_merge(array_keys($exportFields));
603 unset($values[0]);
604
605 //FIXME:skipping some tokens for time being.
be2fb01f 606 $skipTokens = [
353ffa53
TO
607 'is_bulkmail',
608 'group',
609 'tag',
610 'contact_sub_type',
611 'note',
612 'is_deceased',
613 'deceased_date',
614 'legal_identifier',
615 'contact_sub_type',
616 'user_unique_id',
be2fb01f 617 ];
ea921622 618
be2fb01f 619 $customFields = CRM_Core_BAO_CustomField::getFields(['Individual', 'Address']);
cc615373 620 $legacyTokenNames = array_flip(CRM_Utils_Token::legacyContactTokens());
6a488035 621
cc615373 622 foreach ($values as $val) {
6a488035
TO
623 if (in_array($val, $skipTokens)) {
624 continue;
625 }
626 //keys for $tokens should be constant. $token Values are changed for Custom Fields. CRM-3734
72e34731
CW
627 $customFieldId = CRM_Core_BAO_CustomField::getKeyID($val);
628 if ($customFieldId) {
629 // CRM-15191 - if key is not in $customFields then the field is disabled and should be ignored
630 if (!empty($customFields[$customFieldId])) {
631 $tokens["{contact.$val}"] = $customFields[$customFieldId]['label'] . " :: " . $customFields[$customFieldId]['groupTitle'];
632 }
6a488035
TO
633 }
634 else {
cc615373
CW
635 // Support legacy token names
636 $tokenName = CRM_Utils_Array::value($val, $legacyTokenNames, $val);
637 $tokens["{contact.$tokenName}"] = $exportFields[$val]['title'];
6a488035
TO
638 }
639 }
640
9950a1c9 641 // Get all the hook tokens too
be2fb01f 642 $hookTokens = [];
6a488035 643 CRM_Utils_Hook::tokens($hookTokens);
94bf1070 644 foreach ($hookTokens as $tokenValues) {
6a488035
TO
645 foreach ($tokenValues as $key => $value) {
646 if (is_numeric($key)) {
647 $key = $value;
648 }
649 if (!preg_match('/^\{[^\}]+\}$/', $key)) {
650 $key = '{' . $key . '}';
651 }
652 if (preg_match('/^\{([^\}]+)\}$/', $value, $matches)) {
653 $value = $matches[1];
654 }
655 $tokens[$key] = $value;
656 }
657 }
658 }
659
660 return $tokens;
661 }
662
ea921622 663 /**
f9e31d7f 664 * Different type of Participant Tokens.
ea921622 665 *
76e7a76c 666 * @return array
ea921622 667 */
00be9182 668 public static function participantTokens() {
ea921622
KJ
669 static $tokens = NULL;
670 if (!$tokens) {
671 $exportFields = CRM_Event_BAO_Participant::exportableFields();
672
673 $values = array_merge(array_keys($exportFields));
674 unset($values[0]);
675
676 // skipping some tokens for time being.
be2fb01f 677 $skipTokens = [
353ffa53
TO
678 'event_id',
679 'participant_is_pay_later',
680 'participant_is_test',
681 'participant_contact_id',
682 'participant_fee_currency',
683 'participant_campaign_id',
684 'participant_status',
685 'participant_discount_name',
be2fb01f 686 ];
ea921622
KJ
687
688 $customFields = CRM_Core_BAO_CustomField::getFields('Participant');
689
690 foreach ($values as $key => $val) {
691 if (in_array($val, $skipTokens)) {
692 continue;
693 }
694 //keys for $tokens should be constant. $token Values are changed for Custom Fields. CRM-3734
695 if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($val)) {
0d8afee2 696 $tokens["{participant.$val}"] = !empty($customFields[$customFieldId]) ? $customFields[$customFieldId]['label'] . " :: " . $customFields[$customFieldId]['groupTitle'] : '';
ea921622
KJ
697 }
698 else {
699 $tokens["{participant.$val}"] = $exportFields[$val]['title'];
700 }
701 }
702 }
703 return $tokens;
704 }
705
07945b3c 706 /**
0fe4153d 707 * @param int $caseTypeId
07945b3c
CW
708 * @return array
709 */
0fe4153d 710 public static function caseTokens($caseTypeId = NULL) {
07945b3c
CW
711 static $tokens = NULL;
712 if (!$tokens) {
713 foreach (CRM_Case_BAO_Case::fields() as $field) {
714 $tokens["{case.{$field['name']}}"] = $field['title'];
715 }
716
0fe4153d 717 $customFields = CRM_Core_BAO_CustomField::getFields('Case', FALSE, FALSE, $caseTypeId);
07945b3c
CW
718 foreach ($customFields as $id => $field) {
719 $tokens["{case.custom_$id}"] = "{$field['label']} :: {$field['groupTitle']}";
720 }
721 }
722 return $tokens;
723 }
724
6a488035 725 /**
f9e31d7f 726 * CiviCRM supported date input formats.
76e7a76c
CW
727 *
728 * @return array
6a488035 729 */
00be9182 730 public static function getDatePluginInputFormats() {
be2fb01f 731 $dateInputFormats = [
6a488035
TO
732 "mm/dd/yy" => ts('mm/dd/yyyy (12/31/2009)'),
733 "dd/mm/yy" => ts('dd/mm/yyyy (31/12/2009)'),
734 "yy-mm-dd" => ts('yyyy-mm-dd (2009-12-31)'),
735 "dd-mm-yy" => ts('dd-mm-yyyy (31-12-2009)'),
736 'dd.mm.yy' => ts('dd.mm.yyyy (31.12.2009)'),
737 "M d, yy" => ts('M d, yyyy (Dec 31, 2009)'),
738 'd M yy' => ts('d M yyyy (31 Dec 2009)'),
739 "MM d, yy" => ts('MM d, yyyy (December 31, 2009)'),
740 'd MM yy' => ts('d MM yyyy (31 December 2009)'),
741 "DD, d MM yy" => ts('DD, d MM yyyy (Thursday, 31 December 2009)'),
742 "mm/dd" => ts('mm/dd (12/31)'),
743 "dd-mm" => ts('dd-mm (31-12)'),
744 "yy-mm" => ts('yyyy-mm (2009-12)'),
745 'M yy' => ts('M yyyy (Dec 2009)'),
746 "yy" => ts('yyyy (2009)'),
be2fb01f 747 ];
6a488035
TO
748
749 /*
e70a7fc0
TO
750 Year greater than 2000 get wrong result for following format
751 echo date( 'Y-m-d', strtotime( '7 Nov, 2001') );
752 echo date( 'Y-m-d', strtotime( '7 November, 2001') );
753 Return current year
754 expected :: 2001-11-07
755 output :: 2009-11-07
756 However
757 echo date( 'Y-m-d', strtotime( 'Nov 7, 2001') );
758 echo date( 'Y-m-d', strtotime( 'November 7, 2001') );
759 gives proper result
76e7a76c 760 */
6a488035 761
6a488035
TO
762 return $dateInputFormats;
763 }
764
6a488035 765 /**
f9e31d7f 766 * Time formats.
76e7a76c
CW
767 *
768 * @return array
6a488035 769 */
00be9182 770 public static function getTimeFormats() {
be2fb01f 771 return [
6795600d 772 '1' => ts('12 Hours'),
6a488035 773 '2' => ts('24 Hours'),
be2fb01f 774 ];
6a488035
TO
775 }
776
777 /**
f9e31d7f 778 * Get numeric options.
79d7553f 779 *
76e7a76c
CW
780 * @param int $start
781 * @param int $end
6a488035 782 *
76e7a76c 783 * @return array
6a488035
TO
784 */
785 public static function getNumericOptions($start = 0, $end = 10) {
be2fb01f 786 $numericOptions = [];
6a488035 787 for ($i = $start; $i <= $end; $i++) {
2aa397bc 788 $numericOptions[$i] = $i;
6a488035
TO
789 }
790 return $numericOptions;
791 }
f38395f7
KJ
792
793 /**
f9e31d7f 794 * Barcode types.
76e7a76c
CW
795 *
796 * @return array
f38395f7 797 */
00be9182 798 public static function getBarcodeTypes() {
be2fb01f 799 return [
c3831ebd
EM
800 'barcode' => ts('Linear (1D)'),
801 'qrcode' => ts('QR code'),
be2fb01f 802 ];
f38395f7 803 }
77d0b1f8 804
805 /**
f9e31d7f 806 * Dedupe rule types.
76e7a76c
CW
807 *
808 * @return array
77d0b1f8 809 */
00be9182 810 public static function getDedupeRuleTypes() {
be2fb01f 811 return [
c3831ebd
EM
812 'Unsupervised' => ts('Unsupervised'),
813 'Supervised' => ts('Supervised'),
814 'General' => ts('General'),
be2fb01f 815 ];
77d0b1f8 816 }
f80ce889 817
818 /**
f9e31d7f 819 * Campaign group types.
76e7a76c
CW
820 *
821 * @return array
f80ce889 822 */
00be9182 823 public static function getCampaignGroupTypes() {
be2fb01f 824 return [
c3831ebd
EM
825 'Include' => ts('Include'),
826 'Exclude' => ts('Exclude'),
be2fb01f 827 ];
f80ce889 828 }
829
830 /**
f9e31d7f 831 * Subscription history method.
76e7a76c
CW
832 *
833 * @return array
f80ce889 834 */
00be9182 835 public static function getSubscriptionHistoryMethods() {
be2fb01f 836 return [
c3831ebd
EM
837 'Admin' => ts('Admin'),
838 'Email' => ts('Email'),
839 'Web' => ts('Web'),
840 'API' => ts('API'),
be2fb01f 841 ];
f80ce889 842 }
843
844 /**
f9e31d7f 845 * Premium units.
76e7a76c
CW
846 *
847 * @return array
f80ce889 848 */
00be9182 849 public static function getPremiumUnits() {
be2fb01f 850 return [
c3831ebd
EM
851 'day' => ts('Day'),
852 'week' => ts('Week'),
853 'month' => ts('Month'),
854 'year' => ts('Year'),
be2fb01f 855 ];
f80ce889 856 }
56251ea7 857
858 /**
f9e31d7f 859 * Extension types.
76e7a76c
CW
860 *
861 * @return array
56251ea7 862 */
00be9182 863 public static function getExtensionTypes() {
be2fb01f 864 return [
c3831ebd
EM
865 'payment' => ts('Payment'),
866 'search' => ts('Search'),
867 'report' => ts('Report'),
868 'module' => ts('Module'),
869 'sms' => ts('SMS'),
be2fb01f 870 ];
56251ea7 871 }
872
873 /**
f9e31d7f 874 * Job frequency.
76e7a76c
CW
875 *
876 * @return array
56251ea7 877 */
00be9182 878 public static function getJobFrequency() {
be2fb01f 879 return [
bda41fcb
DRJ
880 // CRM-17669
881 'Yearly' => ts('Yearly'),
882 'Quarter' => ts('Quarterly'),
883 'Monthly' => ts('Monthly'),
884 'Weekly' => ts('Weekly'),
885
c3831ebd
EM
886 'Daily' => ts('Daily'),
887 'Hourly' => ts('Hourly'),
888 'Always' => ts('Every time cron job is run'),
be2fb01f 889 ];
56251ea7 890 }
e204d358 891
892 /**
f9e31d7f 893 * Search builder operators.
76e7a76c
CW
894 *
895 * @return array
e204d358 896 */
ed56d481 897 public static function getSearchBuilderOperators($fieldType = NULL) {
80beace7 898 return [
c3831ebd
EM
899 '=' => '=',
900 '!=' => '≠',
901 '>' => '>',
902 '<' => '<',
903 '>=' => '≥',
904 '<=' => '≤',
905 'IN' => ts('In'),
afa0b07c 906 'NOT IN' => ts('Not In'),
c3831ebd 907 'LIKE' => ts('Like'),
afa0b07c 908 'NOT LIKE' => ts('Not Like'),
c3831ebd
EM
909 'RLIKE' => ts('Regex'),
910 'IS EMPTY' => ts('Is Empty'),
911 'IS NOT EMPTY' => ts('Not Empty'),
912 'IS NULL' => ts('Is Null'),
913 'IS NOT NULL' => ts('Not Null'),
80beace7 914 ];
e204d358 915 }
916
917 /**
f9e31d7f 918 * Profile group types.
e204d358 919 *
76e7a76c 920 * @return array
e204d358 921 */
00be9182 922 public static function getProfileGroupType() {
be2fb01f 923 $profileGroupType = [
c3831ebd
EM
924 'Activity' => ts('Activities'),
925 'Contribution' => ts('Contributions'),
926 'Membership' => ts('Memberships'),
927 'Participant' => ts('Participants'),
be2fb01f 928 ];
c3831ebd 929 $contactTypes = self::contactType();
be2fb01f 930 $contactTypes = !empty($contactTypes) ? ['Contact' => 'Contacts'] + $contactTypes : [];
481a74f4 931 $profileGroupType = array_merge($contactTypes, $profileGroupType);
c3831ebd 932
e204d358 933 return $profileGroupType;
934 }
935
e204d358 936 /**
f9e31d7f 937 * Word replacement match type.
76e7a76c
CW
938 *
939 * @return array
e204d358 940 */
00be9182 941 public static function getWordReplacementMatchType() {
be2fb01f 942 return [
353ffa53
TO
943 'exactMatch' => ts('Exact Match'),
944 'wildcardMatch' => ts('Wildcard Match'),
be2fb01f 945 ];
e204d358 946 }
947
71a707c3 948 /**
f9e31d7f 949 * Mailing group types.
76e7a76c
CW
950 *
951 * @return array
71a707c3 952 */
00be9182 953 public static function getMailingGroupTypes() {
be2fb01f 954 return [
c3831ebd
EM
955 'Include' => ts('Include'),
956 'Exclude' => ts('Exclude'),
957 'Base' => ts('Base'),
be2fb01f 958 ];
71a707c3 959 }
960
961 /**
f9e31d7f 962 * Mailing Job Status.
76e7a76c
CW
963 *
964 * @return array
71a707c3 965 */
00be9182 966 public static function getMailingJobStatus() {
be2fb01f 967 return [
c3831ebd
EM
968 'Scheduled' => ts('Scheduled'),
969 'Running' => ts('Running'),
970 'Complete' => ts('Complete'),
971 'Paused' => ts('Paused'),
972 'Canceled' => ts('Canceled'),
be2fb01f 973 ];
71a707c3 974 }
975
76e7a76c
CW
976 /**
977 * @return array
978 */
00be9182 979 public static function billingMode() {
be2fb01f 980 return [
280f1b05
CW
981 CRM_Core_Payment::BILLING_MODE_FORM => 'form',
982 CRM_Core_Payment::BILLING_MODE_BUTTON => 'button',
983 CRM_Core_Payment::BILLING_MODE_NOTIFY => 'notify',
be2fb01f 984 ];
280f1b05
CW
985 }
986
367b5943 987 /**
988 * @return array
989 */
990 public static function contributeMode() {
be2fb01f 991 return [
367b5943 992 CRM_Core_Payment::BILLING_MODE_FORM => 'direct',
993 CRM_Core_Payment::BILLING_MODE_BUTTON => 'directIPN',
994 CRM_Core_Payment::BILLING_MODE_NOTIFY => 'notify',
be2fb01f 995 ];
367b5943 996 }
997
9775f926 998 /**
f9e31d7f 999 * Frequency unit for schedule reminders.
76e7a76c 1000 *
8fe4b69f
CW
1001 * @param int $count
1002 * For pluralization
76e7a76c 1003 * @return array
9775f926 1004 */
8fe4b69f
CW
1005 public static function getRecurringFrequencyUnits($count = 1) {
1006 // @todo this used to refer to the 'recur_frequency_unit' option_values which
1007 // is for recurring payments and probably not good to re-use for recurring entities.
1008 // If something other than a hard-coded list is desired, add a new option_group.
be2fb01f
CW
1009 return [
1010 'hour' => ts('hour', ['plural' => 'hours', 'count' => $count]),
1011 'day' => ts('day', ['plural' => 'days', 'count' => $count]),
1012 'week' => ts('week', ['plural' => 'weeks', 'count' => $count]),
1013 'month' => ts('month', ['plural' => 'months', 'count' => $count]),
1014 'year' => ts('year', ['plural' => 'years', 'count' => $count]),
1015 ];
9775f926 1016 }
96025800 1017
7537a84b
J
1018 /**
1019 * Relative Date Terms.
1020 *
1021 * @return array
1022 */
1023 public static function getRelativeDateTerms() {
be2fb01f 1024 return [
7537a84b
J
1025 'previous' => ts('Previous'),
1026 'previous_2' => ts('Previous 2'),
1027 'previous_before' => ts('Prior to Previous'),
1028 'before_previous' => ts('All Prior to Previous'),
1029 'earlier' => ts('To End of Previous'),
1030 'greater_previous' => ts('From End of Previous'),
1031 'greater' => ts('From Start Of Current'),
1032 'current' => ts('Current'),
1033 'ending_3' => ts('Last 3'),
1034 'ending_2' => ts('Last 2'),
1035 'ending' => ts('Last'),
1036 'this' => ts('This'),
1037 'starting' => ts('Upcoming'),
1038 'less' => ts('To End of'),
1039 'next' => ts('Next'),
be2fb01f 1040 ];
7537a84b
J
1041 }
1042
1043 /**
1044 * Relative Date Units.
1045 *
1046 * @return array
1047 */
1048 public static function getRelativeDateUnits() {
be2fb01f 1049 return [
7537a84b
J
1050 'year' => ts('Years'),
1051 'fiscal_year' => ts('Fiscal Years'),
1052 'quarter' => ts('Quarters'),
1053 'month' => ts('Months'),
1054 'week' => ts('Weeks'),
1055 'day' => ts('Days'),
be2fb01f 1056 ];
7537a84b
J
1057 }
1058
0aeb5a1e
CW
1059 /**
1060 * Exportable document formats.
1061 *
1062 * @return array
1063 */
1064 public static function documentFormat() {
be2fb01f 1065 return [
0aeb5a1e
CW
1066 'pdf' => ts('Portable Document Format (.pdf)'),
1067 'docx' => ts('MS Word (.docx)'),
1068 'odt' => ts('Open Office (.odt)'),
1069 'html' => ts('Webpage (.html)'),
be2fb01f 1070 ];
0aeb5a1e
CW
1071 }
1072
90a73810 1073 /**
1074 * Application type of document.
1075 *
1076 * @return array
1077 */
1078 public static function documentApplicationType() {
be2fb01f 1079 return [
90a73810 1080 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
1081 'odt' => 'application/vnd.oasis.opendocument.text',
be2fb01f 1082 ];
90a73810 1083 }
1084
1cd7479e 1085 /**
1086 * Activity Text options.
1087 *
1088 * @return array
1089 */
1090 public static function activityTextOptions() {
be2fb01f 1091 return [
1cd7479e 1092 2 => ts('Details Only'),
1093 3 => ts('Subject Only'),
1094 6 => ts('Both'),
be2fb01f 1095 ];
1cd7479e 1096 }
1097
f871c3a9
AS
1098 /**
1099 * Relationship permissions
1100 *
1101 * @return array
1102 */
1103 public static function getPermissionedRelationshipOptions() {
be2fb01f 1104 return [
f871c3a9
AS
1105 CRM_Contact_BAO_Relationship::NONE => ts('None'),
1106 CRM_Contact_BAO_Relationship::VIEW => ts('View only'),
1107 CRM_Contact_BAO_Relationship::EDIT => ts('View and update'),
be2fb01f 1108 ];
f871c3a9
AS
1109 }
1110
f5e8cb7b 1111 /**
1112 * Get option values for dashboard entries (used for 'how many events to display on dashboard').
1113 *
1114 * @return array
1115 * Dashboard entries options - in practice [-1 => 'Show All', 10 => 10, 20 => 20, ... 100 => 100].
1116 */
1117 public static function getDashboardEntriesCount() {
1118 $optionValues = [];
1119 $optionValues[-1] = ts('show all');
1120 for ($i = 10; $i <= 100; $i += 10) {
1121 $optionValues[$i] = $i;
1122 }
1123 return $optionValues;
1124 }
1125
4235341b
CW
1126 /**
1127 * Dropdown options for quicksearch in the menu
1128 *
1129 * @return array
1130 */
1131 public static function quicksearchOptions() {
be2fb01f 1132 $includeEmail = civicrm_api3('setting', 'getvalue', ['name' => 'includeEmailInName', 'group' => 'Search Preferences']);
4235341b
CW
1133 $options = [
1134 'sort_name' => $includeEmail ? ts('Name/Email') : ts('Name'),
1135 'contact_id' => ts('Contact ID'),
1136 'external_identifier' => ts('External ID'),
1137 'first_name' => ts('First Name'),
1138 'last_name' => ts('Last Name'),
1139 'email' => ts('Email'),
1140 'phone_numeric' => ts('Phone'),
1141 'street_address' => ts('Street Address'),
1142 'city' => ts('City'),
1143 'postal_code' => ts('Postal Code'),
1144 'job_title' => ts('Job Title'),
1145 ];
1146 $custom = civicrm_api3('CustomField', 'get', [
1f8ac3d2
CW
1147 'return' => ['name', 'label', 'custom_group_id.title'],
1148 'custom_group_id.extends' => ['IN' => ['Contact', 'Individual', 'Organization', 'Household']],
1149 'data_type' => ['NOT IN' => ['ContactReference', 'Date', 'File']],
4235341b
CW
1150 'custom_group_id.is_active' => 1,
1151 'is_active' => 1,
1152 'is_searchable' => 1,
d44e024b 1153 'options' => ['sort' => ['custom_group_id.weight', 'weight'], 'limit' => 0],
4235341b
CW
1154 ]);
1155 foreach ($custom['values'] as $field) {
1156 $options['custom_' . $field['name']] = $field['custom_group_id.title'] . ': ' . $field['label'];
1157 }
1158 return $options;
1159 }
1160
6a488035 1161}