Skip to content
This repository was archived by the owner on Nov 3, 2023. It is now read-only.

Commit f080d88

Browse files
committed
Consider the values of referenced fields in the back end search (see #4376)
1 parent 3610214 commit f080d88

File tree

7 files changed

+46
-7
lines changed

7 files changed

+46
-7
lines changed

system/docs/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ Contao Open Source CMS changelog
44
Version 3.4.0-beta1 (2014-10-XX)
55
--------------------------------
66

7+
### Improved
8+
Consider the values of referenced fields in the back end search (see #4376).
9+
710
### New
811
Add an option to export style sheets (see #7049).
912

system/modules/calendar/dca/tl_calendar_events.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,10 @@
195195
'label' => &$GLOBALS['TL_LANG']['tl_calendar_events']['author'],
196196
'default' => BackendUser::getInstance()->id,
197197
'exclude' => true,
198+
'search' => true,
198199
'filter' => true,
199200
'sorting' => true,
200-
'flag' => 1,
201+
'flag' => 11,
201202
'inputType' => 'select',
202203
'foreignKey' => 'tl_user.name',
203204
'eval' => array('doNotCopy'=>true, 'chosen'=>true, 'mandatory'=>true, 'includeBlankOption'=>true, 'tl_class'=>'w50'),

system/modules/core/dca/tl_article.php

+1
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@
208208
'label' => &$GLOBALS['TL_LANG']['tl_article']['author'],
209209
'default' => BackendUser::getInstance()->id,
210210
'exclude' => true,
211+
'search' => true,
211212
'inputType' => 'select',
212213
'foreignKey' => 'tl_user.name',
213214
'eval' => array('doNotCopy'=>true, 'mandatory'=>true, 'chosen'=>true, 'includeBlankOption'=>true, 'tl_class'=>'w50'),

system/modules/core/dca/tl_page.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,9 @@
512512
'label' => &$GLOBALS['TL_LANG']['tl_page']['cuser'],
513513
'default' => intval(Config::get('defaultUser')),
514514
'exclude' => true,
515+
'search' => true,
515516
'inputType' => 'select',
516-
'foreignKey' => 'tl_user.username',
517+
'foreignKey' => 'tl_user.name',
517518
'eval' => array('mandatory'=>true, 'chosen'=>true, 'includeBlankOption'=>true, 'tl_class'=>'w50'),
518519
'sql' => "int(10) unsigned NOT NULL default '0'",
519520
'relation' => array('type'=>'hasOne', 'load'=>'lazy')
@@ -523,6 +524,7 @@
523524
'label' => &$GLOBALS['TL_LANG']['tl_page']['cgroup'],
524525
'default' => intval(Config::get('defaultGroup')),
525526
'exclude' => true,
527+
'search' => true,
526528
'inputType' => 'select',
527529
'foreignKey' => 'tl_user_group.name',
528530
'eval' => array('mandatory'=>true, 'chosen'=>true, 'includeBlankOption'=>true, 'tl_class'=>'w50'),

system/modules/core/drivers/DC_Table.php

+34-4
Original file line numberDiff line numberDiff line change
@@ -3263,8 +3263,27 @@ protected function treeView()
32633263
}
32643264
else
32653265
{
3266-
$objRoot = $this->Database->prepare("SELECT $for FROM {$this->strTable} WHERE CAST(".$session['search'][$this->strTable]['field']." AS CHAR) REGEXP ? GROUP BY $for")
3267-
->execute($session['search'][$this->strTable]['value']);
3266+
$strPattern = "CAST(%s AS CHAR) REGEXP ?";
3267+
3268+
if (substr(\Config::get('dbCollation'), -3) == '_ci')
3269+
{
3270+
$strPattern = "LOWER(CAST(%s AS CHAR)) REGEXP LOWER(?)";
3271+
}
3272+
3273+
$fld = $session['search'][$this->strTable]['field'];
3274+
3275+
if (isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$fld]['foreignKey']))
3276+
{
3277+
list($t, $f) = explode('.', $GLOBALS['TL_DCA'][$this->strTable]['fields'][$fld]['foreignKey']);
3278+
3279+
$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")
3280+
->execute($session['search'][$this->strTable]['value'], $session['search'][$this->strTable]['value']);
3281+
}
3282+
else
3283+
{
3284+
$objRoot = $this->Database->prepare("SELECT $for FROM {$this->strTable} WHERE " . sprintf($strPattern, $fld) . " GROUP BY $for")
3285+
->execute($session['search'][$this->strTable]['value']);
3286+
}
32683287
}
32693288

32703289
if ($objRoot->numRows < 1)
@@ -4807,13 +4826,24 @@ protected function searchMenu()
48074826
// Set the search value from the session
48084827
elseif ($session['search'][$this->strTable]['value'] != '')
48094828
{
4829+
$strPattern = "CAST(%s AS CHAR) REGEXP ?";
4830+
48104831
if (substr(\Config::get('dbCollation'), -3) == '_ci')
48114832
{
4812-
$this->procedure[] = "LOWER(CAST(".$session['search'][$this->strTable]['field']." AS CHAR)) REGEXP LOWER(?)";
4833+
$strPattern = "LOWER(CAST(%s AS CHAR)) REGEXP LOWER(?)";
4834+
}
4835+
4836+
$fld = $session['search'][$this->strTable]['field'];
4837+
4838+
if (isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$fld]['foreignKey']))
4839+
{
4840+
list($t, $f) = explode('.', $GLOBALS['TL_DCA'][$this->strTable]['fields'][$fld]['foreignKey']);
4841+
$this->procedure[] = "(" . sprintf($strPattern, $fld) . " OR " . sprintf($strPattern, "(SELECT $f FROM $t WHERE $t.id={$this->strTable}.$fld)") . ")";
4842+
$this->values[] = $session['search'][$this->strTable]['value'];
48134843
}
48144844
else
48154845
{
4816-
$this->procedure[] = "CAST(".$session['search'][$this->strTable]['field']." AS CHAR) REGEXP ?";
4846+
$this->procedure[] = sprintf($strPattern, $fld);
48174847
}
48184848

48194849
$this->values[] = $session['search'][$this->strTable]['value'];

system/modules/faq/dca/tl_faq.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,9 @@
175175
'default' => BackendUser::getInstance()->id,
176176
'exclude' => true,
177177
'search' => true,
178+
'filter' => true,
178179
'sorting' => true,
179-
'flag' => 1,
180+
'flag' => 11,
180181
'inputType' => 'select',
181182
'foreignKey' => 'tl_user.name',
182183
'eval' => array('doNotCopy'=>true, 'chosen'=>true, 'mandatory'=>true, 'includeBlankOption'=>true, 'tl_class'=>'w50'),

system/modules/news/dca/tl_news.php

+1
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@
201201
'label' => &$GLOBALS['TL_LANG']['tl_news']['author'],
202202
'default' => BackendUser::getInstance()->id,
203203
'exclude' => true,
204+
'search' => true,
204205
'filter' => true,
205206
'sorting' => true,
206207
'flag' => 11,

0 commit comments

Comments
 (0)