Merge pull request #3516 from jitendrapurohit/CRM-14869
[civicrm-core.git] / CRM / Utils / Type.php
index e794297021d045f7853faa1382f2e0d1b5554257..5192000e2e67e0b9abc2d3f29dbb8a0483e56ceb 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id: $
  *
  */
@@ -39,7 +39,6 @@ class CRM_Utils_Type {
     T_ENUM       = 2,
     T_DATE       = 4,
     T_TIME       = 8,
-    T_BOOL       = 16,
     T_BOOLEAN    = 16,
     T_TEXT       = 32,
     T_LONGTEXT   = 32,
@@ -71,9 +70,7 @@ class CRM_Utils_Type {
    *
    * @param  $type       integer datatype
    *
-   * @return $string     String datatype respective to integer datatype
-   *
-   * @access public
+   * @return string $string     String datatype respective to integer datatype@access public
    * @static
    */
   static function typeToString($type) {
@@ -165,7 +162,25 @@ class CRM_Utils_Type {
         // CRM-8925
       case 'Country':
       case 'StateProvince':
-        if (CRM_Utils_Rule::positiveInteger($data)) {
+        // Checked for multi valued state/country value
+        if (is_array($data)) {
+          $returnData = TRUE;
+          foreach ($data as $data) {
+            if (CRM_Utils_Rule::positiveInteger($data) || CRM_Core_DAO::escapeString($data)) {
+              $returnData = TRUE;
+            }
+            else {
+              $returnData = FALSE;
+            }
+          }
+          if ($returnData) {
+            return $data;
+          }
+        }
+        elseif (!is_numeric($data) &&  CRM_Core_DAO::escapeString($data)) {
+          return $data;
+        }
+        elseif (CRM_Utils_Rule::positiveInteger($data)) {
           return $data;
         }
         break;
@@ -191,6 +206,7 @@ class CRM_Utils_Type {
 
       case 'String':
       case 'Memo':
+      case 'Text':
         return CRM_Core_DAO::escapeString($data);
 
       case 'Date':