| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | Copyright CiviCRM LLC. All rights reserved. | |
| 5 | | | |
| 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 | |
| 9 | +--------------------------------------------------------------------+ |
| 10 | */ |
| 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 |
| 18 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
| 19 | * $Id$ |
| 20 | * |
| 21 | */ |
| 22 | class CRM_Core_SelectValues { |
| 23 | |
| 24 | /** |
| 25 | * Yes/No options |
| 26 | * |
| 27 | * @return array |
| 28 | */ |
| 29 | public static function boolean() { |
| 30 | return [ |
| 31 | 1 => ts('Yes'), |
| 32 | 0 => ts('No'), |
| 33 | ]; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Preferred mail format. |
| 38 | * |
| 39 | * @return array |
| 40 | */ |
| 41 | public static function pmf() { |
| 42 | return [ |
| 43 | 'Both' => ts('Both'), |
| 44 | 'HTML' => ts('HTML'), |
| 45 | 'Text' => ts('Text'), |
| 46 | ]; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Privacy options. |
| 51 | * |
| 52 | * @return array |
| 53 | */ |
| 54 | public static function privacy() { |
| 55 | return [ |
| 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)'), |
| 62 | ]; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Various pre defined contact super types. |
| 67 | * |
| 68 | * @return array |
| 69 | */ |
| 70 | public static function contactType() { |
| 71 | static $contactType = NULL; |
| 72 | if (!$contactType) { |
| 73 | $contactType = CRM_Contact_BAO_ContactType::basicTypePairs(); |
| 74 | } |
| 75 | return $contactType; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Various pre defined unit list. |
| 80 | * |
| 81 | * @param string $unitType |
| 82 | * @return array |
| 83 | */ |
| 84 | public static function unitList($unitType = NULL) { |
| 85 | $unitList = [ |
| 86 | 'day' => ts('day'), |
| 87 | 'month' => ts('month'), |
| 88 | 'year' => ts('year'), |
| 89 | ]; |
| 90 | if ($unitType == 'duration') { |
| 91 | $unitList['lifetime'] = ts('lifetime'); |
| 92 | } |
| 93 | return $unitList; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Membership type unit. |
| 98 | * |
| 99 | * @return array |
| 100 | */ |
| 101 | public static function membershipTypeUnitList() { |
| 102 | return self::unitList('duration'); |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Various pre defined period types. |
| 107 | * |
| 108 | * @return array |
| 109 | */ |
| 110 | public static function periodType() { |
| 111 | return [ |
| 112 | 'rolling' => ts('Rolling'), |
| 113 | 'fixed' => ts('Fixed'), |
| 114 | ]; |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Various pre defined email selection methods. |
| 119 | * |
| 120 | * @return array |
| 121 | */ |
| 122 | public static function emailSelectMethods() { |
| 123 | return [ |
| 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"), |
| 127 | 'location-exclude' => ts("Exclude email addresses assigned to the specified location"), |
| 128 | ]; |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Various pre defined member visibility options. |
| 133 | * |
| 134 | * @return array |
| 135 | */ |
| 136 | public static function memberVisibility() { |
| 137 | return [ |
| 138 | 'Public' => ts('Public'), |
| 139 | 'Admin' => ts('Admin'), |
| 140 | ]; |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Member auto-renew options |
| 145 | * |
| 146 | * @return array |
| 147 | */ |
| 148 | public static function memberAutoRenew() { |
| 149 | return [ |
| 150 | ts('No auto-renew option'), |
| 151 | ts('Give option, but not required'), |
| 152 | ts('Auto-renew required'), |
| 153 | ]; |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * Various pre defined event dates. |
| 158 | * |
| 159 | * @return array |
| 160 | */ |
| 161 | public static function eventDate() { |
| 162 | return [ |
| 163 | 'start_date' => ts('start date'), |
| 164 | 'end_date' => ts('end date'), |
| 165 | 'join_date' => ts('member since'), |
| 166 | ]; |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * Custom form field types. |
| 171 | * |
| 172 | * @return array |
| 173 | */ |
| 174 | public static function customHtmlType() { |
| 175 | return [ |
| 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'), |
| 190 | 'Link' => ts('Link'), |
| 191 | 'ContactReference' => ts('Autocomplete-Select'), |
| 192 | ]; |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * Various pre defined extensions for dynamic properties and groups. |
| 197 | * |
| 198 | * @return array |
| 199 | * |
| 200 | */ |
| 201 | public static function customGroupExtends() { |
| 202 | $customGroupExtends = [ |
| 203 | 'Activity' => ts('Activities'), |
| 204 | 'Relationship' => ts('Relationships'), |
| 205 | 'Contribution' => ts('Contributions'), |
| 206 | 'ContributionRecur' => ts('Recurring Contributions'), |
| 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'), |
| 218 | ]; |
| 219 | $contactTypes = self::contactType(); |
| 220 | $contactTypes = !empty($contactTypes) ? ['Contact' => 'Contacts'] + $contactTypes : []; |
| 221 | $extendObjs = CRM_Core_OptionGroup::values('cg_extend_objects'); |
| 222 | $customGroupExtends = array_merge($contactTypes, $customGroupExtends, $extendObjs); |
| 223 | return $customGroupExtends; |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * Styles for displaying the custom data group. |
| 228 | * |
| 229 | * @return array |
| 230 | */ |
| 231 | public static function customGroupStyle() { |
| 232 | return [ |
| 233 | 'Tab' => ts('Tab'), |
| 234 | 'Inline' => ts('Inline'), |
| 235 | 'Tab with table' => ts('Tab with table'), |
| 236 | ]; |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * For displaying the uf group types. |
| 241 | * |
| 242 | * @return array |
| 243 | */ |
| 244 | public static function ufGroupTypes() { |
| 245 | $ufGroupType = [ |
| 246 | 'Profile' => ts('Standalone Form or Directory'), |
| 247 | 'Search Profile' => ts('Search Views'), |
| 248 | ]; |
| 249 | |
| 250 | if (CRM_Core_Config::singleton()->userSystem->supports_form_extensions) { |
| 251 | $ufGroupType += [ |
| 252 | 'User Registration' => ts('Drupal User Registration'), |
| 253 | 'User Account' => ts('View/Edit Drupal User Account'), |
| 254 | ]; |
| 255 | } |
| 256 | return $ufGroupType; |
| 257 | } |
| 258 | |
| 259 | /** |
| 260 | * The status of a contact within a group. |
| 261 | * |
| 262 | * @return array |
| 263 | */ |
| 264 | public static function groupContactStatus() { |
| 265 | return [ |
| 266 | 'Added' => ts('Added'), |
| 267 | 'Removed' => ts('Removed'), |
| 268 | 'Pending' => ts('Pending'), |
| 269 | ]; |
| 270 | } |
| 271 | |
| 272 | /** |
| 273 | * List of Group Types. |
| 274 | * |
| 275 | * @return array |
| 276 | */ |
| 277 | public static function groupType() { |
| 278 | return [ |
| 279 | 'query' => ts('Dynamic'), |
| 280 | 'static' => ts('Static'), |
| 281 | ]; |
| 282 | } |
| 283 | |
| 284 | /** |
| 285 | * Compose the parameters for a date select object. |
| 286 | * |
| 287 | * @param string|null $type |
| 288 | * the type of date |
| 289 | * @param string|null $format |
| 290 | * date format (QF format) |
| 291 | * @param null $minOffset |
| 292 | * @param null $maxOffset |
| 293 | * @param string $context |
| 294 | * |
| 295 | * @return array |
| 296 | * the date array |
| 297 | * @throws \Exception |
| 298 | */ |
| 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. |
| 301 | $date = [ |
| 302 | 'addEmptyOption' => TRUE, |
| 303 | 'emptyOptionText' => ts('- select -'), |
| 304 | 'emptyOptionValue' => '', |
| 305 | ]; |
| 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 | } |
| 317 | if (!$maxOffset) { |
| 318 | $maxOffset = $dao->end; |
| 319 | } |
| 320 | if (!$minOffset) { |
| 321 | $minOffset = $dao->start; |
| 322 | } |
| 323 | |
| 324 | $date['format'] = $dao->date_format; |
| 325 | $date['time'] = (bool) $dao->time_format; |
| 326 | } |
| 327 | |
| 328 | if (empty($date['format'])) { |
| 329 | if ($context == 'Input') { |
| 330 | $date['format'] = Civi::settings()->get('dateInputFormat'); |
| 331 | } |
| 332 | else { |
| 333 | $date['format'] = 'M d'; |
| 334 | } |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | $date['smarty_view_format'] = CRM_Utils_Date::getDateFieldViewFormat($date['format']); |
| 339 | if (!isset($date['time'])) { |
| 340 | $date['time'] = FALSE; |
| 341 | } |
| 342 | |
| 343 | $year = date('Y'); |
| 344 | $date['minYear'] = $year - (int) $minOffset; |
| 345 | $date['maxYear'] = $year + (int) $maxOffset; |
| 346 | return $date; |
| 347 | } |
| 348 | |
| 349 | /** |
| 350 | * Values for UF form visibility options. |
| 351 | * |
| 352 | * @return array |
| 353 | */ |
| 354 | public static function ufVisibility() { |
| 355 | return [ |
| 356 | 'User and User Admin Only' => ts('User and User Admin Only'), |
| 357 | 'Public Pages' => ts('Expose Publicly'), |
| 358 | 'Public Pages and Listings' => ts('Expose Publicly and for Listings'), |
| 359 | ]; |
| 360 | } |
| 361 | |
| 362 | /** |
| 363 | * Values for group form visibility options. |
| 364 | * |
| 365 | * @return array |
| 366 | */ |
| 367 | public static function groupVisibility() { |
| 368 | return [ |
| 369 | 'User and User Admin Only' => ts('User and User Admin Only'), |
| 370 | 'Public Pages' => ts('Public Pages'), |
| 371 | ]; |
| 372 | } |
| 373 | |
| 374 | /** |
| 375 | * Different type of Mailing Components. |
| 376 | * |
| 377 | * @return array |
| 378 | */ |
| 379 | public static function mailingComponents() { |
| 380 | return [ |
| 381 | 'Header' => ts('Header'), |
| 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'), |
| 389 | ]; |
| 390 | } |
| 391 | |
| 392 | /** |
| 393 | * Get hours. |
| 394 | * |
| 395 | * @return array |
| 396 | */ |
| 397 | public function getHours() { |
| 398 | $hours = []; |
| 399 | for ($i = 0; $i <= 6; $i++) { |
| 400 | $hours[$i] = $i; |
| 401 | } |
| 402 | return $hours; |
| 403 | } |
| 404 | |
| 405 | /** |
| 406 | * Get minutes. |
| 407 | * |
| 408 | * @return array |
| 409 | */ |
| 410 | public function getMinutes() { |
| 411 | $minutes = []; |
| 412 | for ($i = 0; $i < 60; $i = $i + 15) { |
| 413 | $minutes[$i] = $i; |
| 414 | } |
| 415 | return $minutes; |
| 416 | } |
| 417 | |
| 418 | /** |
| 419 | * Get the Map Provider. |
| 420 | * |
| 421 | * @return array |
| 422 | * array of map providers |
| 423 | */ |
| 424 | public static function mapProvider() { |
| 425 | static $map = NULL; |
| 426 | if (!$map) { |
| 427 | $map = ['' => '- select -'] + CRM_Utils_System::getPluginList('templates/CRM/Contact/Form/Task/Map', ".tpl"); |
| 428 | } |
| 429 | return $map; |
| 430 | } |
| 431 | |
| 432 | /** |
| 433 | * Get the Geocoding Providers from available plugins. |
| 434 | * |
| 435 | * @return array |
| 436 | * array of geocoder providers |
| 437 | */ |
| 438 | public static function geoProvider() { |
| 439 | static $geo = NULL; |
| 440 | if (!$geo) { |
| 441 | $geo = ['' => '- select -'] + CRM_Utils_System::getPluginList('CRM/Utils/Geocode'); |
| 442 | } |
| 443 | return $geo; |
| 444 | } |
| 445 | |
| 446 | /** |
| 447 | * Get the Address Standardization Providers from available plugins. |
| 448 | * |
| 449 | * @return array |
| 450 | * array of address standardization providers |
| 451 | */ |
| 452 | public static function addressProvider() { |
| 453 | static $addr = NULL; |
| 454 | if (!$addr) { |
| 455 | $addr = array_merge(['' => '- select -'], CRM_Utils_System::getPluginList('CRM/Utils/Address', '.php', ['BatchUpdate'])); |
| 456 | } |
| 457 | return $addr; |
| 458 | } |
| 459 | |
| 460 | /** |
| 461 | * Different type of Mailing Tokens. |
| 462 | * |
| 463 | * @return array |
| 464 | */ |
| 465 | public static function mailingTokens() { |
| 466 | return [ |
| 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'), |
| 483 | ]; |
| 484 | } |
| 485 | |
| 486 | /** |
| 487 | * Different type of Activity Tokens. |
| 488 | * |
| 489 | * @return array |
| 490 | */ |
| 491 | public static function activityTokens() { |
| 492 | return [ |
| 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'), |
| 497 | ]; |
| 498 | } |
| 499 | |
| 500 | /** |
| 501 | * Different type of Membership Tokens. |
| 502 | * |
| 503 | * @return array |
| 504 | */ |
| 505 | public static function membershipTokens() { |
| 506 | return [ |
| 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'), |
| 514 | ]; |
| 515 | } |
| 516 | |
| 517 | /** |
| 518 | * Different type of Event Tokens. |
| 519 | * |
| 520 | * @return array |
| 521 | */ |
| 522 | public static function eventTokens() { |
| 523 | return [ |
| 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'), |
| 537 | '{event.balance}' => ts('Event Balance'), |
| 538 | ]; |
| 539 | } |
| 540 | |
| 541 | /** |
| 542 | * Different type of Event Tokens. |
| 543 | * |
| 544 | * @return array |
| 545 | */ |
| 546 | public static function contributionTokens() { |
| 547 | return array_merge([ |
| 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'), |
| 552 | '{contribution.non_deductible_amount}' => ts('Non-deductible Amount'), |
| 553 | '{contribution.receive_date}' => ts('Contribution Date Received'), |
| 554 | '{contribution.payment_instrument}' => ts('Payment Method'), |
| 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'), |
| 571 | ], CRM_Utils_Token::getCustomFieldTokens('contribution', TRUE)); |
| 572 | } |
| 573 | |
| 574 | /** |
| 575 | * Different type of Contact Tokens. |
| 576 | * |
| 577 | * @return array |
| 578 | */ |
| 579 | public static function contactTokens() { |
| 580 | static $tokens = NULL; |
| 581 | if (!$tokens) { |
| 582 | $additionalFields = [ |
| 583 | 'checksum' => ['title' => ts('Checksum')], |
| 584 | 'contact_id' => ['title' => ts('Internal Contact ID')], |
| 585 | ]; |
| 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. |
| 592 | $skipTokens = [ |
| 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', |
| 603 | ]; |
| 604 | |
| 605 | $customFields = CRM_Core_BAO_CustomField::getFields(['Individual', 'Address']); |
| 606 | $legacyTokenNames = array_flip(CRM_Utils_Token::legacyContactTokens()); |
| 607 | |
| 608 | foreach ($values as $val) { |
| 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 |
| 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 | } |
| 619 | } |
| 620 | else { |
| 621 | // Support legacy token names |
| 622 | $tokenName = CRM_Utils_Array::value($val, $legacyTokenNames, $val); |
| 623 | $tokens["{contact.$tokenName}"] = $exportFields[$val]['title']; |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | // Get all the hook tokens too |
| 628 | $hookTokens = []; |
| 629 | CRM_Utils_Hook::tokens($hookTokens); |
| 630 | foreach ($hookTokens as $tokenValues) { |
| 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 | |
| 649 | /** |
| 650 | * Different type of Participant Tokens. |
| 651 | * |
| 652 | * @return array |
| 653 | */ |
| 654 | public static function participantTokens() { |
| 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. |
| 663 | $skipTokens = [ |
| 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', |
| 672 | ]; |
| 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)) { |
| 682 | $tokens["{participant.$val}"] = !empty($customFields[$customFieldId]) ? $customFields[$customFieldId]['label'] . " :: " . $customFields[$customFieldId]['groupTitle'] : ''; |
| 683 | } |
| 684 | else { |
| 685 | $tokens["{participant.$val}"] = $exportFields[$val]['title']; |
| 686 | } |
| 687 | } |
| 688 | } |
| 689 | return $tokens; |
| 690 | } |
| 691 | |
| 692 | /** |
| 693 | * @param int $caseTypeId |
| 694 | * @return array |
| 695 | */ |
| 696 | public static function caseTokens($caseTypeId = NULL) { |
| 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 | |
| 703 | $customFields = CRM_Core_BAO_CustomField::getFields('Case', FALSE, FALSE, $caseTypeId); |
| 704 | foreach ($customFields as $id => $field) { |
| 705 | $tokens["{case.custom_$id}"] = "{$field['label']} :: {$field['groupTitle']}"; |
| 706 | } |
| 707 | } |
| 708 | return $tokens; |
| 709 | } |
| 710 | |
| 711 | /** |
| 712 | * CiviCRM supported date input formats. |
| 713 | * |
| 714 | * @return array |
| 715 | */ |
| 716 | public static function getDatePluginInputFormats() { |
| 717 | return [ |
| 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)'), |
| 733 | ]; |
| 734 | } |
| 735 | |
| 736 | /** |
| 737 | * Time formats. |
| 738 | * |
| 739 | * @return array |
| 740 | */ |
| 741 | public static function getTimeFormats() { |
| 742 | return [ |
| 743 | '1' => ts('12 Hours'), |
| 744 | '2' => ts('24 Hours'), |
| 745 | ]; |
| 746 | } |
| 747 | |
| 748 | /** |
| 749 | * Get numeric options. |
| 750 | * |
| 751 | * @param int $start |
| 752 | * @param int $end |
| 753 | * |
| 754 | * @return array |
| 755 | */ |
| 756 | public static function getNumericOptions($start = 0, $end = 10) { |
| 757 | $numericOptions = []; |
| 758 | for ($i = $start; $i <= $end; $i++) { |
| 759 | $numericOptions[$i] = $i; |
| 760 | } |
| 761 | return $numericOptions; |
| 762 | } |
| 763 | |
| 764 | /** |
| 765 | * Barcode types. |
| 766 | * |
| 767 | * @return array |
| 768 | */ |
| 769 | public static function getBarcodeTypes() { |
| 770 | return [ |
| 771 | 'barcode' => ts('Linear (1D)'), |
| 772 | 'qrcode' => ts('QR code'), |
| 773 | ]; |
| 774 | } |
| 775 | |
| 776 | /** |
| 777 | * Dedupe rule types. |
| 778 | * |
| 779 | * @return array |
| 780 | */ |
| 781 | public static function getDedupeRuleTypes() { |
| 782 | return [ |
| 783 | 'Unsupervised' => ts('Unsupervised'), |
| 784 | 'Supervised' => ts('Supervised'), |
| 785 | 'General' => ts('General'), |
| 786 | ]; |
| 787 | } |
| 788 | |
| 789 | /** |
| 790 | * Campaign group types. |
| 791 | * |
| 792 | * @return array |
| 793 | */ |
| 794 | public static function getCampaignGroupTypes() { |
| 795 | return [ |
| 796 | 'Include' => ts('Include'), |
| 797 | 'Exclude' => ts('Exclude'), |
| 798 | ]; |
| 799 | } |
| 800 | |
| 801 | /** |
| 802 | * Subscription history method. |
| 803 | * |
| 804 | * @return array |
| 805 | */ |
| 806 | public static function getSubscriptionHistoryMethods() { |
| 807 | return [ |
| 808 | 'Admin' => ts('Admin'), |
| 809 | 'Email' => ts('Email'), |
| 810 | 'Web' => ts('Web'), |
| 811 | 'API' => ts('API'), |
| 812 | ]; |
| 813 | } |
| 814 | |
| 815 | /** |
| 816 | * Premium units. |
| 817 | * |
| 818 | * @return array |
| 819 | */ |
| 820 | public static function getPremiumUnits() { |
| 821 | return [ |
| 822 | 'day' => ts('Day'), |
| 823 | 'week' => ts('Week'), |
| 824 | 'month' => ts('Month'), |
| 825 | 'year' => ts('Year'), |
| 826 | ]; |
| 827 | } |
| 828 | |
| 829 | /** |
| 830 | * Extension types. |
| 831 | * |
| 832 | * @return array |
| 833 | */ |
| 834 | public static function getExtensionTypes() { |
| 835 | return [ |
| 836 | 'payment' => ts('Payment'), |
| 837 | 'search' => ts('Search'), |
| 838 | 'report' => ts('Report'), |
| 839 | 'module' => ts('Module'), |
| 840 | 'sms' => ts('SMS'), |
| 841 | ]; |
| 842 | } |
| 843 | |
| 844 | /** |
| 845 | * Job frequency. |
| 846 | * |
| 847 | * @return array |
| 848 | */ |
| 849 | public static function getJobFrequency() { |
| 850 | return [ |
| 851 | // CRM-17669 |
| 852 | 'Yearly' => ts('Yearly'), |
| 853 | 'Quarter' => ts('Quarterly'), |
| 854 | 'Monthly' => ts('Monthly'), |
| 855 | 'Weekly' => ts('Weekly'), |
| 856 | |
| 857 | 'Daily' => ts('Daily'), |
| 858 | 'Hourly' => ts('Hourly'), |
| 859 | 'Always' => ts('Every time cron job is run'), |
| 860 | ]; |
| 861 | } |
| 862 | |
| 863 | /** |
| 864 | * Search builder operators. |
| 865 | * |
| 866 | * @return array |
| 867 | */ |
| 868 | public static function getSearchBuilderOperators($fieldType = NULL) { |
| 869 | return [ |
| 870 | '=' => '=', |
| 871 | '!=' => '≠', |
| 872 | '>' => '>', |
| 873 | '<' => '<', |
| 874 | '>=' => '≥', |
| 875 | '<=' => '≤', |
| 876 | 'IN' => ts('In'), |
| 877 | 'NOT IN' => ts('Not In'), |
| 878 | 'LIKE' => ts('Like'), |
| 879 | 'NOT LIKE' => ts('Not Like'), |
| 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'), |
| 885 | ]; |
| 886 | } |
| 887 | |
| 888 | /** |
| 889 | * Profile group types. |
| 890 | * |
| 891 | * @return array |
| 892 | */ |
| 893 | public static function getProfileGroupType() { |
| 894 | $profileGroupType = [ |
| 895 | 'Activity' => ts('Activities'), |
| 896 | 'Contribution' => ts('Contributions'), |
| 897 | 'Membership' => ts('Memberships'), |
| 898 | 'Participant' => ts('Participants'), |
| 899 | ]; |
| 900 | $contactTypes = self::contactType(); |
| 901 | $contactTypes = !empty($contactTypes) ? ['Contact' => 'Contacts'] + $contactTypes : []; |
| 902 | $profileGroupType = array_merge($contactTypes, $profileGroupType); |
| 903 | |
| 904 | return $profileGroupType; |
| 905 | } |
| 906 | |
| 907 | /** |
| 908 | * Word replacement match type. |
| 909 | * |
| 910 | * @return array |
| 911 | */ |
| 912 | public static function getWordReplacementMatchType() { |
| 913 | return [ |
| 914 | 'exactMatch' => ts('Exact Match'), |
| 915 | 'wildcardMatch' => ts('Wildcard Match'), |
| 916 | ]; |
| 917 | } |
| 918 | |
| 919 | /** |
| 920 | * Mailing group types. |
| 921 | * |
| 922 | * @return array |
| 923 | */ |
| 924 | public static function getMailingGroupTypes() { |
| 925 | return [ |
| 926 | 'Include' => ts('Include'), |
| 927 | 'Exclude' => ts('Exclude'), |
| 928 | 'Base' => ts('Base'), |
| 929 | ]; |
| 930 | } |
| 931 | |
| 932 | /** |
| 933 | * Mailing Job Status. |
| 934 | * |
| 935 | * @return array |
| 936 | */ |
| 937 | public static function getMailingJobStatus() { |
| 938 | return [ |
| 939 | 'Scheduled' => ts('Scheduled'), |
| 940 | 'Running' => ts('Running'), |
| 941 | 'Complete' => ts('Complete'), |
| 942 | 'Paused' => ts('Paused'), |
| 943 | 'Canceled' => ts('Canceled'), |
| 944 | ]; |
| 945 | } |
| 946 | |
| 947 | /** |
| 948 | * @return array |
| 949 | */ |
| 950 | public static function billingMode() { |
| 951 | return [ |
| 952 | CRM_Core_Payment::BILLING_MODE_FORM => 'form', |
| 953 | CRM_Core_Payment::BILLING_MODE_BUTTON => 'button', |
| 954 | CRM_Core_Payment::BILLING_MODE_NOTIFY => 'notify', |
| 955 | ]; |
| 956 | } |
| 957 | |
| 958 | /** |
| 959 | * @return array |
| 960 | */ |
| 961 | public static function contributeMode() { |
| 962 | return [ |
| 963 | CRM_Core_Payment::BILLING_MODE_FORM => 'direct', |
| 964 | CRM_Core_Payment::BILLING_MODE_BUTTON => 'directIPN', |
| 965 | CRM_Core_Payment::BILLING_MODE_NOTIFY => 'notify', |
| 966 | ]; |
| 967 | } |
| 968 | |
| 969 | /** |
| 970 | * Frequency unit for schedule reminders. |
| 971 | * |
| 972 | * @param int $count |
| 973 | * For pluralization |
| 974 | * @return array |
| 975 | */ |
| 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. |
| 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 | ]; |
| 987 | } |
| 988 | |
| 989 | /** |
| 990 | * Relative Date Terms. |
| 991 | * |
| 992 | * @return array |
| 993 | */ |
| 994 | public static function getRelativeDateTerms() { |
| 995 | return [ |
| 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'), |
| 1011 | ]; |
| 1012 | } |
| 1013 | |
| 1014 | /** |
| 1015 | * Relative Date Units. |
| 1016 | * |
| 1017 | * @return array |
| 1018 | */ |
| 1019 | public static function getRelativeDateUnits() { |
| 1020 | return [ |
| 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'), |
| 1027 | ]; |
| 1028 | } |
| 1029 | |
| 1030 | /** |
| 1031 | * Exportable document formats. |
| 1032 | * |
| 1033 | * @return array |
| 1034 | */ |
| 1035 | public static function documentFormat() { |
| 1036 | return [ |
| 1037 | 'pdf' => ts('Portable Document Format (.pdf)'), |
| 1038 | 'docx' => ts('MS Word (.docx)'), |
| 1039 | 'odt' => ts('Open Office (.odt)'), |
| 1040 | 'html' => ts('Webpage (.html)'), |
| 1041 | ]; |
| 1042 | } |
| 1043 | |
| 1044 | /** |
| 1045 | * Application type of document. |
| 1046 | * |
| 1047 | * @return array |
| 1048 | */ |
| 1049 | public static function documentApplicationType() { |
| 1050 | return [ |
| 1051 | 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', |
| 1052 | 'odt' => 'application/vnd.oasis.opendocument.text', |
| 1053 | ]; |
| 1054 | } |
| 1055 | |
| 1056 | /** |
| 1057 | * Activity Text options. |
| 1058 | * |
| 1059 | * @return array |
| 1060 | */ |
| 1061 | public static function activityTextOptions() { |
| 1062 | return [ |
| 1063 | 2 => ts('Details Only'), |
| 1064 | 3 => ts('Subject Only'), |
| 1065 | 6 => ts('Both'), |
| 1066 | ]; |
| 1067 | } |
| 1068 | |
| 1069 | /** |
| 1070 | * Relationship permissions |
| 1071 | * |
| 1072 | * @return array |
| 1073 | */ |
| 1074 | public static function getPermissionedRelationshipOptions() { |
| 1075 | return [ |
| 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'), |
| 1079 | ]; |
| 1080 | } |
| 1081 | |
| 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 | |
| 1097 | /** |
| 1098 | * Dropdown options for quicksearch in the menu |
| 1099 | * |
| 1100 | * @return array |
| 1101 | */ |
| 1102 | public static function quicksearchOptions() { |
| 1103 | $includeEmail = civicrm_api3('setting', 'getvalue', ['name' => 'includeEmailInName', 'group' => 'Search Preferences']); |
| 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', [ |
| 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']], |
| 1121 | 'custom_group_id.is_active' => 1, |
| 1122 | 'is_active' => 1, |
| 1123 | 'is_searchable' => 1, |
| 1124 | 'options' => ['sort' => ['custom_group_id.weight', 'weight'], 'limit' => 0], |
| 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 | |
| 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 | |
| 1149 | } |