SelectValues.php 30.7 KB
Newer Older
totten's avatar
totten committed
1 2 3
<?php
/*
 +--------------------------------------------------------------------+
totten's avatar
totten committed
4
 | CiviCRM version 5                                                  |
totten's avatar
totten committed
5
 +--------------------------------------------------------------------+
yashodha's avatar
yashodha committed
6
 | Copyright CiviCRM LLC (c) 2004-2018                                |
totten's avatar
totten committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 +--------------------------------------------------------------------+
 | This file is a part of CiviCRM.                                    |
 |                                                                    |
 | CiviCRM is free software; you can copy, modify, and distribute it  |
 | under the terms of the GNU Affero General Public License           |
 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
 |                                                                    |
 | CiviCRM is distributed in the hope that it will be useful, but     |
 | WITHOUT ANY WARRANTY; without even the implied warranty of         |
 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
 | See the GNU Affero General Public License for more details.        |
 |                                                                    |
 | You should have received a copy of the GNU Affero General Public   |
 | License and the CiviCRM Licensing Exception along                  |
 | with this program; if not, contact CiviCRM LLC                     |
 | at info[AT]civicrm[DOT]org. If you have questions about the        |
 | GNU Affero General Public License or the licensing of CiviCRM,     |
 | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
 +--------------------------------------------------------------------+
26
 */
totten's avatar
totten committed
27 28 29 30 31 32 33

/**
 * One place to store frequently used values in Select Elements. Note that
 * some of the below elements will be dynamic, so we'll probably have a
 * smart caching scheme on a per domain basis
 *
 * @package CRM
yashodha's avatar
yashodha committed
34
 * @copyright CiviCRM LLC (c) 2004-2018
totten's avatar
totten committed
35 36 37 38 39
 * $Id$
 *
 */
