Index: class.ux_t3lib_db.php =================================================================== --- class.ux_t3lib_db.php (revision 25490) +++ class.ux_t3lib_db.php (working copy) @@ -969,12 +969,14 @@ $from_table[$k]['as'] = $this->quoteName($from_table[$k]['as']); } if (is_array($v['JOIN'])) { - $from_table[$k]['JOIN']['withTable'] = $this->quoteName($from_table[$k]['JOIN']['withTable']); - $from_table[$k]['JOIN']['as'] = ($from_table[$k]['JOIN']['as']) ? $this->quoteName($from_table[$k]['JOIN']['as']) : ''; - $from_table[$k]['JOIN']['ON'][0]['table'] = ($from_table[$k]['JOIN']['ON'][0]['table']) ? $this->quoteName($from_table[$k]['JOIN']['ON'][0]['table']) : ''; - $from_table[$k]['JOIN']['ON'][0]['field'] = $this->quoteName($from_table[$k]['JOIN']['ON'][0]['field']); - $from_table[$k]['JOIN']['ON'][1]['table'] = ($from_table[$k]['JOIN']['ON'][1]['table']) ? $this->quoteName($from_table[$k]['JOIN']['ON'][1]['table']) : ''; - $from_table[$k]['JOIN']['ON'][1]['field'] = $this->quoteName($from_table[$k]['JOIN']['ON'][1]['field']); + foreach ($v['JOIN'] as $joinCnt => $join) { + $from_table[$k]['JOIN'][$joinCnt]['withTable'] = $this->quoteName($join['withTable']); + $from_table[$k]['JOIN'][$joinCnt]['as'] = ($join['as']) ? $this->quoteName($join['as']) : ''; + $from_table[$k]['JOIN'][$joinCnt]['ON'][0]['table'] = ($join['ON'][0]['table']) ? $this->quoteName($join['ON'][0]['table']) : ''; + $from_table[$k]['JOIN'][$joinCnt]['ON'][0]['field'] = $this->quoteName($join['ON'][0]['field']); + $from_table[$k]['JOIN'][$joinCnt]['ON'][1]['table'] = ($join['ON'][1]['table']) ? $this->quoteName($join['ON'][1]['table']) : ''; + $from_table[$k]['JOIN'][$joinCnt]['ON'][1]['field'] = $this->quoteName($join['ON'][1]['field']); + } } } return $this->SQLparser->compileFromTables($from_table); @@ -2282,10 +2284,24 @@ if ($fieldMappingOnly) { if (is_array($this->mapping[$tableCfg['table']]['mapFieldNames'])) { $this->cache_mappingFromTableList[$key] = $tables; + } elseif (is_array($tableCfg['JOIN'])) { + foreach ($tableCfg['JOIN'] as $join) { + if (is_array($this->mapping[$join['withTable']]['mapFieldNames'])) { + $this->cache_mappingFromTableList[$key] = $tables; + break; + } + } } } else { if (is_array($this->mapping[$tableCfg['table']])) { $this->cache_mappingFromTableList[$key] = $tables; + } elseif (is_array($tableCfg['JOIN'])) { + foreach ($tableCfg['JOIN'] as $join) { + if (is_array($this->mapping[$join['withTable']])) { + $this->cache_mappingFromTableList[$key] = $tables; + break; + } + } } } } @@ -2361,6 +2377,29 @@ $tables = $this->SQLparser->parseFromTables($from_table); $defaultTable = $tables[0]['table']; foreach($tables as $k => $v) { + // Mapping JOINS + if (is_array($v['JOIN'])) { + foreach($v['JOIN'] as $joinCnt => $join) { + // Mapping withTable of the JOIN + if ($this->mapping[$join['withTable']]['mapTableName']) { + $tables[$k]['JOIN'][$joinCnt]['withTable'] = $this->mapping[$join['withTable']]['mapTableName']; + } + $onPartsArray = array(); + // Mapping ON parts of the JOIN + if (is_array($join['ON'])) { + foreach ($join['ON'] as $onParts) { + if (isset($this->mapping[$onParts['table']]['mapFieldNames'][$onParts['field']])) { + $onParts['field'] = $this->mapping[$onParts['table']]['mapFieldNames'][$onParts['field']]; + } + if (isset($this->mapping[$onParts['table']]['mapTableName'])) { + $onParts['table'] = $this->mapping[$onParts['table']]['mapTableName']; + } + $onPartsArray[] = $onParts; + } + $tables[$k]['JOIN'][$joinCnt]['ON'] = $onPartsArray; + } + } + } if ($this->mapping[$v['table']]['mapTableName']) { $tables[$k]['table'] = $this->mapping[$v['table']]['mapTableName']; }