Merge pull request #4291 from mrpaulc/CRM-12920
[civicrm-core.git] / CRM / Core / BAO / CustomField.php
index 4c90b62952c9d0fde46c5c47bb25a743739d6de6..da6671bb40205f80197c65f6a9ded5f1abc03f63 100644 (file)
@@ -411,11 +411,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
       }
     }
 
-    if ($customDataSubType && !is_array($customDataSubType)) {
-      $customDataSubType = explode(CRM_Core_DAO::VALUE_SEPARATOR,
-        trim($customDataSubType, CRM_Core_DAO::VALUE_SEPARATOR)
-      );
-    }
+    $customDataSubType = CRM_Utils_Array::explodePadded($customDataSubType);
 
     if (is_array($customDataType)) {
       $cacheKey = implode('_', $customDataType);
@@ -684,8 +680,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
         );
       }
     }
-    return $all ? array(
-      NULL, NULL) : NULL;
+    return $all ? array(NULL, NULL) : NULL;
   }
 
   /**
@@ -759,10 +754,6 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
       $widget = 'Text';
     }
 
-    if ($widget == 'Select State/Province' || $widget == 'Select Country') {
-      $qf->_stateCountryMap[$widget == 'Select Country' ? 'country' : 'state_province'][] = $elementName;
-    }
-
     $placeholder = $search ? ts('- any -') : ($useRequired ? ts('- select -') : ts('- none -'));
 
     // FIXME: Why are select state/country separate widget types?
@@ -1456,7 +1447,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
    *
    * @return array
    */
-  static function getFileURL($contactID, $cfID, $fileID = NULL, $absolute = FALSE) {
+  static function getFileURL($contactID, $cfID, $fileID = NULL, $absolute = FALSE, $multiRecordWhereClause = NULL) {
     if ($contactID) {
       if (!$fileID) {
         $params = array('id' => $cfID);
@@ -1471,7 +1462,12 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
         );
 
         //query to fetch id from civicrm_file
-        $query = "SELECT {$columnName} FROM {$tableName} where entity_id = {$contactID}";
+        if ($multiRecordWhereClause) {
+          $query = "SELECT {$columnName} FROM {$tableName} where entity_id = {$contactID} AND {$multiRecordWhereClause}";
+        }
+        else {
+          $query = "SELECT {$columnName} FROM {$tableName} where entity_id = {$contactID}";
+        }
         $fileID = CRM_Core_DAO::singleValueQuery($query);
       }
 
@@ -1535,6 +1531,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
    * @param int     $entityId            entity id (contribution, membership...)
    * @param boolean $inline              consider inline custom groups only
    * @param boolean $checkPermission     if false, do not include permissioning clause
+   * @param boolean $includeViewOnly     if true, fields marked 'View Only' are included. Required for APIv3.
    *
    * @return array $customFormatted formatted custom field array
    * @static
@@ -1543,7 +1540,8 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
     $customFieldExtend, $customValueId = NULL,
     $entityId = NULL,
     $inline = FALSE,
-    $checkPermission = TRUE
+    $checkPermission = TRUE,
+    $includeViewOnly = false
   ) {
     //get the custom fields for the entity
     //subtype and basic type
@@ -1576,7 +1574,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
     }
 
     // return if field is a 'code' field
-    if (!empty($customFields[$customFieldId]['is_view'])) {
+    if (!$includeViewOnly && !empty($customFields[$customFieldId]['is_view'])) {
       return;
     }