class CRM_Core_SelectValues {

40 41 42 43 44 45 46 47 48 49 50 51
  /**
   * Yes/No options
   *
   * @return array
   */
  public static function boolean() {
    return array(
      1 => ts('Yes'),
      0 => ts('No'),
    );
  }

totten's avatar
totten committed
52
  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
53
   * Preferred mail format.
kurund's avatar
kurund committed
54
   *
colemanw's avatar
colemanw committed
55
   * @return array
totten's avatar
totten committed
56
   */
57
  public static function pmf() {
colemanw's avatar
colemanw committed
58 59 60 61 62
    return array(
      'Both' => ts('Both'),
      'HTML' => ts('HTML'),
      'Text' => ts('Text'),
    );
totten's avatar
totten committed
63 64 65
  }

  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
66
   * Privacy options.
colemanw's avatar
colemanw committed
67 68
   *
   * @return array
totten's avatar
totten committed
69
   */
70
  public static function privacy() {
colemanw's avatar
colemanw committed
71 72 73 74 75 76 77 78
    return array(
      'do_not_phone' => ts('Do not phone'),
      'do_not_email' => ts('Do not email'),
      'do_not_mail' => ts('Do not mail'),
      'do_not_sms' => ts('Do not sms'),
      'do_not_trade' => ts('Do not trade'),
      'is_opt_out' => ts('No bulk emails (User Opt Out)'),
    );
totten's avatar
totten committed
79 80 81
  }

  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
82
   * Various pre defined contact super types.
colemanw's avatar
colemanw committed
83 84
   *
   * @return array
totten's avatar
totten committed
85
   */
86
  public static function contactType() {
totten's avatar
totten committed
87 88
    static $contactType = NULL;
    if (!$contactType) {
Deepak Srivastava's avatar
Deepak Srivastava committed
89
      $contactType = CRM_Contact_BAO_ContactType::basicTypePairs();
totten's avatar
totten committed
90 91 92 93 94
    }
    return $contactType;
  }

  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
95
   * Various pre defined unit list.
kurund's avatar
kurund committed
96
   *
colemanw's avatar
colemanw committed
97 98
   * @param string $unitType
   * @return array
totten's avatar
totten committed
99
   */
100
  public static function unitList($unitType = NULL) {
101 102 103 104 105 106
    $unitList = array(
      'day' => ts('day'),
      'month' => ts('month'),
      'year' => ts('year'),
    );
    if ($unitType == 'duration') {
colemanw's avatar
colemanw committed
107
      $unitList['lifetime'] = ts('lifetime');
totten's avatar
totten committed
108 109 110 111
    }
    return $unitList;
  }

112
  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
113
   * Membership type unit.
colemanw's avatar
colemanw committed
114 115
   *
   * @return array
116
   */
totten's avatar
totten committed
117
  public static function membershipTypeUnitList() {
colemanw's avatar
colemanw committed
118
    return self::unitList('duration');
119 120
  }

totten's avatar
totten committed
121
  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
122
   * Various pre defined period types.
colemanw's avatar
colemanw committed
123 124
   *
   * @return array
totten's avatar
totten committed
125
   */
126
  public static function periodType() {
127 128 129 130
    return array(
      'rolling' => ts('Rolling'),
      'fixed' => ts('Fixed'),
    );
totten's avatar
totten committed
131 132
  }

133
  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
134
   * Various pre defined email selection methods.
colemanw's avatar
colemanw committed
135 136
   *
   * @return array
137
   */
138
  public static function emailSelectMethods() {
139 140 141 142
    return array(
      'automatic' => ts("Automatic"),
      'location-only' => ts("Only send to email addresses assigned to the specified location"),
      'location-prefer' => ts("Prefer email addresses assigned to the specified location"),
143
      'location-exclude' => ts("Exclude email addresses assigned to the specified location"),
144 145 146
    );
  }

totten's avatar
totten committed
147
  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
148
   * Various pre defined member visibility options.
colemanw's avatar
colemanw committed
149 150
   *
   * @return array
totten's avatar
totten committed
151
   */
152
  public static function memberVisibility() {
colemanw's avatar
colemanw committed
153 154 155 156
    return array(
      'Public' => ts('Public'),
      'Admin' => ts('Admin'),
    );
totten's avatar
totten committed
157 158
  }

159 160
  /**
   * Member auto-renew options
colemanw's avatar
colemanw committed
161 162
   *
   * @return array
163 164 165 166 167
   */
  public static function memberAutoRenew() {
    return array(
      ts('No auto-renew option'),
      ts('Give option, but not required'),
168
      ts('Auto-renew required'),
169 170 171
    );
  }

totten's avatar
totten committed
172
  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
173
   * Various pre defined event dates.
colemanw's avatar
colemanw committed
174 175
   *
   * @return array
totten's avatar
totten committed
176
   */
177
  public static function eventDate() {
178 179 180 181 182
    return array(
      'start_date' => ts('start date'),
      'end_date' => ts('end date'),
      'join_date' => ts('member since'),
    );
totten's avatar
totten committed
183 184 185
  }

  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
186
   * Custom form field types.
colemanw's avatar
colemanw committed
187 188
   *
   * @return array
totten's avatar
totten committed
189
   */
190
  public static function customHtmlType() {
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
    return array(
      'Text' => ts('Single-line input field (text or numeric)'),
      'TextArea' => ts('Multi-line text box (textarea)'),
      'Select' => ts('Drop-down (select list)'),
      'Radio' => ts('Radio buttons'),
      'CheckBox' => ts('Checkbox(es)'),
      'Select Date' => ts('Select Date'),
      'File' => ts('File'),
      'Select State/Province' => ts('Select State/Province'),
      'Multi-Select State/Province' => ts('Multi-Select State/Province'),
      'Select Country' => ts('Select Country'),
      'Multi-Select Country' => ts('Multi-Select Country'),
      'RichTextEditor' => ts('Rich Text Editor'),
      'Autocomplete-Select' => ts('Autocomplete-Select'),
      'Multi-Select' => ts('Multi-Select'),
      'Link' => ts('Link'),
207
      'ContactReference' => ts('Autocomplete-Select'),
208
    );
totten's avatar
totten committed
209 210 211
  }

  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
212
   * Various pre defined extensions for dynamic properties and groups.
totten's avatar
totten committed
213
   *
colemanw's avatar
colemanw committed
214 215
   * @return array
   *
totten's avatar
totten committed
216
   */
217
  public static function customGroupExtends() {
218 219 220 221
    $customGroupExtends = array(
      'Activity' => ts('Activities'),
      'Relationship' => ts('Relationships'),
      'Contribution' => ts('Contributions'),
222
      'ContributionRecur' => ts('Recurring Contributions'),
223 224 225 226 227 228 229 230 231 232 233 234 235
      'Group' => ts('Groups'),
      'Membership' => ts('Memberships'),
      'Event' => ts('Events'),
      'Participant' => ts('Participants'),
      'ParticipantRole' => ts('Participants (Role)'),
      'ParticipantEventName' => ts('Participants (Event Name)'),
      'ParticipantEventType' => ts('Participants (Event Type)'),
      'Pledge' => ts('Pledges'),
      'Grant' => ts('Grants'),
      'Address' => ts('Addresses'),
      'Campaign' => ts('Campaigns'),
    );
    $contactTypes = self::contactType();
colemanw's avatar
colemanw committed
236 237
    $contactTypes = !empty($contactTypes) ? array('Contact' => 'Contacts') + $contactTypes : array();
    $extendObjs = CRM_Core_OptionGroup::values('cg_extend_objects');
238
    $customGroupExtends = array_merge($contactTypes, $customGroupExtends, $extendObjs);
totten's avatar
totten committed
239 240 241 242
    return $customGroupExtends;
  }

  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
243
   * Styles for displaying the custom data group.
totten's avatar
totten committed
244
   *
colemanw's avatar
colemanw committed
245
   * @return array
totten's avatar
totten committed
246
   */
247
  public static function customGroupStyle() {
248 249 250 251 252
    return array(
      'Tab' => ts('Tab'),
      'Inline' => ts('Inline'),
      'Tab with table' => ts('Tab with table'),
    );
totten's avatar
totten committed
253 254 255
  }

  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
256
   * For displaying the uf group types.
totten's avatar
totten committed
257
   *
colemanw's avatar
colemanw committed
258
   * @return array
totten's avatar
totten committed
259
   */
260
  public static function ufGroupTypes() {
261 262 263 264 265 266 267 268 269
    $ufGroupType = array(
      'Profile' => ts('Standalone Form or Directory'),
      'Search Profile' => ts('Search Views'),
    );

    if (CRM_Core_Config::singleton()->userSystem->supports_form_extensions) {
      $ufGroupType += array(
        'User Registration' => ts('Drupal User Registration'),
        'User Account' => ts('View/Edit Drupal User Account'),
totten's avatar
totten committed
270 271 272 273 274 275
      );
    }
    return $ufGroupType;
  }

  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
276
   * The status of a contact within a group.
totten's avatar
totten committed
277
   *
colemanw's avatar
colemanw committed
278
   * @return array
totten's avatar
totten committed
279
   */
280
  public static function groupContactStatus() {
281 282 283 284 285
    return array(
      'Added' => ts('Added'),
      'Removed' => ts('Removed'),
      'Pending' => ts('Pending'),
    );
totten's avatar
totten committed
286 287 288
  }

  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
289
   * List of Group Types.
colemanw's avatar
colemanw committed
290 291
   *
   * @return array
totten's avatar
totten committed
292
   */
293
  public static function groupType() {
294 295 296 297
    return array(
      'query' => ts('Dynamic'),
      'static' => ts('Static'),
    );
totten's avatar
totten committed
298 299 300
  }

  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
301
   * Compose the parameters for a date select object.
totten's avatar
totten committed
302
   *
colemanw's avatar
colemanw committed
303 304 305 306
   * @param string|NULL $type
   *   the type of date
   * @param string|NULL $format
   *   date format (QF format)
Eileen McNaughton's avatar
Eileen McNaughton committed
307 308
   * @param null $minOffset
   * @param null $maxOffset
totten's avatar
totten committed
309
   *
310 311
   * @return array
   *   the date array
totten's avatar
totten committed
312
   */
313 314
  public static function date($type = NULL, $format = NULL, $minOffset = NULL, $maxOffset = NULL, $context = 'display') {
    // These options are deprecated. Definitely not used in datepicker. Possibly not even in jcalendar+addDateTime.
totten's avatar
totten committed
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
    $date = array(
      'addEmptyOption' => TRUE,
      'emptyOptionText' => ts('- select -'),
      'emptyOptionValue' => '',
    );

    if ($format) {
      $date['format'] = $format;
    }
    else {
      if ($type) {
        $dao = new CRM_Core_DAO_PreferencesDate();
        $dao->name = $type;
        if (!$dao->find(TRUE)) {
          CRM_Core_Error::fatal();
        }
331 332 333 334 335 336
        if (!$maxOffset) {
          $maxOffset = $dao->end;
        }
        if (!$minOffset) {
          $minOffset = $dao->start;
        }
totten's avatar
totten committed
337 338

        $date['format'] = $dao->date_format;
339
        $date['time'] = (bool) $dao->time_format;
totten's avatar
totten committed
340 341
      }

342
      if (empty($date['format'])) {
343 344 345 346 347 348
        if ($context == 'Input') {
          $date['format'] = Civi::settings()->get('dateInputFormat');
        }
        else {
          $date['format'] = 'M d';
        }
totten's avatar
totten committed
349 350
      }
    }
351

352
    $date['smarty_view_format'] = CRM_Utils_Date::getDateFieldViewFormat($date['format']);
353 354 355
    if (!isset($date['time'])) {
      $date['time'] = FALSE;
    }
totten's avatar
totten committed
356

colemanw's avatar
colemanw committed
357
    $year = date('Y');
358 359
    $date['minYear'] = $year - (int) $minOffset;
    $date['maxYear'] = $year + (int) $maxOffset;
totten's avatar
totten committed
360 361 362 363
    return $date;
  }

  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
364
   * Values for UF form visibility options.
totten's avatar
totten committed
365
   *
colemanw's avatar
colemanw committed
366
   * @return array
totten's avatar
totten committed
367
   */
368
  public static function ufVisibility() {
369 370
    return array(
      'User and User Admin Only' => ts('User and User Admin Only'),
371 372
      'Public Pages' => ts('Expose Publicly'),
      'Public Pages and Listings' => ts('Expose Publicly and for Listings'),
373
    );
totten's avatar
totten committed
374 375
  }

376
  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
377
   * Values for group form visibility options.
378
   *
colemanw's avatar
colemanw committed
379
   * @return array
380
   */
381
  public static function groupVisibility() {
382
    return array(
colemanw's avatar
colemanw committed
383 384 385
      'User and User Admin Only' => ts('User and User Admin Only'),
      'Public Pages' => ts('Public Pages'),
    );
386 387
  }

totten's avatar
totten committed
388
  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
389
   * Different type of Mailing Components.
totten's avatar
totten committed
390
   *
colemanw's avatar
colemanw committed
391
   * @return array
totten's avatar
totten committed
392
   */
393
  public static function mailingComponents() {
totten's avatar
totten committed
394
    return array(
totten's avatar
totten committed
395
      'Header' => ts('Header'),
396 397 398 399 400 401 402 403
      'Footer' => ts('Footer'),
      'Reply' => ts('Reply Auto-responder'),
      'OptOut' => ts('Opt-out Message'),
      'Subscribe' => ts('Subscription Confirmation Request'),
      'Welcome' => ts('Welcome Message'),
      'Unsubscribe' => ts('Unsubscribe Message'),
      'Resubscribe' => ts('Resubscribe Message'),
    );
totten's avatar
totten committed
404 405 406
  }

  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
407
   * Get hours.
totten's avatar
totten committed
408
   *
colemanw's avatar
colemanw committed
409
   * @return array
totten's avatar
totten committed
410
   */
411
  public function getHours() {
412
    $hours = array();
totten's avatar
totten committed
413 414 415 416 417 418 419
    for ($i = 0; $i <= 6; $i++) {
      $hours[$i] = $i;
    }
    return $hours;
  }

  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
420
   * Get minutes.
totten's avatar
totten committed
421
   *
colemanw's avatar
colemanw committed
422
   * @return array
totten's avatar
totten committed
423
   */
424
  public function getMinutes() {
425
    $minutes = array();
totten's avatar
totten committed
426 427 428 429 430 431 432
    for ($i = 0; $i < 60; $i = $i + 15) {
      $minutes[$i] = $i;
    }
    return $minutes;
  }

  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
433
   * Get the Map Provider.
totten's avatar
totten committed
434
   *
435 436
   * @return array
   *   array of map providers
totten's avatar
totten committed
437
   */
438
  public static function mapProvider() {
totten's avatar
totten committed
439 440
    static $map = NULL;
    if (!$map) {
441
      $map = array('' => '- select -') + CRM_Utils_System::getPluginList('templates/CRM/Contact/Form/Task/Map', ".tpl");
totten's avatar
totten committed
442 443 444 445 446
    }
    return $map;
  }

  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
447
   * Get the Geocoding Providers from available plugins.
totten's avatar
totten committed
448
   *
449 450
   * @return array
   *   array of geocoder providers
totten's avatar
totten committed
451
   */
452
  public static function geoProvider() {
totten's avatar
totten committed
453 454
    static $geo = NULL;
    if (!$geo) {
455
      $geo = array('' => '- select -') + CRM_Utils_System::getPluginList('CRM/Utils/Geocode');
totten's avatar
totten committed
456 457 458 459 460
    }
    return $geo;
  }

  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
461
   * Get the Address Standardization Providers from available plugins.
totten's avatar
totten committed
462
   *
463 464
   * @return array
   *   array of address standardization providers
totten's avatar
totten committed
465
   */
466
  public static function addressProvider() {
totten's avatar
totten committed
467 468
    static $addr = NULL;
    if (!$addr) {
469
      $addr = array_merge(['' => '- select -'], CRM_Utils_System::getPluginList('CRM/Utils/Address', '.php', array('BatchUpdate')));
totten's avatar
totten committed
470 471 472 473 474
    }
    return $addr;
  }

  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
475
   * Different type of Mailing Tokens.
totten's avatar
totten committed
476
   *
colemanw's avatar
colemanw committed
477
   * @return array
totten's avatar
totten committed
478
   */
479
  public static function mailingTokens() {
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497
    return array(
      '{action.unsubscribe}' => ts('Unsubscribe via email'),
      '{action.unsubscribeUrl}' => ts('Unsubscribe via web page'),
      '{action.resubscribe}' => ts('Resubscribe via email'),
      '{action.resubscribeUrl}' => ts('Resubscribe via web page'),
      '{action.optOut}' => ts('Opt out via email'),
      '{action.optOutUrl}' => ts('Opt out via web page'),
      '{action.forward}' => ts('Forward this email (link)'),
      '{action.reply}' => ts('Reply to this email (link)'),
      '{action.subscribeUrl}' => ts('Subscribe via web page'),
      '{domain.name}' => ts('Domain name'),
      '{domain.address}' => ts('Domain (organization) address'),
      '{domain.phone}' => ts('Domain (organization) phone'),
      '{domain.email}' => ts('Domain (organization) email'),
      '{mailing.name}' => ts('Mailing name'),
      '{mailing.group}' => ts('Mailing group'),
      '{mailing.viewUrl}' => ts('Mailing permalink'),
    );
totten's avatar
totten committed
498 499 500
  }

  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
501
   * Different type of Activity Tokens.
totten's avatar
totten committed
502
   *
colemanw's avatar
colemanw committed
503
   * @return array
totten's avatar
totten committed
504
   */
505
  public static function activityTokens() {
506 507 508 509 510 511
    return array(
      '{activity.activity_id}' => ts('Activity ID'),
      '{activity.subject}' => ts('Activity Subject'),
      '{activity.details}' => ts('Activity Details'),
      '{activity.activity_date_time}' => ts('Activity Date Time'),
    );
totten's avatar
totten committed
512 513 514
  }

  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
515
   * Different type of Membership Tokens.
totten's avatar
totten committed
516
   *
colemanw's avatar
colemanw committed
517
   * @return array
totten's avatar
totten committed
518
   */
519
  public static function membershipTokens() {
520 521 522 523 524 525 526 527 528
    return array(
      '{membership.id}' => ts('Membership ID'),
      '{membership.status}' => ts('Membership Status'),
      '{membership.type}' => ts('Membership Type'),
      '{membership.start_date}' => ts('Membership Start Date'),
      '{membership.join_date}' => ts('Membership Join Date'),
      '{membership.end_date}' => ts('Membership End Date'),
      '{membership.fee}' => ts('Membership Fee'),
    );
totten's avatar
totten committed
529 530 531
  }

  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
532
   * Different type of Event Tokens.
totten's avatar
totten committed
533
   *
colemanw's avatar
colemanw committed
534
   * @return array
totten's avatar
totten committed
535
   */
536
  public static function eventTokens() {
537 538 539 540 541 542 543 544 545 546 547 548 549 550
    return array(
      '{event.event_id}' => ts('Event ID'),
      '{event.title}' => ts('Event Title'),
      '{event.start_date}' => ts('Event Start Date'),
      '{event.end_date}' => ts('Event End Date'),
      '{event.event_type}' => ts('Event Type'),
      '{event.summary}' => ts('Event Summary'),
      '{event.contact_email}' => ts('Event Contact Email'),
      '{event.contact_phone}' => ts('Event Contact Phone'),
      '{event.description}' => ts('Event Description'),
      '{event.location}' => ts('Event Location'),
      '{event.fee_amount}' => ts('Event Fees'),
      '{event.info_url}' => ts('Event Info URL'),
      '{event.registration_url}' => ts('Event Registration URL'),
551
      '{event.balance}' => ts('Event Balance'),
552
    );
totten's avatar
totten committed
553 554 555
  }

  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
556
   * Different type of Event Tokens.
totten's avatar
totten committed
557
   *
colemanw's avatar
colemanw committed
558
   * @return array
totten's avatar
totten committed
559
   */
560
  public static function contributionTokens() {
561
    return array_merge(array(
562 563 564 565
      '{contribution.contribution_id}' => ts('Contribution ID'),
      '{contribution.total_amount}' => ts('Total Amount'),
      '{contribution.fee_amount}' => ts('Fee Amount'),
      '{contribution.net_amount}' => ts('Net Amount'),
566
      '{contribution.non_deductible_amount}' => ts('Non-deductible Amount'),
567
      '{contribution.receive_date}' => ts('Contribution Date Received'),
568
      '{contribution.payment_instrument}' => ts('Payment Method'),
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584
      '{contribution.trxn_id}' => ts('Transaction ID'),
      '{contribution.invoice_id}' => ts('Invoice ID'),
      '{contribution.currency}' => ts('Currency'),
      '{contribution.cancel_date}' => ts('Contribution Cancel Date'),
      '{contribution.cancel_reason}' => ts('Contribution Cancel Reason'),
      '{contribution.receipt_date}' => ts('Receipt Date'),
      '{contribution.thankyou_date}' => ts('Thank You Date'),
      '{contribution.contribution_source}' => ts('Contribution Source'),
      '{contribution.amount_level}' => ts('Amount Level'),
      //'{contribution.contribution_recur_id}' => ts('Contribution Recurring ID'),
      //'{contribution.honor_contact_id}' => ts('Honor Contact ID'),
      '{contribution.contribution_status_id}' => ts('Contribution Status'),
      //'{contribution.honor_type_id}' => ts('Honor Type ID'),
      //'{contribution.address_id}' => ts('Address ID'),
      '{contribution.check_number}' => ts('Check Number'),
      '{contribution.campaign}' => ts('Contribution Campaign'),
585
    ), CRM_Utils_Token::getCustomFieldTokens('contribution', TRUE));
totten's avatar
totten committed
586 587 588
  }

  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
589
   * Different type of Contact Tokens.
totten's avatar
totten committed
590
   *
colemanw's avatar
colemanw committed
591
   * @return array
totten's avatar
totten committed
592
   */
593
  public static function contactTokens() {
totten's avatar
totten committed
594 595
    static $tokens = NULL;
    if (!$tokens) {
totten's avatar
totten committed
596
      $additionalFields = array(
totten's avatar
totten committed
597
        'checksum' => array('title' => ts('Checksum')),
totten's avatar
totten committed
598 599 600 601 602 603 604 605 606
        'contact_id' => array('title' => ts('Internal Contact ID')),
      );
      $exportFields = array_merge(CRM_Contact_BAO_Contact::exportableFields(), $additionalFields);

      $values = array_merge(array_keys($exportFields));
      unset($values[0]);

      //FIXME:skipping some tokens for time being.
      $skipTokens = array(
totten's avatar
totten committed
607 608 609 610 611 612 613 614 615 616
        'is_bulkmail',
        'group',
        'tag',
        'contact_sub_type',
        'note',
        'is_deceased',
        'deceased_date',
        'legal_identifier',
        'contact_sub_type',
        'user_unique_id',
totten's avatar
totten committed
617
      );
618

619
      $customFields = CRM_Core_BAO_CustomField::getFields(array('Individual', 'Address'));
620
      $legacyTokenNames = array_flip(CRM_Utils_Token::legacyContactTokens());
totten's avatar
totten committed
621

622
      foreach ($values as $val) {
totten's avatar
totten committed
623 624 625 626
        if (in_array($val, $skipTokens)) {
          continue;
        }
        //keys for $tokens should be constant. $token Values are changed for Custom Fields. CRM-3734
627 628 629 630 631 632
        $customFieldId = CRM_Core_BAO_CustomField::getKeyID($val);
        if ($customFieldId) {
          // CRM-15191 - if key is not in $customFields then the field is disabled and should be ignored
          if (!empty($customFields[$customFieldId])) {
            $tokens["{contact.$val}"] = $customFields[$customFieldId]['label'] . " :: " . $customFields[$customFieldId]['groupTitle'];
          }
totten's avatar
totten committed
633 634
        }
        else {
635 636 637
          // Support legacy token names
          $tokenName = CRM_Utils_Array::value($val, $legacyTokenNames, $val);
          $tokens["{contact.$tokenName}"] = $exportFields[$val]['title'];
totten's avatar
totten committed
638 639 640
        }
      }

641
      // Get all the hook tokens too
totten's avatar
totten committed
642 643
      $hookTokens = array();
      CRM_Utils_Hook::tokens($hookTokens);
Eileen McNaughton's avatar
Eileen McNaughton committed
644
      foreach ($hookTokens as $tokenValues) {
totten's avatar
totten committed
645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662
        foreach ($tokenValues as $key => $value) {
          if (is_numeric($key)) {
            $key = $value;
          }
          if (!preg_match('/^\{[^\}]+\}$/', $key)) {
            $key = '{' . $key . '}';
          }
          if (preg_match('/^\{([^\}]+)\}$/', $value, $matches)) {
            $value = $matches[1];
          }
          $tokens[$key] = $value;
        }
      }
    }

    return $tokens;
  }

663
  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
664
   * Different type of Participant Tokens.
665
   *
colemanw's avatar
colemanw committed
666
   * @return array
667
   */
668
  public static function participantTokens() {
669 670 671 672 673 674 675 676 677
    static $tokens = NULL;
    if (!$tokens) {
      $exportFields = CRM_Event_BAO_Participant::exportableFields();

      $values = array_merge(array_keys($exportFields));
      unset($values[0]);

      // skipping some tokens for time being.
      $skipTokens = array(
totten's avatar
totten committed
678 679 680 681 682 683 684 685
        'event_id',
        'participant_is_pay_later',
        'participant_is_test',
        'participant_contact_id',
        'participant_fee_currency',
        'participant_campaign_id',
        'participant_status',
        'participant_discount_name',
686 687 688 689 690 691 692 693 694 695
      );

      $customFields = CRM_Core_BAO_CustomField::getFields('Participant');

      foreach ($values as $key => $val) {
        if (in_array($val, $skipTokens)) {
          continue;
        }
        //keys for $tokens should be constant. $token Values are changed for Custom Fields. CRM-3734
        if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($val)) {
696
          $tokens["{participant.$val}"] = !empty($customFields[$customFieldId]) ? $customFields[$customFieldId]['label'] . " :: " . $customFields[$customFieldId]['groupTitle'] : '';
697 698 699 700 701 702 703 704 705
        }
        else {
          $tokens["{participant.$val}"] = $exportFields[$val]['title'];
        }
      }
    }
    return $tokens;
  }

