Fixed bug #6953: Mapping of fieldnames in SQL-functions like MIN(), MAX() or SUM...
authorXavier Perseguers <typo3@perseguers.ch>
Thu, 8 Oct 2009 05:14:38 +0000 (05:14 +0000)
committerXavier Perseguers <typo3@perseguers.ch>
Thu, 8 Oct 2009 05:14:38 +0000 (05:14 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/dbal/trunk@25171 735d13b6-9817-0410-8766-e36946ffe9aa

typo3/sysext/dbal/ChangeLog
typo3/sysext/dbal/class.ux_t3lib_db.php

index 2940076..7e5c54b 100644 (file)
@@ -1,3 +1,7 @@
+2009-10-08  Xavier Perseguers  <typo3@perseguers.ch>
+
+       Fixed bug #6953: Mapping of fieldnames in SQL-functions like MIN(), MAX() or SUM() does not work (Thanks to Christian and Michael Miousse)
+
 2009-10-01  Xavier Perseguers  <typo3@perseguers.ch>
 
        * Raised version to 0.9.22
index 20068a1..9cb1835 100644 (file)
@@ -2415,6 +2415,29 @@ class ux_t3lib_DB extends t3lib_DB {
                                                $sqlPartArray[$k]['field'] = $this->mapping[$t]['mapFieldNames'][$sqlPartArray[$k]['field']];
                                        }
 
+                                               // Mapping field name in SQL-functions like MIN(), MAX() or SUM()
+                                       if ($this->mapping[$t]['mapFieldNames']) {
+                                               $fieldArray = explode('.', $sqlPartArray[$k]['func_content']);
+                                               if (count($fieldArray) == 1 && is_array($this->mapping[$t]['mapFieldNames']) && isset($this->mapping[$t]['mapFieldNames'][$fieldArray[0]])) {
+                                                       $sqlPartArray[$k]['func_content.'][0]['func_content'] = $this->mapping[$t]['mapFieldNames'][$fieldArray[0]];
+                                                       $sqlPartArray[$k]['func_content'] = $this->mapping[$t]['mapFieldNames'][$fieldArray[0]];
+                                               }
+                                               elseif (count($fieldArray) == 2) {
+                                                               // Map the external table
+                                                       $table = $fieldArray[0];
+                                                       if (isset($this->mapping[$fieldArray[0]]['mapTableName'])) {
+                                                               $table = $this->mapping[$fieldArray[0]]['mapTableName'];
+                                                       }
+                                                               // Map the field itself
+                                                       $field = $fieldArray[1];
+                                                       if (is_array($this->mapping[$fieldArray[0]]['mapFieldNames']) && isset($this->mapping[$fieldArray[0]]['mapFieldNames'][$fieldArray[1]])) {
+                                                               $field = $this->mapping[$fieldArray[0]]['mapFieldNames'][$fieldArray[1]];
+                                                       }
+                                                       $sqlPartArray[$k]['func_content.'][0]['func_content'] = $table . '.' . $field;
+                                                       $sqlPartArray[$k]['func_content'] = $table . '.' . $field;
+                                               }
+                                       }
+
                                                // do we have a field name in the value?
                                                // this is a very simplistic check, beware
                                        if (!is_numeric($sqlPartArray[$k]['value'][0]) && !isset($sqlPartArray[$k]['value'][1])) {