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