ignore uf_join module for reserved profiles CRM-14488
[civicrm-core.git] / CRM / Core / BAO / UFField.php
index e4baabe332852abc74cb65d56b2b47572d5de886..843e97c38f8ea421a9e07cf6b9f3d00e6f485f35 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$
  *
  */
@@ -140,10 +140,15 @@ class CRM_Core_BAO_UFField extends CRM_Core_DAO_UFField {
     $ufField->uf_group_id = CRM_Utils_Array::value('uf_group', $ids);
     $ufField->field_type = $params['field_name'][0];
     $ufField->field_name = $params['field_name'][1];
-    $ufField->location_type_id = (CRM_Utils_Array::value(2, $params['field_name'])) ? $params['field_name'][2] : 'NULL';
+    if ($params['field_name'][1] == 'url') {
+      $ufField->website_type_id = CRM_Utils_Array::value(2, $params['field_name'], NULL);
+    }
+    else {
+      $ufField->location_type_id = (CRM_Utils_Array::value(2, $params['field_name'])) ? $params['field_name'][2] : 'NULL';
+    }
     $ufField->phone_type_id = CRM_Utils_Array::value(3, $params['field_name']);
 
-    if (CRM_Utils_Array::value('uf_field', $ids)) {
+    if (!empty($ids['uf_field'])) {
       $ufField->whereAdd("id <> " . CRM_Utils_Array::value('uf_field', $ids));
     }
 
@@ -211,7 +216,14 @@ WHERE cf.id IN (" . $customFieldIds . ") AND is_multiple = 1 LIMIT 0,1";
     $ufField->field_name = $params['field_name'][1];
 
     //should not set location type id for Primary
-    $locationTypeId = CRM_Utils_Array::value(2, $params['field_name']);
+    $locationTypeId = NULL;
+    if ($params['field_name'][1] == 'url') {
+      $ufField->website_type_id = CRM_Utils_Array::value(2, $params['field_name']);
+    }
+    else {
+      $locationTypeId = CRM_Utils_Array::value(2, $params['field_name']);
+      $ufField->website_type_id = NULL;
+    }
     if ($locationTypeId) {
       $ufField->location_type_id = $locationTypeId;
     }
@@ -252,7 +264,7 @@ WHERE cf.id IN (" . $customFieldIds . ") AND is_multiple = 1 LIMIT 0,1";
     // fix for CRM-316
     $oldWeight = NULL;
 
-    if (CRM_Utils_Array::value('field_id', $params)) {
+    if (!empty($params['field_id'])) {
       $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFField', $params['field_id'], 'weight', 'id');
     }
     $fieldValues = array('uf_group_id' => $params['group_id']);
@@ -796,7 +808,11 @@ SELECT  id
     $billing_id = CRM_Core_BAO_LocationType::getBilling();
     list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2);
 
-    $profileFields = civicrm_api3('uf_field', 'get', array_merge($profileFilter, array('is_active' => 1, 'return' => 'field_name')));
+    $profileFields = civicrm_api3('uf_field', 'get', array_merge($profileFilter,
+      array('is_active' => 1, 'return' => 'field_name', 'options' => array(
+        'limit' => 0,
+      ))
+    ));
     //check for valid fields ( fields that are present in billing block )
     $validBillingFields = array(
       'first_name',
@@ -917,12 +933,7 @@ SELECT  id
           'name' => 'contribution_note',
           'title' => ts('Contribution Note'),
         );
-        if ($gid && CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $gid, 'name') == 'contribution_batch_entry') {
-          $fields['Contribution'] = array_merge($contribFields, self::getContribBatchEntryFields());
-        }
-        else {
-          $fields['Contribution'] = $contribFields;
-        }
+        $fields['Contribution'] = array_merge($contribFields, self::getContribBatchEntryFields());
       }
     }
 
@@ -968,6 +979,24 @@ SELECT  id
       }
     }
 
+    if (CRM_Core_Permission::access('CiviCase')) {
+      $caseFields = CRM_Case_BAO_Query::getFields(TRUE);
+      $caseFields = array_merge($caseFields, CRM_Core_BAO_CustomField::getFieldsForImport('Case'));
+      if ($caseFields) {
+        // Remove fields not supported by profiles
+        CRM_Utils_Array::remove($caseFields,
+          'case_id',
+          'case_type',
+          'case_start_date',
+          'case_end_date',
+          'case_role',
+          'case_status',
+          'case_deleted'
+        );
+      }
+      $fields['Case'] = $caseFields;
+    }
+
     $activityFields = CRM_Activity_BAO_Activity::getProfileFields();
     if ($activityFields) {
       // campaign related fields.
@@ -1064,6 +1093,10 @@ SELECT  id
           'name' => 'soft_credit',
           'title' => ts('Soft Credit'),
         ),
+        'soft_credit_type' => array(
+          'name' => 'soft_credit_type',
+          'title' => ts('Soft Credit Type'),
+        ),
         'product_name' => array(
           'name' => 'product_name',
           'title' => ts('Premiums'),