706
  /**
707
   * @param int $caseTypeId
708 709
   * @return array
   */
710
  public static function caseTokens($caseTypeId = NULL) {
711 712 713 714 715 716
    static $tokens = NULL;
    if (!$tokens) {
      foreach (CRM_Case_BAO_Case::fields() as $field) {
        $tokens["{case.{$field['name']}}"] = $field['title'];
      }

717
      $customFields = CRM_Core_BAO_CustomField::getFields('Case', FALSE, FALSE, $caseTypeId);
718 719 720 721 722 723 724
      foreach ($customFields as $id => $field) {
        $tokens["{case.custom_$id}"] = "{$field['label']} :: {$field['groupTitle']}";
      }
    }
    return $tokens;
  }

totten's avatar
totten committed
725
  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
726
   * CiviCRM supported date input formats.
colemanw's avatar
colemanw committed
727 728
   *
   * @return array
totten's avatar
totten committed
729
   */
730
  public static function getDatePluginInputFormats() {
totten's avatar
totten committed
731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749
    $dateInputFormats = array(
      "mm/dd/yy" => ts('mm/dd/yyyy (12/31/2009)'),
      "dd/mm/yy" => ts('dd/mm/yyyy (31/12/2009)'),
      "yy-mm-dd" => ts('yyyy-mm-dd (2009-12-31)'),
      "dd-mm-yy" => ts('dd-mm-yyyy (31-12-2009)'),
      'dd.mm.yy' => ts('dd.mm.yyyy (31.12.2009)'),
      "M d, yy" => ts('M d, yyyy (Dec 31, 2009)'),
      'd M yy' => ts('d M yyyy (31 Dec 2009)'),
      "MM d, yy" => ts('MM d, yyyy (December 31, 2009)'),
      'd MM yy' => ts('d MM yyyy (31 December 2009)'),
      "DD, d MM yy" => ts('DD, d MM yyyy (Thursday, 31 December 2009)'),
      "mm/dd" => ts('mm/dd (12/31)'),
      "dd-mm" => ts('dd-mm (31-12)'),
      "yy-mm" => ts('yyyy-mm (2009-12)'),
      'M yy' => ts('M yyyy (Dec 2009)'),
      "yy" => ts('yyyy (2009)'),
    );

    /*
750 751 752 753 754 755 756 757 758 759
    Year greater than 2000 get wrong result for following format
    echo date( 'Y-m-d', strtotime( '7 Nov, 2001') );
    echo date( 'Y-m-d', strtotime( '7 November, 2001') );
    Return current year
    expected :: 2001-11-07
    output   :: 2009-11-07
    However
    echo date( 'Y-m-d', strtotime( 'Nov 7, 2001') );
    echo date( 'Y-m-d', strtotime( 'November 7, 2001') );
    gives proper result
colemanw's avatar
colemanw committed
760
     */
totten's avatar
totten committed
761 762 763 764 765

    return $dateInputFormats;
  }

  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
