Merge branch 4.5 into 4.6
[civicrm-core.git] / CRM / Core / SelectValues.php
index 1d8812ba1ce011457a06c13d4d45993b544a2048..721ba43ea4b4754f4c68d9c94f1908dff9afd6c0 100644 (file)
@@ -23,7 +23,7 @@
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  * One place to store frequently used values in Select Elements. Note that
 class CRM_Core_SelectValues {
 
   /**
-   * Preferred mail format
-   * @static
+   * Yes/No options
+   *
+   * @return array
+   */
+  public static function boolean() {
+    return array(
+      1 => ts('Yes'),
+      0 => ts('No'),
+    );
+  }
+
+  /**
+   * Preferred mail format.
+   *
+   * @return array
    */
   public static function pmf() {
     return array(
@@ -50,8 +63,9 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * Privacy options
-   * @static
+   * Privacy options.
+   *
+   * @return array
    */
   public static function privacy() {
     return array(
@@ -65,8 +79,9 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * Various pre defined contact super types
-   * @static
+   * Various pre defined contact super types.
+   *
+   * @return array
    */
   public static function contactType() {
     static $contactType = NULL;
@@ -77,8 +92,10 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * Various pre defined unit list
-   * @static
+   * Various pre defined unit list.
+   *
+   * @param string $unitType
+   * @return array
    */
   public static function unitList($unitType = NULL) {
     $unitList = array(
@@ -93,16 +110,18 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * Membership type unit
-   * @static
+   * Membership type unit.
+   *
+   * @return array
    */
-  public static function membershipTypeUnitList( ) {
+  public static function membershipTypeUnitList() {
     return self::unitList('duration');
   }
 
   /**
-   * Various pre defined period types
-   * @static
+   * Various pre defined period types.
+   *
+   * @return array
    */
   public static function periodType() {
     return array(
@@ -112,21 +131,23 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * Various pre defined email selection methods
-   * @static
+   * Various pre defined email selection methods.
+   *
+   * @return array
    */
   public static function emailSelectMethods() {
     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"),
-      'location-exclude' => ts("Exclude email addresses assigned to the specified location")
+      'location-exclude' => ts("Exclude email addresses assigned to the specified location"),
     );
   }
 
   /**
-   * Various pre defined member visibility options
-   * @static
+   * Various pre defined member visibility options.
+   *
+   * @return array
    */
   public static function memberVisibility() {
     return array(
@@ -137,19 +158,21 @@ class CRM_Core_SelectValues {
 
   /**
    * Member auto-renew options
-   * @static
+   *
+   * @return array
    */
   public static function memberAutoRenew() {
     return array(
       ts('No auto-renew option'),
       ts('Give option, but not required'),
-      ts('Auto-renew required')
+      ts('Auto-renew required'),
     );
   }
 
   /**
-   * Various pre defined event dates
-   * @static
+   * Various pre defined event dates.
+   *
+   * @return array
    */
   public static function eventDate() {
     return array(
@@ -160,8 +183,9 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * Custom form field types
-   * @static
+   * Custom form field types.
+   *
+   * @return array
    */
   public static function customHtmlType() {
     return array(
@@ -186,9 +210,10 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * Various pre defined extensions for dynamic properties and groups
+   * Various pre defined extensions for dynamic properties and groups.
+   *
+   * @return array
    *
-   * @static
    */
   public static function customGroupExtends() {
     $customGroupExtends = array(
@@ -215,9 +240,9 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * Styles for displaying the custom data group
+   * Styles for displaying the custom data group.
    *
-   * @static
+   * @return array
    */
   public static function customGroupStyle() {
     return array(
@@ -228,9 +253,9 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * For displaying the uf group types
+   * For displaying the uf group types.
    *
-   * @static
+   * @return array
    */
   public static function ufGroupTypes() {
     $ufGroupType = array(
@@ -248,9 +273,9 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * The status of a contact within a group
+   * The status of a contact within a group.
    *
-   * @static
+   * @return array
    */
   public static function groupContactStatus() {
     return array(
@@ -261,8 +286,9 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * List of Group Types
-   * @static
+   * List of Group Types.
+   *
+   * @return array
    */
   public static function groupType() {
     return array(
@@ -272,19 +298,19 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * Compose the parameters for a date select object
-   *
-   * @param  string|NULL $type the type of date
-   * @param  string|NULL $format date format ( QF format)
+   * Compose the parameters for a date select object.
    *
+   * @param string|NULL $type
+   *   the type of date
+   * @param string|NULL $format
+   *   date format (QF format)
    * @param null $minOffset
    * @param null $maxOffset
    *
-   * @return array         the date array
-   * @static
+   * @return array
+   *   the date array
    */
   public static function date($type = NULL, $format = NULL, $minOffset = NULL, $maxOffset = NULL) {
-
     $date = array(
       'addEmptyOption' => TRUE,
       'emptyOptionText' => ts('- select -'),
@@ -324,9 +350,9 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * Values for UF form visibility options
+   * Values for UF form visibility options.
    *
-   * @static
+   * @return array
    */
   public static function ufVisibility() {
     return array(
@@ -337,9 +363,9 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * Values for group form visibility options
+   * Values for group form visibility options.
    *
-   * @static
+   * @return array
    */
   public static function groupVisibility() {
     return array(
@@ -349,13 +375,13 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * Different type of Mailing Components
+   * Different type of Mailing Components.
    *
-   * @static
-   * return array
+   * @return array
    */
   public static function mailingComponents() {
-    return array('Header' => ts('Header'),
+    return array(
+      'Header' => ts('Header'),
       'Footer' => ts('Footer'),
       'Reply' => ts('Reply Auto-responder'),
       'OptOut' => ts('Opt-out Message'),
@@ -367,10 +393,9 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * Get hours
+   * Get hours.
    *
-   *
-   * @static
+   * @return array
    */
   public function getHours() {
     $hours = array();
@@ -381,10 +406,9 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * Get minutes
-   *
+   * Get minutes.
    *
-   * @static
+   * @return array
    */
   public function getMinutes() {
     $minutes = array();
@@ -395,10 +419,10 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * Get the Map Provider
+   * Get the Map Provider.
    *
-   * @return array $map array of map providers
-   * @static
+   * @return array
+   *   array of map providers
    */
   public static function mapProvider() {
     static $map = NULL;
@@ -409,10 +433,10 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * Get the Geocoding Providers from available plugins
+   * Get the Geocoding Providers from available plugins.
    *
-   * @return array $geo array of geocoder providers
-   * @static
+   * @return array
+   *   array of geocoder providers
    */
   public static function geoProvider() {
     static $geo = NULL;
@@ -423,11 +447,10 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * Get the Address Standardization Providers from available
-   * plugins
+   * Get the Address Standardization Providers from available plugins.
    *
-   * @return array $addr array of address standardization providers
-   * @static
+   * @return array
+   *   array of address standardization providers
    */
   public static function addressProvider() {
     static $addr = NULL;
@@ -438,10 +461,9 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * Different type of Mailing Tokens
+   * Different type of Mailing Tokens.
    *
-   * @static
-   * return array
+   * @return array
    */
   public static function mailingTokens() {
     return array(
@@ -465,10 +487,9 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * Different type of Activity Tokens
+   * Different type of Activity Tokens.
    *
-   * @static
-   * return array
+   * @return array
    */
   public static function activityTokens() {
     return array(
@@ -480,10 +501,9 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * Different type of Membership Tokens
+   * Different type of Membership Tokens.
    *
-   * @static
-   * return array
+   * @return array
    */
   public static function membershipTokens() {
     return array(
@@ -498,10 +518,9 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * Different type of Event Tokens
+   * Different type of Event Tokens.
    *
-   * @static
-   * return array
+   * @return array
    */
   public static function eventTokens() {
     return array(
@@ -518,15 +537,14 @@ class CRM_Core_SelectValues {
       '{event.fee_amount}' => ts('Event Fees'),
       '{event.info_url}' => ts('Event Info URL'),
       '{event.registration_url}' => ts('Event Registration URL'),
-      '{event.balance}' => ts('Event Balance')
+      '{event.balance}' => ts('Event Balance'),
     );
   }
 
   /**
-   * Different type of Event Tokens
+   * Different type of Event Tokens.
    *
-   * @static
-   * return array
+   * @return array
    */
   public static function contributionTokens() {
     return array(
@@ -557,15 +575,15 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * Different type of Contact Tokens
+   * Different type of Contact Tokens.
    *
-   * @static
-   * return array
+   * @return array
    */
   public static function contactTokens() {
     static $tokens = NULL;
     if (!$tokens) {
-      $additionalFields = array('checksum' => array('title' => ts('Checksum')),
+      $additionalFields = array(
+        'checksum' => array('title' => ts('Checksum')),
         'contact_id' => array('title' => ts('Internal Contact ID')),
       );
       $exportFields = array_merge(CRM_Contact_BAO_Contact::exportableFields(), $additionalFields);
@@ -575,8 +593,16 @@ class CRM_Core_SelectValues {
 
       //FIXME:skipping some tokens for time being.
       $skipTokens = array(
-        'is_bulkmail', 'group', 'tag', 'contact_sub_type', 'note',
-        'is_deceased', 'deceased_date', 'legal_identifier', 'contact_sub_type', 'user_unique_id',
+        'is_bulkmail',
+        'group',
+        'tag',
+        'contact_sub_type',
+        'note',
+        'is_deceased',
+        'deceased_date',
+        'legal_identifier',
+        'contact_sub_type',
+        'user_unique_id',
       );
 
       $customFields = CRM_Core_BAO_CustomField::getFields(array('Individual', 'Address'));
@@ -601,7 +627,7 @@ class CRM_Core_SelectValues {
         }
       }
 
-      // might as well get all the hook tokens to
+      // Get all the hook tokens too
       $hookTokens = array();
       CRM_Utils_Hook::tokens($hookTokens);
       foreach ($hookTokens as $tokenValues) {
@@ -624,10 +650,9 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * Different type of Participant Tokens
+   * Different type of Participant Tokens.
    *
-   * @static
-   * return array
+   * @return array
    */
   public static function participantTokens() {
     static $tokens = NULL;
@@ -639,8 +664,14 @@ class CRM_Core_SelectValues {
 
       // skipping some tokens for time being.
       $skipTokens = array(
-        'event_id', 'participant_is_pay_later', 'participant_is_test', 'participant_contact_id',
-        'participant_fee_currency', 'participant_campaign_id', 'participant_status', 'participant_discount_name',
+        'event_id',
+        'participant_is_pay_later',
+        'participant_is_test',
+        'participant_contact_id',
+        'participant_fee_currency',
+        'participant_campaign_id',
+        'participant_status',
+        'participant_discount_name',
       );
 
       $customFields = CRM_Core_BAO_CustomField::getFields('Participant');
@@ -662,7 +693,9 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   *  CiviCRM supported date input formats
+   * CiviCRM supported date input formats.
+   *
+   * @return array
    */
   public static function getDatePluginInputFormats() {
     $dateInputFormats = array(
@@ -684,24 +717,25 @@ class CRM_Core_SelectValues {
     );
 
     /*
-         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
-        */
-
+    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
+     */
 
     return $dateInputFormats;
   }
 
   /**
-   * Map date plugin and actual format that is used by PHP
+   * Map date plugin and actual format that is used by PHP.
+   *
+   * @return array
    */
   public static function datePluginToPHPFormats() {
     $dateInputFormats = array(
@@ -725,7 +759,9 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * Time formats
+   * Time formats.
+   *
+   * @return array
    */
   public static function getTimeFormats() {
     return array(
@@ -735,22 +771,25 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * Get numeric options
+   * Get numeric options.
    *
+   * @param int $start
+   * @param int $end
    *
-   * @static
+   * @return array
    */
   public static function getNumericOptions($start = 0, $end = 10) {
     $numericOptions = array();
     for ($i = $start; $i <= $end; $i++) {
-        $numericOptions[$i] = $i;
+      $numericOptions[$i] = $i;
     }
     return $numericOptions;
   }
 
   /**
-   * Barcode types
-   * @static
+   * Barcode types.
+   *
+   * @return array
    */
   public static function getBarcodeTypes() {
     return array(
@@ -760,7 +799,9 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * Dedupe rule types
+   * Dedupe rule types.
+   *
+   * @return array
    */
   public static function getDedupeRuleTypes() {
     return array(
@@ -771,7 +812,9 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * Campaign group types
+   * Campaign group types.
+   *
+   * @return array
    */
   public static function getCampaignGroupTypes() {
     return array(
@@ -781,7 +824,9 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * Subscription history method
+   * Subscription history method.
+   *
+   * @return array
    */
   public static function getSubscriptionHistoryMethods() {
     return array(
@@ -793,7 +838,9 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * Premium units
+   * Premium units.
+   *
+   * @return array
    */
   public static function getPremiumUnits() {
     return array(
@@ -805,10 +852,12 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * Extension types
+   * Extension types.
+   *
+   * @return array
    */
   public static function getExtensionTypes() {
-    return  array(
+    return array(
       'payment' => ts('Payment'),
       'search' => ts('Search'),
       'report' => ts('Report'),
@@ -818,7 +867,9 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * Job frequency
+   * Job frequency.
+   *
+   * @return array
    */
   public static function getJobFrequency() {
     return array(
@@ -829,7 +880,9 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * Search builder operators
+   * Search builder operators.
+   *
+   * @return array
    */
   public static function getSearchBuilderOperators() {
     return array(
@@ -840,7 +893,9 @@ class CRM_Core_SelectValues {
       '>=' => '≥',
       '<=' => '≤',
       'IN' => ts('In'),
+      'NOT IN' => ts('Not In'),
       'LIKE' => ts('Like'),
+      'NOT LIKE' => ts('Not Like'),
       'RLIKE' => ts('Regex'),
       'IS EMPTY' => ts('Is Empty'),
       'IS NOT EMPTY' => ts('Not Empty'),
@@ -850,9 +905,9 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * Profile group types
+   * Profile group types.
    *
-   * @static
+   * @return array
    */
   public static function getProfileGroupType() {
     $profileGroupType = array(
@@ -863,24 +918,28 @@ class CRM_Core_SelectValues {
     );
     $contactTypes = self::contactType();
     $contactTypes = !empty($contactTypes) ? array('Contact' => 'Contacts') + $contactTypes : array();
-    $profileGroupType = array_merge($contactTypes, $profileGroupType );
+    $profileGroupType = array_merge($contactTypes, $profileGroupType);
 
     return $profileGroupType;
   }
 
 
   /**
-   * Word replacement match type
+   * Word replacement match type.
+   *
+   * @return array
    */
   public static function getWordReplacementMatchType() {
     return array(
-        'exactMatch' => ts('Exact Match'),
-        'wildcardMatch' => ts('Wildcard Match'),
-      );
+      'exactMatch' => ts('Exact Match'),
+      'wildcardMatch' => ts('Wildcard Match'),
+    );
   }
 
   /**
-   * Mailing group types
+   * Mailing group types.
+   *
+   * @return array
    */
   public static function getMailingGroupTypes() {
     return array(
@@ -891,7 +950,9 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * Mailing Job Status
+   * Mailing Job Status.
+   *
+   * @return array
    */
   public static function getMailingJobStatus() {
     return array(
@@ -903,6 +964,9 @@ class CRM_Core_SelectValues {
     );
   }
 
+  /**
+   * @return array
+   */
   public static function billingMode() {
     return array(
       CRM_Core_Payment::BILLING_MODE_FORM => 'form',
@@ -912,16 +976,23 @@ class CRM_Core_SelectValues {
   }
 
   /**
-   * Frequency unit for schedule reminders
-   */
-  public static function getScheduleReminderFrequencyUnits() {
-    //@todo update schema to refer to option group direct & remove this
-    static $scheduleReminderFrequencyUnits = NULL;
-    if (!$scheduleReminderFrequencyUnits) {
-      $scheduleReminderFrequencyUnits = array(
-          'hour' => ts('hour')) + CRM_Core_OptionGroup::values('recur_frequency_units');
-    }
-
-    return $scheduleReminderFrequencyUnits;
+   * Frequency unit for schedule reminders.
+   *
+   * @param int $count
+   *   For pluralization
+   * @return array
+   */
+  public static function getRecurringFrequencyUnits($count = 1) {
+    // @todo this used to refer to the 'recur_frequency_unit' option_values which
+    // is for recurring payments and probably not good to re-use for recurring entities.
+    // If something other than a hard-coded list is desired, add a new option_group.
+    return array(
+      'hour' => ts('hour', array('plural' => 'hours', 'count' => $count)),
+      'day' => ts('day', array('plural' => 'days', 'count' => $count)),
+      'week' => ts('week', array('plural' => 'weeks', 'count' => $count)),
+      'month' => ts('month', array('plural' => 'months', 'count' => $count)),
+      'year' => ts('year', array('plural' => 'years', 'count' => $count)),
+    );
   }
+
 }