コード例 #1
0
 /**
  * Get all the State/Province abbreviations from the database.
  *
  * Same as above, except gets the abbreviations instead of the names.
  *
  *
  * @param bool|int $id - Optional id to return
  *
  * @param bool $limit
  *
  * @return array
  *   array reference of all State/Province abbreviations.
  */
 public static function stateProvinceAbbreviation($id = FALSE, $limit = TRUE)
 {
     if ($id > 1) {
         $query = "\nSELECT abbreviation\nFROM   civicrm_state_province\nWHERE  id = %1";
         $params = array(1 => array($id, 'Integer'));
         return CRM_Core_DAO::singleValueQuery($query, $params);
     }
     if (!self::$stateProvinceAbbreviation || !$id) {
         $whereClause = FALSE;
         if ($limit) {
             $countryIsoCodes = self::countryIsoCode();
             $limitCodes = CRM_Core_BAO_Country::provinceLimit();
             $limitIds = array();
             foreach ($limitCodes as $code) {
                 $tmpArray = array_keys($countryIsoCodes, $code);
                 if (!empty($tmpArray)) {
                     $limitIds[] = array_shift($tmpArray);
                 }
             }
             if (!empty($limitIds)) {
                 $whereClause = 'country_id IN (' . implode(', ', $limitIds) . ')';
             }
         }
         self::populate(self::$stateProvinceAbbreviation, 'CRM_Core_DAO_StateProvince', TRUE, 'abbreviation', 'is_active', $whereClause);
     }
     if ($id) {
         if (array_key_exists($id, self::$stateProvinceAbbreviation)) {
             return self::$stateProvinceAbbreviation[$id];
         } else {
             $result = NULL;
             return $result;
         }
     }
     return self::$stateProvinceAbbreviation;
 }