diff --git a/system/docs/CHANGELOG.md b/system/docs/CHANGELOG.md index cd2e4b13e8..0a7ca89f43 100644 --- a/system/docs/CHANGELOG.md +++ b/system/docs/CHANGELOG.md @@ -4,6 +4,9 @@ Contao Open Source CMS changelog Version 3.4.0-beta1 (2014-10-XX) -------------------------------- +### Improved +Consider the values of referenced fields in the back end search (see #4376). + ### New Add an option to export style sheets (see #7049). diff --git a/system/modules/calendar/dca/tl_calendar_events.php b/system/modules/calendar/dca/tl_calendar_events.php index 5f33e2e9e5..7dec6a8b84 100644 --- a/system/modules/calendar/dca/tl_calendar_events.php +++ b/system/modules/calendar/dca/tl_calendar_events.php @@ -195,9 +195,10 @@ 'label' => &$GLOBALS['TL_LANG']['tl_calendar_events']['author'], 'default' => BackendUser::getInstance()->id, 'exclude' => true, + 'search' => true, 'filter' => true, 'sorting' => true, - 'flag' => 1, + 'flag' => 11, 'inputType' => 'select', 'foreignKey' => 'tl_user.name', 'eval' => array('doNotCopy'=>true, 'chosen'=>true, 'mandatory'=>true, 'includeBlankOption'=>true, 'tl_class'=>'w50'), diff --git a/system/modules/core/dca/tl_article.php b/system/modules/core/dca/tl_article.php index e319434d9b..8dd8687a33 100644 --- a/system/modules/core/dca/tl_article.php +++ b/system/modules/core/dca/tl_article.php @@ -208,6 +208,7 @@ 'label' => &$GLOBALS['TL_LANG']['tl_article']['author'], 'default' => BackendUser::getInstance()->id, 'exclude' => true, + 'search' => true, 'inputType' => 'select', 'foreignKey' => 'tl_user.name', 'eval' => array('doNotCopy'=>true, 'mandatory'=>true, 'chosen'=>true, 'includeBlankOption'=>true, 'tl_class'=>'w50'), diff --git a/system/modules/core/dca/tl_page.php b/system/modules/core/dca/tl_page.php index 3ea38a8881..de6522d1d8 100644 --- a/system/modules/core/dca/tl_page.php +++ b/system/modules/core/dca/tl_page.php @@ -512,6 +512,7 @@ 'label' => &$GLOBALS['TL_LANG']['tl_page']['cuser'], 'default' => intval(Config::get('defaultUser')), 'exclude' => true, + 'search' => true, 'inputType' => 'select', 'foreignKey' => 'tl_user.username', 'eval' => array('mandatory'=>true, 'chosen'=>true, 'includeBlankOption'=>true, 'tl_class'=>'w50'), @@ -523,6 +524,7 @@ 'label' => &$GLOBALS['TL_LANG']['tl_page']['cgroup'], 'default' => intval(Config::get('defaultGroup')), 'exclude' => true, + 'search' => true, 'inputType' => 'select', 'foreignKey' => 'tl_user_group.name', 'eval' => array('mandatory'=>true, 'chosen'=>true, 'includeBlankOption'=>true, 'tl_class'=>'w50'), diff --git a/system/modules/core/drivers/DC_Table.php b/system/modules/core/drivers/DC_Table.php index 10b4578b9c..3b5792dfd9 100644 --- a/system/modules/core/drivers/DC_Table.php +++ b/system/modules/core/drivers/DC_Table.php @@ -3263,8 +3263,27 @@ protected function treeView() } else { - $objRoot = $this->Database->prepare("SELECT $for FROM {$this->strTable} WHERE CAST(".$session['search'][$this->strTable]['field']." AS CHAR) REGEXP ? GROUP BY $for") - ->execute($session['search'][$this->strTable]['value']); + $strPattern = "CAST(%s AS CHAR) REGEXP ?"; + + if (substr(\Config::get('dbCollation'), -3) == '_ci') + { + $strPattern = "LOWER(CAST(%s AS CHAR)) REGEXP LOWER(?)"; + } + + $fld = $session['search'][$this->strTable]['field']; + + if (isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$fld]['foreignKey'])) + { + list($t, $f) = explode('.', $GLOBALS['TL_DCA'][$this->strTable]['fields'][$fld]['foreignKey']); + + $objRoot = $this->Database->prepare("SELECT $for FROM {$this->strTable} WHERE (" . sprintf($strPattern, $fld) . " OR " . sprintf($strPattern, "(SELECT $f FROM $t WHERE $t.id={$this->strTable}.$fld)") . ") GROUP BY $for") + ->execute($session['search'][$this->strTable]['value'], $session['search'][$this->strTable]['value']); + } + else + { + $objRoot = $this->Database->prepare("SELECT $for FROM {$this->strTable} WHERE " . sprintf($strPattern, $fld) . " GROUP BY $for") + ->execute($session['search'][$this->strTable]['value']); + } } if ($objRoot->numRows < 1) @@ -4807,13 +4826,24 @@ protected function searchMenu() // Set the search value from the session elseif ($session['search'][$this->strTable]['value'] != '') { + $strPattern = "CAST(%s AS CHAR) REGEXP ?"; + if (substr(\Config::get('dbCollation'), -3) == '_ci') { - $this->procedure[] = "LOWER(CAST(".$session['search'][$this->strTable]['field']." AS CHAR)) REGEXP LOWER(?)"; + $strPattern = "LOWER(CAST(%s AS CHAR)) REGEXP LOWER(?)"; + } + + $fld = $session['search'][$this->strTable]['field']; + + if (isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$fld]['foreignKey'])) + { + list($t, $f) = explode('.', $GLOBALS['TL_DCA'][$this->strTable]['fields'][$fld]['foreignKey']); + $this->procedure[] = "(" . sprintf($strPattern, $fld) . " OR " . sprintf($strPattern, "(SELECT $f FROM $t WHERE $t.id={$this->strTable}.$fld)") . ")"; + $this->values[] = $session['search'][$this->strTable]['value']; } else { - $this->procedure[] = "CAST(".$session['search'][$this->strTable]['field']." AS CHAR) REGEXP ?"; + $this->procedure[] = sprintf($strPattern, $fld); } $this->values[] = $session['search'][$this->strTable]['value']; diff --git a/system/modules/faq/dca/tl_faq.php b/system/modules/faq/dca/tl_faq.php index ff8b7e64f1..8f0d755bd2 100644 --- a/system/modules/faq/dca/tl_faq.php +++ b/system/modules/faq/dca/tl_faq.php @@ -175,8 +175,9 @@ 'default' => BackendUser::getInstance()->id, 'exclude' => true, 'search' => true, + 'filter' => true, 'sorting' => true, - 'flag' => 1, + 'flag' => 11, 'inputType' => 'select', 'foreignKey' => 'tl_user.name', 'eval' => array('doNotCopy'=>true, 'chosen'=>true, 'mandatory'=>true, 'includeBlankOption'=>true, 'tl_class'=>'w50'), diff --git a/system/modules/news/dca/tl_news.php b/system/modules/news/dca/tl_news.php index fec57fea65..5f69298322 100644 --- a/system/modules/news/dca/tl_news.php +++ b/system/modules/news/dca/tl_news.php @@ -201,6 +201,7 @@ 'label' => &$GLOBALS['TL_LANG']['tl_news']['author'], 'default' => BackendUser::getInstance()->id, 'exclude' => true, + 'search' => true, 'filter' => true, 'sorting' => true, 'flag' => 11,