766
   * Time formats.
colemanw's avatar
colemanw committed
767 768
   *
   * @return array
totten's avatar
totten committed
769
   */
770
  public static function getTimeFormats() {
colemanw's avatar
colemanw committed
771 772
    return array(
      '1' => ts('12 Hours'),
totten's avatar
totten committed
773 774 775 776 777
      '2' => ts('24 Hours'),
    );
  }

  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
778
   * Get numeric options.
kurund's avatar
kurund committed
779
   *
colemanw's avatar
colemanw committed
780 781
   * @param int $start
   * @param int $end
totten's avatar
totten committed
782
   *
colemanw's avatar
colemanw committed
783
   * @return array
totten's avatar
totten committed
784 785
   */
  public static function getNumericOptions($start = 0, $end = 10) {
786
    $numericOptions = array();
totten's avatar
totten committed
787
    for ($i = $start; $i <= $end; $i++) {
totten's avatar
totten committed
788
      $numericOptions[$i] = $i;
totten's avatar
totten committed
789 790 791
    }
    return $numericOptions;
  }
792 793

  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
794
   * Barcode types.
colemanw's avatar
colemanw committed
795 796
   *
   * @return array
797
   */
798
  public static function getBarcodeTypes() {
799 800 801 802
    return array(
      'barcode' => ts('Linear (1D)'),
      'qrcode' => ts('QR code'),
    );
803
  }
