Fixed bug #13402: Active suggest feature for TCA fields with foreign tables
authorSteffen Kamper <info@sk-typo3.de>
Mon, 12 Apr 2010 22:52:33 +0000 (22:52 +0000)
committerSteffen Kamper <info@sk-typo3.de>
Mon, 12 Apr 2010 22:52:33 +0000 (22:52 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@7320 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/tceforms/class.t3lib_tceforms_suggest.php
t3lib/tceforms/class.t3lib_tceforms_suggest_defaultreceiver.php

index 53fc22c..ed7e098 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
 2010-04-13  Steffen Kamper  <info@sk-typo3.de>
 
+       * Fixed bug #13402: Active suggest feature for TCA fields with foreign tables
        * Fixed bug #13788: [felogin] Redirects use incorrect function parameters
        * Updated manual of felogin (thanks to Jigal van Hemert and Jeff Segars)
        * Reverted Update #14063: Updated ExtJs library from 3.1.1 to 3.2 Final
index 16ce07a..fd2c942 100644 (file)
@@ -129,9 +129,17 @@ class t3lib_TCEforms_Suggest {
                }
 
                $TSconfig = t3lib_BEfunc::getPagesTSconfig($pageId);
-
+               $queryTables = array();
+               $foreign_table_where = '';
                $wizardConfig = $GLOBALS['TCA'][$table]['columns'][$field]['config']['wizards']['suggest'];
+               if (isset($GLOBALS['TCA'][$table]['columns'][$field]['config']['allowed'])) {
                $queryTables = t3lib_div::trimExplode(',', $GLOBALS['TCA'][$table]['columns'][$field]['config']['allowed']);
+               } elseif (isset($GLOBALS['TCA'][$table]['columns'][$field]['config']['foreign_table'])) {
+                       $queryTables = array($GLOBALS['TCA'][$table]['columns'][$field]['config']['foreign_table']);
+                       $foreign_table_where = $GLOBALS['TCA'][$table]['columns'][$field]['config']['foreign_table_where'];
+                               // strip ORDER BY clause
+                       $foreign_table_where = trim(preg_replace('/ORDER[[:space:]]+BY.*/i', '', $foreign_table_where));
+               }
                $resultRows = array();
 
                        // fetch the records for each query table. A query table is a table from which records are allowed to
@@ -168,6 +176,17 @@ class t3lib_TCEforms_Suggest {
                        if (is_array($TSconfig['TCEFORM.'][$table.'.'][$field.'.']['suggest.'][$queryTable.'.'])) {
                                $config = t3lib_div::array_merge_recursive_overrule($config, $TSconfig['TCEFORM.'][$table.'.'][$field.'.']['suggest.'][$queryTable.'.']);
                        }
+
+                               //process addWhere
+                       if (!isset($config['addWhere']) && $foreign_table_where) {
+                               $config['addWhere'] = $foreign_table_where;
+                       }
+                       if (isset($config['addWhere'])) {
+                               $config['addWhere'] = strtr(' ' . $config['addWhere'], array(
+                                       '###THIS_UID###' => intval($uid),
+                                       '###CURRENT_PID###' => intval($pageId),
+                               ));
+                       }
                                // instantiate the class that should fetch the records for this $queryTable
                        $receiverClassName = $config['receiverClass'];
                        if (!class_exists($receiverClassName)) {
index 3d2a45e..d462d55 100644 (file)
@@ -131,6 +131,10 @@ class t3lib_TCEforms_Suggest_DefaultReceiver {
                if ($GLOBALS['TCA'][$this->table]['ctrl']['versioningWS'] == true) {
                        $this->addWhere .= ' AND t3ver_wsid = 0';
                }
+
+               if (isset($config['addWhere'])) {
+                       $this->addWhere .= ' ' . $config['addWhere'];
+               }
        }
 
        /**
@@ -161,7 +165,6 @@ class t3lib_TCEforms_Suggest_DefaultReceiver {
                                $this->orderByStatement,
                                $start . ', 50');
 
-
                $allRowsCount = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
 
                if ($allRowsCount) {