CRM-14028 - Workaround the number 0 == empty() php bug
[civicrm-core.git] / CRM / Core / BAO / Mapping.php
index d931339530cd80f2d5d2c71d79ac12e58ebf3a3d..4eca12bb0d11cc2f188753f9044f487549d145e9 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.4                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2013                                |
  +--------------------------------------------------------------------+
@@ -324,9 +324,11 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
     $contactType = array('Individual', 'Household', 'Organization');
     foreach ($contactType as $value) {
       $contactFields = CRM_Contact_BAO_Contact::exportableFields($value, FALSE, $required);
+      $contactFields = array_merge($contactFields, CRM_Contact_BAO_Query_Hook::singleton()->getFields());
+
       // exclude the address options disabled in the Address Settings
       $fields[$value] = CRM_Core_BAO_Address::validateAddressOptions($contactFields);
-
+      ksort($fields[$value]);
       if ($mappingType == 'Export') {
         $relationships = array();
         $relationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, $value);
@@ -467,14 +469,14 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
       $csRelationships = array();
 
       if ($mappingType == 'Export') {
-        $subTypeRelationshipTypes = 
+        $subTypeRelationshipTypes =
           CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, $val['parent'],
                                                                    FALSE, 'label', TRUE, $subType);
-        
+
         foreach ($subTypeRelationshipTypes as $key => $var) {
           if (!array_key_exists($key, $fields[$val['parent']])) {
             list($type) = explode('_', $key);
-            
+
             $csRelationships[$key]['title'] = $var;
             $csRelationships[$key]['headerPattern'] = '/' . preg_quote($var, '/') . '/';
             $csRelationships[$key]['export'] = TRUE;
@@ -527,7 +529,7 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
 
     $mapperKeys = array_keys($mapperFields);
 
-    $locationTypes = CRM_Core_PseudoConstant::locationType();
+    $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
 
     $defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
 
@@ -558,15 +560,19 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
 
     foreach ($sel1 as $key => $sel) {
       if ($key) {
-        asort($mapperFields[$key]);
+        // sort everything BUT the contactType which is sorted seperately by
+        // an initial commit of CRM-13278 (check ksort above)
+        if (!in_array($key, $contactType)) {
+          asort($mapperFields[$key]);
+        }
         $sel2[$key] = array('' => ts('- select field -')) + $mapperFields[$key];
       }
     }
 
     $sel3['']    = NULL;
     $sel5['']    = NULL;
-    $phoneTypes  = CRM_Core_PseudoConstant::phoneType();
-    $imProviders = CRM_Core_PseudoConstant::IMProvider();
+    $phoneTypes  = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
+    $imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id');
     asort($phoneTypes);
 
     foreach ($sel1 as $k => $sel) {
@@ -847,20 +853,20 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
         if ($mappingType == 'Search Builder') {
           //CRM -2292, restricted array set
           $operatorArray = array(
-            ''             => ts('-operator-'),
-            '='            => '=',
-            '!='           => '!=',
-            '>'            => '>',
-            '<'            => '<',
-            '>='           => '>=',
-            '<='           => '<=',
-            'IN'           => 'IN',
-            'LIKE'         => 'LIKE',
-            'RLIKE'        => 'RLIKE',
-            'IS EMPTY'     => 'IS EMPTY',
-            'IS NOT EMPTY' => 'IS NOT EMPTY',
-            'IS NULL'      => 'IS NULL',
-            'IS NOT NULL'  => 'IS NOT NULL',
+            '' => ts('-operator-'),
+            '=' => '=',
+            '!=' => '≠',
+            '>' => '>',
+            '<' => '<',
+            '>=' => '≥',
+            '<=' => '≤',
+            'IN' => ts('In'),
+            'LIKE' => ts('Like'),
+            'RLIKE' => ts('Regex'),
+            'IS EMPTY' => ts('Is Empty'),
+            'IS NOT EMPTY' => ts('Not Empty'),
+            'IS NULL' => ts('Is Null'),
+            'IS NOT NULL' => ts('Not Null'),
           );
 
           $form->add('select', "operator[$x][$i]", '', $operatorArray);
@@ -1024,7 +1030,8 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
             }
           }
 
-          if ($v[0] == 'Contribution' && substr($fldName, 0, 7) != 'custom_') {
+          if ($v[0] == 'Contribution' && substr($fldName, 0, 7) != 'custom_'
+            && substr($fldName, 0, 10) != 'financial_') {
             if (substr($fldName, 0, 13) != 'contribution_') {
               $fldName = 'contribution_' . $fldName;
             }
@@ -1087,7 +1094,7 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
       return $fields;
     }
 
-    $locationTypes = CRM_Core_PseudoConstant::locationType();
+    $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
     foreach ($params['mapper'] as $key => $value) {
       foreach ($value as $k => $v) {
         if (isset($v[1])) {
@@ -1172,7 +1179,7 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping {
           }
 
           if (CRM_Utils_Array::value('operator', $params)) {
-            $saveMappingFields->operator = CRM_Utils_Array::value($k, $params['operator'][$key]);            
+            $saveMappingFields->operator = CRM_Utils_Array::value($k, $params['operator'][$key]);
           }
           if (CRM_Utils_Array::value('value', $params)) {
             $saveMappingFields->value = CRM_Utils_Array::value($k, $params['value'][$key]);