804 805

  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
806
   * Dedupe rule types.
colemanw's avatar
colemanw committed
807 808
   *
   * @return array
809
   */
810
  public static function getDedupeRuleTypes() {
811 812 813 814 815
    return array(
      'Unsupervised' => ts('Unsupervised'),
      'Supervised' => ts('Supervised'),
      'General' => ts('General'),
    );
816
  }
817 818

  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
819
   * Campaign group types.
colemanw's avatar
colemanw committed
820 821
   *
   * @return array
822
   */
823
  public static function getCampaignGroupTypes() {
824 825 826 827
    return array(
      'Include' => ts('Include'),
      'Exclude' => ts('Exclude'),
    );
828 829 830
  }

  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
831
   * Subscription history method.
colemanw's avatar
colemanw committed
832 833
   *
   * @return array
834
   */
835
  public static function getSubscriptionHistoryMethods() {
836 837 838 839 840 841
    return array(
      'Admin' => ts('Admin'),
      'Email' => ts('Email'),
      'Web' => ts('Web'),
      'API' => ts('API'),
    );
842 843 844
  }

  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
845
   * Premium units.
colemanw's avatar
colemanw committed
846 847
   *
   * @return array
848
   */
849
  public static function getPremiumUnits() {
850 851 852 853 854 855
    return array(
      'day' => ts('Day'),
      'week' => ts('Week'),
      'month' => ts('Month'),
      'year' => ts('Year'),
    );
856
  }
