copyright and version fixes
[civicrm-core.git] / CRM / Core / BAO / CustomValueTable.php
index 74beeed525e579ad96beb6b8d7990d2ac487f997..5c004a44fa16bb2d4744c5293ed7537ea990468b 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | 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$
  *
  */
@@ -91,7 +91,7 @@ class CRM_Core_BAO_CustomValueTable {
                   CRM_Utils_Array::lookupValue($states, 'state_province',
                     CRM_Core_PseudoConstant::stateProvince(), TRUE
                   );
-                  if (!CRM_Utils_Array::value('state_province_id', $states)) {
+                  if (empty($states['state_province_id'])) {
                     CRM_Utils_Array::lookupValue($states, 'state_province',
                       CRM_Core_PseudoConstant::stateProvinceAbbreviation(), TRUE
                     );
@@ -128,7 +128,7 @@ class CRM_Core_BAO_CustomValueTable {
                   CRM_Utils_Array::lookupValue($countries, 'country',
                     CRM_Core_PseudoConstant::country(), TRUE
                   );
-                  if (!CRM_Utils_Array::value('country_id', $countries)) {
+                  if (empty($countries['country_id'])) {
                     CRM_Utils_Array::lookupValue($countries, 'country',
                       CRM_Core_PseudoConstant::countryIsoCode(), TRUE
                     );
@@ -320,7 +320,7 @@ class CRM_Core_BAO_CustomValueTable {
           $cvParam['type'] = 'Timestamp';
         }
 
-        if (CRM_Utils_Array::value('id', $customValue)) {
+        if (!empty($customValue['id'])) {
           $cvParam['id'] = $customValue['id'];
         }
         if (!array_key_exists($customValue['table_name'], $cvParams)) {
@@ -399,7 +399,8 @@ SELECT cg.table_name,
        cg.id as groupID,
        cg.is_multiple,
        cf.column_name,
-       cf.id as fieldID
+       cf.id as fieldID,
+       cf.data_type as fieldDataType
 FROM   civicrm_custom_group cg,
        civicrm_custom_field cf
 WHERE  cf.custom_group_id = cg.id
@@ -419,6 +420,7 @@ AND    $cond
       $fields[$dao->table_name][] = $dao->fieldID;
       $select[$dao->table_name][] = "{$dao->column_name} AS custom_{$dao->fieldID}";
       $isMultiple[$dao->table_name] = $dao->is_multiple ? TRUE : FALSE;
+      $file[$dao->table_name][$dao->fieldID] = $dao->fieldDataType;     
     }
 
     $result = array();
@@ -430,13 +432,29 @@ AND    $cond
           $fieldName = "custom_{$fieldID}";
           if ($isMultiple[$tableName]) {
             if ($formatMultiRecordField) {
-              $result["{$dao->id}"]["{$fieldID}"] = $dao->$fieldName;
+              if($file[$tableName][$fieldID] == 'File') {
+                if($fileid = $dao->$fieldName) {
+                  $fileurl = CRM_Core_BAO_File::paperIconAttachment($tableName,$entityID);
+                  $result["{$dao->id}"]["{$fieldID}"] = $fileurl[$dao->$fieldName];
+                }
+              }
+              else {
+                $result["{$dao->id}"]["{$fieldID}"] = $dao->$fieldName;
+              }
             } else {
               $result["{$fieldID}_{$dao->id}"] = $dao->$fieldName;
             }
           }
           else {
-            $result[$fieldID] = $dao->$fieldName;
+            if($file[$tableName][$fieldID] == 'File') {
+              if($fileid = $dao->$fieldName) {
+                $fileurl = CRM_Core_BAO_File::paperIconAttachment($tableName,$entityID);
+                $result[$fieldID] = $fileurl[$dao->$fieldName];
+              }
+            }
+            else {
+              $result[$fieldID] = $dao->$fieldName;          
+            }
           }
         }
       }