857 858

  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
859
   * Extension types.
colemanw's avatar
colemanw committed
860 861
   *
   * @return array
862
   */
863
  public static function getExtensionTypes() {
totten's avatar
totten committed
864
    return array(
865 866 867 868 869 870
      'payment' => ts('Payment'),
      'search' => ts('Search'),
      'report' => ts('Report'),
      'module' => ts('Module'),
      'sms' => ts('SMS'),
    );
871 872 873
  }

  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
874
   * Job frequency.
colemanw's avatar
colemanw committed
875 876
   *
   * @return array
877
   */
878
  public static function getJobFrequency() {
879
    return array(
880 881 882 883 884 885
      // CRM-17669
      'Yearly' => ts('Yearly'),
      'Quarter' => ts('Quarterly'),
      'Monthly' => ts('Monthly'),
      'Weekly' => ts('Weekly'),

886 887 888 889
      'Daily' => ts('Daily'),
      'Hourly' => ts('Hourly'),
      'Always' => ts('Every time cron job is run'),
    );
890
  }
891 892

  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
893
   * Search builder operators.
colemanw's avatar
colemanw committed
894 895
   *
   * @return array
896
   */
897
  public static function getSearchBuilderOperators($fieldType = NULL) {
898
    return [
899 900 901 902 903 904 905
      '=' => '=',
      '!=' => '≠',
      '>' => '>',
      '<' => '<',
      '>=' => '≥',
      '<=' => '≤',
      'IN' => ts('In'),
monishdeb's avatar
monishdeb committed
906
      'NOT IN' => ts('Not In'),
907
      'LIKE' => ts('Like'),
monishdeb's avatar
monishdeb committed
908
      'NOT LIKE' => ts('Not Like'),
909 910 911 912 913
      'RLIKE' => ts('Regex'),
      'IS EMPTY' => ts('Is Empty'),
      'IS NOT EMPTY' => ts('Not Empty'),
      'IS NULL' => ts('Is Null'),
      'IS NOT NULL' => ts('Not Null'),
914
    ];
915 916 917
  }

  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
918
   * Profile group types.
919
   *
colemanw's avatar
colemanw committed
920
   * @return array
921
   */
922
  public static function getProfileGroupType() {
923 924 925 926 927 928 929
    $profileGroupType = array(
      'Activity' => ts('Activities'),
      'Contribution' => ts('Contributions'),
      'Membership' => ts('Memberships'),
      'Participant' => ts('Participants'),
    );
    $contactTypes = self::contactType();
colemanw's avatar
colemanw committed
930
    $contactTypes = !empty($contactTypes) ? array('Contact' => 'Contacts') + $contactTypes : array();
931
    $profileGroupType = array_merge($contactTypes, $profileGroupType);
932

933 934 935 936 937
    return $profileGroupType;
  }


  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
938
   * Word replacement match type.
colemanw's avatar
colemanw committed
939 940
   *
   * @return array
941
   */
942
  public static function getWordReplacementMatchType() {
943
    return array(
totten's avatar
totten committed
944 945 946
      'exactMatch' => ts('Exact Match'),
      'wildcardMatch' => ts('Wildcard Match'),
    );
947 948
  }

949
  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
950
   * Mailing group types.
colemanw's avatar
colemanw committed
951 952
   *
   * @return array
953
   */
954
  public static function getMailingGroupTypes() {
955 956 957 958 959
    return array(
      'Include' => ts('Include'),
      'Exclude' => ts('Exclude'),
      'Base' => ts('Base'),
    );
960 961 962
  }

  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
963
   * Mailing Job Status.
colemanw's avatar
colemanw committed
964 965
   *
   * @return array
966
   */
967
  public static function getMailingJobStatus() {
968 969 970 971 972 973 974
    return array(
      'Scheduled' => ts('Scheduled'),
      'Running' => ts('Running'),
      'Complete' => ts('Complete'),
      'Paused' => ts('Paused'),
      'Canceled' => ts('Canceled'),
    );
975 976
  }

colemanw's avatar
colemanw committed
977 978 979
  /**
   * @return array
   */
980
  public static function billingMode() {
981 982 983 984 985 986 987
    return array(
      CRM_Core_Payment::BILLING_MODE_FORM => 'form',
      CRM_Core_Payment::BILLING_MODE_BUTTON => 'button',
      CRM_Core_Payment::BILLING_MODE_NOTIFY => 'notify',
    );
  }

988 989 990 991 992 993 994 995 996 997 998
  /**
   * @return array
   */
  public static function contributeMode() {
    return array(
      CRM_Core_Payment::BILLING_MODE_FORM => 'direct',
      CRM_Core_Payment::BILLING_MODE_BUTTON => 'directIPN',
      CRM_Core_Payment::BILLING_MODE_NOTIFY => 'notify',
    );
  }

kurund's avatar
kurund committed
999
  /**
Eileen McNaughton's avatar
Eileen McNaughton committed
1000
   * Frequency unit for schedule reminders.
colemanw's avatar
colemanw committed
1001
   *
1002 1003
   * @param int $count
   *   For pluralization
colemanw's avatar
colemanw committed
1004
   * @return array
kurund's avatar
kurund committed
1005
   */
1006 1007 1008 1009